Skip to content

Commit

Permalink
Environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
hozuki committed May 30, 2020
1 parent 2d4a44b commit bb64895
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
30 changes: 17 additions & 13 deletions cmake/project_properties.cmake
Original file line number Diff line number Diff line change
@@ -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 ()
10 changes: 6 additions & 4 deletions scripts/configure-cmake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ elseif ($isLinux)

if ($null -ne $scriptPath)
{
. (Join-Path $PSScriptRoot "environment-variable.ps1")

# Setup version info
if ($env:CI)
{
Expand All @@ -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"
}
}

Expand Down
13 changes: 13 additions & 0 deletions scripts/environment-variable.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit bb64895

Please sign in to comment.