Skip to content

Commit

Permalink
Version info
Browse files Browse the repository at this point in the history
  • Loading branch information
hozuki committed May 30, 2020
1 parent bb64895 commit 734d723
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmake/project_options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option(LIBCGSS_LIBRARY_VERSION "Library version. Leave it empty or provide a four-part version string (major.minor.patch.tweak)." "")
33 changes: 16 additions & 17 deletions cmake/project_properties.cmake
Original file line number Diff line number Diff line change
@@ -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 ()
12 changes: 12 additions & 0 deletions scripts/configure-cmake-ubuntu.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions scripts/configure-cmake-win.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 2 additions & 6 deletions scripts/configure-cmake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
13 changes: 0 additions & 13 deletions scripts/environment-variable.ps1

This file was deleted.

0 comments on commit 734d723

Please sign in to comment.