From 876744ad2c9c29d10b923c5f9dcd632b631ac000 Mon Sep 17 00:00:00 2001 From: Andrew Nelless Date: Thu, 27 Apr 2017 15:40:23 +0100 Subject: [PATCH] Cleanup version number handling in CMake --- CMakeLists.txt | 60 ++++++++++++++++++++++++------------- src/gui/CMakeLists.txt | 4 +-- src/gui/src/AboutDialog.cpp | 2 +- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a721ad1..6eeaff08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,41 +23,59 @@ option (SYNERGY_BUILD_LEGACY_INSTALLER "Build the installer" ON) set (CMAKE_CXX_STANDARD 14) set (CMAKE_CXX_EXTENSIONS OFF) set (CMAKE_CXX_STANDARD_REQUIRED ON) - set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") # # Version # -if ((NOT DEFINED SYNERGY_VERSION_MAJOR) AND (DEFINED ENV{SYNERGY_VERSION_MAJOR})) - set (SYNERGY_VERSION_MAJOR $ENV{SYNERGY_VERSION_MAJOR}) - set (SYNERGY_VERSION_MINOR $ENV{SYNERGY_VERSION_MINOR}) - set (SYNERGY_VERSION_PATCH $ENV{SYNERGY_VERSION_PATCH}) - set (SYNERGY_VERSION_STAGE $ENV{SYNERGY_VERSION_STAGE}) +# NOTE: We follow 'Semantic Versioning' now: http://semver.org/ + +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) + message (WARNING "SYNERGY_VERSION_MAJOR not set. Defaulted to ${SYNERGY_VERSION_MAJOR}") + endif() endif() -if (DEFINED SYNERGY_VERSION_MAJOR) - set (VERSION_MAJOR ${SYNERGY_VERSION_MAJOR}) - set (VERSION_MINOR ${SYNERGY_VERSION_MINOR}) - set (VERSION_REV ${SYNERGY_VERSION_PATCH}) - set (VERSION_STAGE ${SYNERGY_VERSION_STAGE}) -else() - message (WARNING "Synergy version number not set by build environment.") - set (VERSION_MAJOR 1) - set (VERSION_MINOR 9) - set (VERSION_REV 0) - set (VERSION_STAGE git) +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) + message (WARNING "(SYNERGY_VERSION_MINOR not set. Defaulted to ${SYNERGY_VERSION_MINOR}") + endif() endif() -set (SYNERGY_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}") -set (VERSION ${SYNERGY_VERSION}) -message (STATUS "Synergy version is " ${SYNERGY_VERSION}) +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_PATCH not set. Defaulted to ${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 "git") + message (WARNING "SYNERGY_VERSION_STAGE not set. Defaulted to ${SYNERGY_VERSION_STAGE}") + endif() +endif() + +if ((NOT DEFINED SYNERGY_REVISION) AND (DEFINED ENV{SYNERGY_REVISION})) + set (SYNERGY_REVISION $ENV{SYNERGY_REVISION}) +endif() + +set (SYNERGY_VERSION "${SYNERGY_VERSION_MAJOR}.${SYNERGY_VERSION_MINOR}.${SYNERGY_VERSION_PATCH}") # TODO: Find out why we need these, and remove them if (COMMAND cmake_policy) - cmake_policy (SET CMP0003 NEW) + cmake_policy (SET CMP0003 NEW) cmake_policy (SET CMP0005 NEW) endif() diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index a0f4122d..afb80c07 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -33,8 +33,8 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") endif() qt5_use_modules (synergy Core Widgets Network) -target_compile_definitions (synergy PRIVATE -DVERSION_STAGE="${VERSION_STAGE}") -target_compile_definitions (synergy PRIVATE -DVERSION_REVISION="${SYNERGY_GIT_COMMIT}") +target_compile_definitions (synergy PRIVATE -DSYNERGY_VERSION_STAGE="${SYNERGY_VERSION_STAGE}") +target_compile_definitions (synergy PRIVATE -DSYNERGY_REVISION="${SYNERGY_REVISION}") if (WIN32) target_link_libraries (synergy ${DNSSD_LIB}) diff --git a/src/gui/src/AboutDialog.cpp b/src/gui/src/AboutDialog.cpp index 1d2f5888..52613480 100644 --- a/src/gui/src/AboutDialog.cpp +++ b/src/gui/src/AboutDialog.cpp @@ -29,7 +29,7 @@ AboutDialog::AboutDialog(QWidget* parent, const QString& synergyApp) : m_versionChecker.setApp(synergyApp); QString version = m_versionChecker.getVersion(); - version = version + '-' + VERSION_STAGE + '-' + VERSION_REVISION; + version = version + '-' + SYNERGY_VERSION_STAGE + '-' + SYNERGY_REVISION; m_pLabelSynergyVersion->setText(version); QString buildDateString = QString::fromLocal8Bit(__DATE__).simplified();