From c20346971db87af5deee59d7d04af86e680f52c0 Mon Sep 17 00:00:00 2001 From: Andrew Nelless Date: Sat, 27 May 2017 14:01:49 +0100 Subject: [PATCH] Move version number handling out of main CMake file --- Build.properties | 2 +- CMakeLists.txt | 90 +-------------------------------------------- cmake/Version.cmake | 90 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 89 deletions(-) create mode 100644 cmake/Version.cmake diff --git a/Build.properties b/Build.properties index 18ad0b51..75a143ab 100644 --- a/Build.properties +++ b/Build.properties @@ -4,4 +4,4 @@ SYNERGY_VERSION_MAJOR = 1 SYNERGY_VERSION_MINOR = 9 SYNERGY_VERSION_PATCH = 0 -SYNERGY_VERSION_STAGE = rc4 +SYNERGY_VERSION_STAGE = snapshot diff --git a/CMakeLists.txt b/CMakeLists.txt index e8619128..61cb4648 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,95 +32,9 @@ if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") endif() # -# Version +# Synergy version # -if (NOT DEFINED SYNERGY_VERSION_MAJOR) - if (DEFINED ENV{SYNERGY_VERSION_MAJOR}) - set (SYNERGY_VERSION_MAJOR $ENV{SYNERGY_VERSION_MAJOR}) - else() - set (SYNERGY_VERSION_MAJOR 1) - set (SYNERGY_VERSION_WARNED 1) - message (WARNING "SYNERGY_VERSION_MAJOR not set. Defaulted to ${SYNERGY_VERSION_MAJOR}") - endif() -endif() - -if (NOT DEFINED SYNERGY_VERSION_MINOR) - if (DEFINED ENV{SYNERGY_VERSION_MINOR}) - set (SYNERGY_VERSION_MINOR $ENV{SYNERGY_VERSION_MINOR}) - else() - set (SYNERGY_VERSION_MINOR 9) - if (NOT ${SYNERGY_VERSION_WARNED}) - set (SYNERGY_VERSION_WARNED 1) - message (WARNING "(SYNERGY_VERSION_MINOR not set. Defaulted to ${SYNERGY_VERSION_MINOR}") - endif() - endif() -endif() - -if (NOT DEFINED SYNERGY_VERSION_PATCH) - if (DEFINED ENV{SYNERGY_VERSION_PATCH}) - set (SYNERGY_VERSION_PATCH $ENV{SYNERGY_VERSION_PATCH}) - else() - set (SYNERGY_VERSION_PATCH 0) - if (NOT ${SYNERGY_VERSION_WARNED}) - set (SYNERGY_VERSION_WARNED 1) - message (WARNING "SYNERGY_VERSION_PATCH not set. Defaulted to ${SYNERGY_VERSION_PATCH}") - endif() - endif() -endif() - -if (NOT DEFINED SYNERGY_VERSION_STAGE) - if (DEFINED ENV{SYNERGY_VERSION_STAGE}) - set (SYNERGY_VERSION_STAGE $ENV{SYNERGY_VERSION_STAGE}) - else() - set (SYNERGY_VERSION_STAGE "git") - if (NOT ${SYNERGY_VERSION_WARNED}) - set (SYNERGY_VERSION_WARNED 1) - message (WARNING "SYNERGY_VERSION_STAGE not set. Defaulted to '${SYNERGY_VERSION_STAGE}'") - endif() - endif() -endif() - -if (NOT DEFINED SYNERGY_REVISION) - if (DEFINED ENV{GIT_COMMIT}) - string (SUBSTRING $ENV{GIT_COMMIT} 0 8 SYNERGY_REVISION) - elseif (SYNERGY_VERSION_STAGE STREQUAL "git") - execute_process ( - COMMAND git rev-parse --short=8 HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE SYNERGY_REVISION - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - endif() -endif() - -if (DEFINED SYNERGY_REVISION) - string(LENGTH ${SYNERGY_REVISION} SYNERGY_REVISION_LENGTH) - if (NOT ((SYNERGY_REVISION MATCHES "^[a-f0-9]+") AND (SYNERGY_REVISION_LENGTH EQUAL "8"))) - message (FATAL_ERROR "SYNERGY_REVISION='${SYNERGY_REVISION}' should be a short git commit hash") - endif() - unset (SYNERGY_REVISION_LENGTH) -else() - -endif() -if (DEFINED ENV{BUILD_NUMBER}) - set (SYNERGY_BUILD_NUMBER $ENV{BUILD_NUMBER}) -else() - set (SYNERGY_BUILD_NUMBER 1) -endif() - -string (TIMESTAMP SYNERGY_BUILD_DATE "%Y%m%d" UTC) - -if (SYNERGY_VERSION_STAGE STREQUAL "git") - set (SYNERGY_SNAPSHOT_INFO ".unstable.${SYNERGY_REVISION}") - set (SYNERGY_VERSION_TAG "unstable.b${SYNERGY_BUILD_NUMBER}-${SYNERGY_REVISION}") -else() - set (SYNERGY_SNAPSHOT_INFO ".${SYNERGY_VERSION_STAGE}.${SYNERGY_REVISION}") - set (SYNERGY_VERSION_TAG "${SYNERGY_VERSION_STAGE}.b${SYNERGY_BUILD_NUMBER}-${SYNERGY_REVISION}") -endif() - -set (SYNERGY_VERSION "${SYNERGY_VERSION_MAJOR}.${SYNERGY_VERSION_MINOR}.${SYNERGY_VERSION_PATCH}") -set (SYNERGY_VERSION_STRING "${SYNERGY_VERSION}-${SYNERGY_VERSION_TAG}") -message (STATUS "Full Synergy version string is " ${SYNERGY_VERSION_STRING}) +include (cmake/Version.cmake) # TODO: Find out why we need these, and remove them if (COMMAND cmake_policy) diff --git a/cmake/Version.cmake b/cmake/Version.cmake new file mode 100644 index 00000000..266744e6 --- /dev/null +++ b/cmake/Version.cmake @@ -0,0 +1,90 @@ +cmake_minimum_required (VERSION 3.4) + +# +# Synergy Version +# +if (NOT DEFINED SYNERGY_VERSION_MAJOR) + if (DEFINED ENV{SYNERGY_VERSION_MAJOR}) + set (SYNERGY_VERSION_MAJOR $ENV{SYNERGY_VERSION_MAJOR}) + else() + set (SYNERGY_VERSION_MAJOR 1) + endif() +endif() + +if (NOT DEFINED SYNERGY_VERSION_MINOR) + if (DEFINED ENV{SYNERGY_VERSION_MINOR}) + set (SYNERGY_VERSION_MINOR $ENV{SYNERGY_VERSION_MINOR}) + else() + set (SYNERGY_VERSION_MINOR 9) + endif() +endif() + +if (NOT DEFINED SYNERGY_VERSION_PATCH) + if (DEFINED ENV{SYNERGY_VERSION_PATCH}) + set (SYNERGY_VERSION_PATCH $ENV{SYNERGY_VERSION_PATCH}) + else() + set (SYNERGY_VERSION_PATCH 0) + message (WARNING "Synergy version wasn't set. Set to ${SYNERGY_VERSION_MAJOR}.${SYNERGY_VERSION_MINOR}.${SYNERGY_VERSION_PATCH}") + endif() +endif() + +if (NOT DEFINED SYNERGY_VERSION_STAGE) + if (DEFINED ENV{SYNERGY_VERSION_STAGE}) + set (SYNERGY_VERSION_STAGE $ENV{SYNERGY_VERSION_STAGE}) + else() + set (SYNERGY_VERSION_STAGE "snapshot") + endif() +endif() + +if (NOT DEFINED SYNERGY_REVISION) + if (DEFINED ENV{GIT_COMMIT}) + string (SUBSTRING $ENV{GIT_COMMIT} 0 8 SYNERGY_REVISION) + elseif (SYNERGY_VERSION_STAGE STREQUAL "snapshot") + execute_process ( + COMMAND git rev-parse --short=8 HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE SYNERGY_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() +endif() + +if (DEFINED SYNERGY_REVISION) + string(LENGTH ${SYNERGY_REVISION} SYNERGY_REVISION_LENGTH) + if (NOT ((SYNERGY_REVISION MATCHES "^[a-f0-9]+") AND (SYNERGY_REVISION_LENGTH EQUAL "8"))) + message (FATAL_ERROR "SYNERGY_REVISION ('${SYNERGY_REVISION}') should be a short commit hash") + endif() + unset (SYNERGY_REVISION_LENGTH) +else() + set (SYNERGY_REVISION "0badc0de") +endif() + +if (DEFINED ENV{BUILD_NUMBER}) + set (SYNERGY_BUILD_NUMBER $ENV{BUILD_NUMBER}) +else() + set (SYNERGY_BUILD_NUMBER 1) +endif() + +string (TIMESTAMP SYNERGY_BUILD_DATE "%Y%m%d" UTC) +set (SYNERGY_SNAPSHOT_INFO ".${SYNERGY_VERSION_STAGE}.${SYNERGY_REVISION}") + +if (SYNERGY_VERSION_STAGE STREQUAL "snapshot") + set (SYNERGY_VERSION_TAG "${SYNERGY_VERSION_STAGE}.b${SYNERGY_BUILD_NUMBER}-${SYNERGY_REVISION}") +else() + set (SYNERGY_VERSION_TAG "${SYNERGY_VERSION_STAGE}") +endif() + +set (SYNERGY_VERSION "${SYNERGY_VERSION_MAJOR}.${SYNERGY_VERSION_MINOR}.${SYNERGY_VERSION_PATCH}") +set (SYNERGY_VERSION_STRING "${SYNERGY_VERSION}-${SYNERGY_VERSION_TAG}") +message (STATUS "Full Synergy version string is '" ${SYNERGY_VERSION_STRING} "'") + +add_definitions (-DSYNERGY_VERSION="${SYNERGY_VERSION}") +add_definitions (-DSYNERGY_VERSION_STRING="${SYNERGY_VERSION_STRING}") +add_definitions (-DSYNERGY_REVISION="${SYNERGY_REVISION}") +add_definitions (-DSYNERGY_BUILD_DATE="${SYNERGY_BUILD_DATE}") +add_definitions (-DSYNERGY_BUILD_NUMBER=${SYNERGY_BUILD_NUMBER}) + +if (SYNERGY_DEVELOPER_MODE) + add_definitions (-DSYNERGY_DEVELOPER_MODE=1) +endif() +