|
| 1 | +# Set build variables if env variables are defined |
| 2 | +# These are used in configured files such as manifests for different packages |
| 3 | +if(DEFINED ENV{BRANCH}) # cmake-lint: disable=W0106 |
| 4 | + set(GITHUB_BRANCH $ENV{BRANCH}) |
| 5 | +endif() |
| 6 | +if(DEFINED ENV{BUILD_VERSION}) # cmake-lint: disable=W0106 |
| 7 | + set(BUILD_VERSION $ENV{BUILD_VERSION}) |
| 8 | +endif() |
| 9 | +if(DEFINED ENV{CLONE_URL}) # cmake-lint: disable=W0106 |
| 10 | + set(GITHUB_CLONE_URL $ENV{CLONE_URL}) |
| 11 | +endif() |
| 12 | +if(DEFINED ENV{COMMIT}) # cmake-lint: disable=W0106 |
| 13 | + set(GITHUB_COMMIT $ENV{COMMIT}) |
| 14 | +endif() |
| 15 | +if(DEFINED ENV{TAG}) # cmake-lint: disable=W0106 |
| 16 | + set(GITHUB_TAG $ENV{TAG}) |
| 17 | +endif() |
| 18 | + |
1 | 19 | # Check if env vars are defined before attempting to access them, variables will be defined even if blank |
2 | | -if((DEFINED ENV{BRANCH}) AND (DEFINED ENV{BUILD_VERSION}) AND (DEFINED ENV{COMMIT})) # cmake-lint: disable=W0106 |
3 | | - if(($ENV{BRANCH} STREQUAL "master") AND (NOT $ENV{BUILD_VERSION} STREQUAL "")) |
4 | | - # If BRANCH is "master" and BUILD_VERSION is not empty, then we are building a master branch |
5 | | - MESSAGE("Got from CI master branch and version $ENV{BUILD_VERSION}") |
| 20 | +if((DEFINED ENV{BRANCH}) AND (DEFINED ENV{BUILD_VERSION})) # cmake-lint: disable=W0106 |
| 21 | + if((DEFINED ENV{BRANCH}) AND (NOT $ENV{BUILD_VERSION} STREQUAL "")) |
| 22 | + # If BRANCH is defined and BUILD_VERSION is not empty, then we are building from CI |
| 23 | + # If BRANCH is master we are building a push/release build |
| 24 | + MESSAGE("Got from CI '$ENV{BRANCH}' branch and version '$ENV{BUILD_VERSION}'") |
6 | 25 | set(PROJECT_VERSION $ENV{BUILD_VERSION}) |
7 | 26 | set(CMAKE_PROJECT_VERSION ${PROJECT_VERSION}) # cpack will use this to set the binary versions |
8 | | - elseif((DEFINED ENV{BRANCH}) AND (DEFINED ENV{COMMIT})) |
9 | | - # If BRANCH is set but not BUILD_VERSION we are building a PR, we gather only the commit hash |
10 | | - MESSAGE("Got from CI $ENV{BRANCH} branch and commit $ENV{COMMIT}") |
11 | | - set(PROJECT_VERSION ${PROJECT_VERSION}.$ENV{COMMIT}) |
12 | 27 | endif() |
| 28 | +else() |
13 | 29 | # Generate Sunshine Version based of the git tag |
14 | 30 | # https://github.com/nocnokneo/cmake-git-versioning-example/blob/master/LICENSE |
15 | | -else() |
16 | 31 | find_package(Git) |
17 | 32 | if(GIT_EXECUTABLE) |
18 | 33 | MESSAGE("${CMAKE_SOURCE_DIR}") |
@@ -85,3 +100,9 @@ if(PROJECT_VERSION MATCHES "^([0-9]{4})[.]([0-9]{3,4})") |
85 | 100 | set(PROJECT_DAY "0${PROJECT_DAY}") |
86 | 101 | endif() |
87 | 102 | endif() |
| 103 | + |
| 104 | +message("PROJECT_VERSION: ${PROJECT_VERSION}") |
| 105 | +message("CMAKE_PROJECT_VERSION: ${CMAKE_PROJECT_VERSION}") |
| 106 | +message("PROJECT_YEAR: ${PROJECT_YEAR}") |
| 107 | +message("PROJECT_MONTH: ${PROJECT_MONTH}") |
| 108 | +message("PROJECT_DAY: ${PROJECT_DAY}") |
0 commit comments