From bb648954ad04882795b5644a70714d4c7e85aa57 Mon Sep 17 00:00:00 2001 From: George Wu Date: Sat, 30 May 2020 18:39:39 +0200 Subject: [PATCH] Environment variables --- appveyor.yml | 2 +- cmake/project_properties.cmake | 30 +++++++++++++++++------------- scripts/configure-cmake.ps1 | 10 ++++++---- scripts/environment-variable.ps1 | 13 +++++++++++++ 4 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 scripts/environment-variable.ps1 diff --git a/appveyor.yml b/appveyor.yml index f6aca98..77a873f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,7 @@ version: '0.3.7.{build}' environment: matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 CONFIGURATION: Release ARCH: Win64 @@ -19,7 +20,6 @@ environment: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 CONFIGURATION: Release ARCH: Win32 - - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu CGSS_BUILD_JNI_LIBRARY: ON matrix: fast_finish: true diff --git a/cmake/project_properties.cmake b/cmake/project_properties.cmake index 8e010b5..5318aa2 100644 --- a/cmake/project_properties.cmake +++ b/cmake/project_properties.cmake @@ -1,19 +1,23 @@ if ($ENV{CI}) - string(LENGTH $ENV{LIBCGSS_VERSION_MAJOR} VERSION_INFO_LENGTH) + if (DEFINED ENV{LIBCGSS_VERSION_MAJOR) + string(LENGTH $ENV{LIBCGSS_VERSION_MAJOR} VERSION_INFO_LENGTH) - if (VERSION_INFO_LENGTH GREATER 0) - # If we are in a CI environment, load version info from environment variables (see configure-cmake.ps1) - set(PROJECT_VERSION_MAJOR $ENV{LIBCGSS_VERSION_MAJOR}) - set(PROJECT_VERSION_MINOR $ENV{LIBCGSS_VERSION_MINOR}) - set(PROJECT_VERSION_PATCH $ENV{LIBCGSS_VERSION_PATCH}) - set(PROJECT_VERSION_TWEAK $ENV{LIBCGSS_VERSION_TWEAK}) + if (VERSION_INFO_LENGTH GREATER 0) + # If we are in a CI environment, load version info from environment variables (see configure-cmake.ps1) + set(PROJECT_VERSION_MAJOR $ENV{LIBCGSS_VERSION_MAJOR}) + set(PROJECT_VERSION_MINOR $ENV{LIBCGSS_VERSION_MINOR}) + set(PROJECT_VERSION_PATCH $ENV{LIBCGSS_VERSION_PATCH}) + set(PROJECT_VERSION_TWEAK $ENV{LIBCGSS_VERSION_TWEAK}) - set_target_properties(cgss - PROPERTIES - VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}" - SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" - ) + set_target_properties(cgss + PROPERTIES + VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}" + SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" + ) + else () + message(WARNING "Warning: CI environment detected but libcgss version is empty.") + endif () else () - message(WARNING "Warning: CI environment detected but libcgss version is not set.") + message(WARNING "Warning: CI environment detected but libcgss version is not defined.") endif () endif () diff --git a/scripts/configure-cmake.ps1 b/scripts/configure-cmake.ps1 index 3ad8d8c..fb85e79 100644 --- a/scripts/configure-cmake.ps1 +++ b/scripts/configure-cmake.ps1 @@ -19,6 +19,8 @@ elseif ($isLinux) if ($null -ne $scriptPath) { + . (Join-Path $PSScriptRoot "environment-variable.ps1") + # Setup version info if ($env:CI) { @@ -30,10 +32,10 @@ if ($null -ne $scriptPath) { [String[]]$versionParts = $buildVersion.Split('.') - [Environment]::SetEnvironmentVariable("LIBCGSS_VERSION_MAJOR", $versionParts[0], [EnvironmentVariableTarget]::User) - [Environment]::SetEnvironmentVariable("LIBCGSS_VERSION_MINOR", $versionParts[1], [EnvironmentVariableTarget]::User) - [Environment]::SetEnvironmentVariable("LIBCGSS_VERSION_PATCH", $versionParts[2], [EnvironmentVariableTarget]::User) - [Environment]::SetEnvironmentVariable("LIBCGSS_VERSION_TWEAK", "0", [EnvironmentVariableTarget]::User) # alwasy "0" + Set-PersistentEnvironmentVariable("LIBCGSS_VERSION_MAJOR", $versionParts[0]) + Set-PersistentEnvironmentVariable("LIBCGSS_VERSION_MINOR", $versionParts[1]) + Set-PersistentEnvironmentVariable("LIBCGSS_VERSION_PATCH", $versionParts[2]) + Set-PersistentEnvironmentVariable("LIBCGSS_VERSION_TWEAK", "0") # alwasy "0" } } diff --git a/scripts/environment-variable.ps1 b/scripts/environment-variable.ps1 new file mode 100644 index 0000000..5b9a797 --- /dev/null +++ b/scripts/environment-variable.ps1 @@ -0,0 +1,13 @@ +function Set-PersistentEnvironmentVariable([String] $name, [String]$value) +{ + if ($IsWindows) + { + [Environment]::SetEnvironmentVariable($name, $value, [EnvironmentVariableTarget]::User) + } + else + { + # There is still no way to persist *nix environment variables in PowerShell (PowerShell/PowerShell#4341). + # But this function should run in root scope and all CMake processes are its child so we should be OK. + Set-Item -Path "env:$name" -Value $value + } +}