From 734d72349302aec67654c046ff17f747f43626e1 Mon Sep 17 00:00:00 2001 From: George Wu Date: Sat, 30 May 2020 19:12:56 +0200 Subject: [PATCH] Version info --- CMakeLists.txt | 2 ++ cmake/project_options.cmake | 1 + cmake/project_properties.cmake | 33 +++++++++++++++--------------- scripts/configure-cmake-ubuntu.ps1 | 12 +++++++++++ scripts/configure-cmake-win.ps1 | 12 +++++++++++ scripts/configure-cmake.ps1 | 8 ++------ scripts/environment-variable.ps1 | 13 ------------ 7 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 cmake/project_options.cmake delete mode 100644 scripts/environment-variable.ps1 diff --git a/CMakeLists.txt b/CMakeLists.txt index e1e7439..1e4051a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ include(cmake/common_defines.cmake) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/${TARGET_ARCH}/${CMAKE_BUILD_TYPE}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) +include(cmake/project_options.cmake) + include(cmake/project_files.cmake) include(cmake/project_targets.cmake) include(cmake/project_properties.cmake) diff --git a/cmake/project_options.cmake b/cmake/project_options.cmake new file mode 100644 index 0000000..8468e81 --- /dev/null +++ b/cmake/project_options.cmake @@ -0,0 +1 @@ +option(LIBCGSS_LIBRARY_VERSION "Library version. Leave it empty or provide a four-part version string (major.minor.patch.tweak)." "") diff --git a/cmake/project_properties.cmake b/cmake/project_properties.cmake index 5318aa2..7b56233 100644 --- a/cmake/project_properties.cmake +++ b/cmake/project_properties.cmake @@ -1,23 +1,22 @@ if ($ENV{CI}) - if (DEFINED ENV{LIBCGSS_VERSION_MAJOR) - string(LENGTH $ENV{LIBCGSS_VERSION_MAJOR} VERSION_INFO_LENGTH) + string(LENGTH LIBCGSS_LIBRARY_VERSION 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) + string(REPLACE "." ";" VERSION_COMPONENTS ${LIBCGSS_LIBRARY_VERSION}) - 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 () + # If we are in a CI environment, load version info from environment variables (see configure-cmake.ps1) + list(GET VERSION_COMPONENTS 0 PROJECT_VERSION_MAJOR) + list(GET VERSION_COMPONENTS 1 PROJECT_VERSION_MINOR) + list(GET VERSION_COMPONENTS 2 PROJECT_VERSION_PATCH) + # Always 0 + set(PROJECT_VERSION_TWEAK 0) + + 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 not defined.") + message(WARNING "Warning: CI environment detected but libcgss version is empty.") endif () endif () diff --git a/scripts/configure-cmake-ubuntu.ps1 b/scripts/configure-cmake-ubuntu.ps1 index 5e902d5..aa1c5a1 100644 --- a/scripts/configure-cmake-ubuntu.ps1 +++ b/scripts/configure-cmake-ubuntu.ps1 @@ -82,6 +82,18 @@ $cmakeParams.AddRange([System.Linq.Enumerable]::Select( }) ) +if ($env:CI) +{ + if (-not [String]::IsNullOrWhiteSpace($env:LIBCGSS_LIBRARY_VERSION)) + { + $cmakeParams.Add("-DLIBCGSS_LIBRARY_VERSION=`"$env:LIBCGSS_LIBRARY_VERSION`"") + } + else + { + Write-Error "Should not happen." + } +} + $cmakeParams.AddRange([String[]]@("-DCMAKE_BUILD_TYPE=MinSizeRel", "../..")) $cmakeParamsLit = [String]::Join(' ', $cmakeParams) diff --git a/scripts/configure-cmake-win.ps1 b/scripts/configure-cmake-win.ps1 index 1f7c130..1f3cd86 100644 --- a/scripts/configure-cmake-win.ps1 +++ b/scripts/configure-cmake-win.ps1 @@ -69,6 +69,18 @@ $cmakeParams.AddRange([System.Linq.Enumerable]::Select( }) ) +if ($env:CI) +{ + if (-not [String]::IsNullOrWhiteSpace($env:LIBCGSS_LIBRARY_VERSION)) + { + $cmakeParams.Add("-DLIBCGSS_LIBRARY_VERSION=`"$env:LIBCGSS_LIBRARY_VERSION`"") + } + else + { + Write-Error "Should not happen." + } +} + if ($multiPlatform) { [String]$cmakeGenArch = 'Win32'; diff --git a/scripts/configure-cmake.ps1 b/scripts/configure-cmake.ps1 index fb85e79..f3b9e36 100644 --- a/scripts/configure-cmake.ps1 +++ b/scripts/configure-cmake.ps1 @@ -30,12 +30,8 @@ if ($null -ne $scriptPath) if (-not([String]::IsNullOrWhiteSpace($buildVersion))) { - [String[]]$versionParts = $buildVersion.Split('.') - - 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" + # OK I give up. + $env:LIBCGSS_LIBRARY_VERSION = $buildVersion } } diff --git a/scripts/environment-variable.ps1 b/scripts/environment-variable.ps1 deleted file mode 100644 index 5b9a797..0000000 --- a/scripts/environment-variable.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -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 - } -}