Cleanup version number handling in CMake

This commit is contained in:
Andrew Nelless 2017-04-27 15:40:23 +01:00
parent 380e2db9aa
commit 876744ad2c
3 changed files with 42 additions and 24 deletions

View File

@ -23,41 +23,59 @@ option (SYNERGY_BUILD_LEGACY_INSTALLER "Build the installer" ON)
set (CMAKE_CXX_STANDARD 14) set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_EXTENSIONS OFF) set (CMAKE_CXX_EXTENSIONS OFF)
set (CMAKE_CXX_STANDARD_REQUIRED ON) set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
# #
# Version # Version
# #
if ((NOT DEFINED SYNERGY_VERSION_MAJOR) AND (DEFINED ENV{SYNERGY_VERSION_MAJOR})) # NOTE: We follow 'Semantic Versioning' now: http://semver.org/
set (SYNERGY_VERSION_MAJOR $ENV{SYNERGY_VERSION_MAJOR})
set (SYNERGY_VERSION_MINOR $ENV{SYNERGY_VERSION_MINOR}) if (NOT DEFINED SYNERGY_VERSION_MAJOR)
set (SYNERGY_VERSION_PATCH $ENV{SYNERGY_VERSION_PATCH}) if (DEFINED ENV{SYNERGY_VERSION_MAJOR})
set (SYNERGY_VERSION_STAGE $ENV{SYNERGY_VERSION_STAGE}) 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() endif()
if (DEFINED SYNERGY_VERSION_MAJOR) if (NOT DEFINED SYNERGY_VERSION_MINOR)
set (VERSION_MAJOR ${SYNERGY_VERSION_MAJOR}) if (DEFINED ENV{SYNERGY_VERSION_MINOR})
set (VERSION_MINOR ${SYNERGY_VERSION_MINOR}) set (SYNERGY_VERSION_MINOR $ENV{SYNERGY_VERSION_MINOR})
set (VERSION_REV ${SYNERGY_VERSION_PATCH}) else()
set (VERSION_STAGE ${SYNERGY_VERSION_STAGE}) set (SYNERGY_VERSION_MINOR 9)
else() message (WARNING "(SYNERGY_VERSION_MINOR not set. Defaulted to ${SYNERGY_VERSION_MINOR}")
message (WARNING "Synergy version number not set by build environment.") endif()
set (VERSION_MAJOR 1)
set (VERSION_MINOR 9)
set (VERSION_REV 0)
set (VERSION_STAGE git)
endif() endif()
set (SYNERGY_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}") if (NOT DEFINED SYNERGY_VERSION_PATCH)
set (VERSION ${SYNERGY_VERSION}) if (DEFINED ENV{SYNERGY_VERSION_PATCH})
message (STATUS "Synergy version is " ${SYNERGY_VERSION}) 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 # TODO: Find out why we need these, and remove them
if (COMMAND cmake_policy) if (COMMAND cmake_policy)
cmake_policy (SET CMP0003 NEW) cmake_policy (SET CMP0003 NEW)
cmake_policy (SET CMP0005 NEW) cmake_policy (SET CMP0005 NEW)
endif() endif()

View File

@ -33,8 +33,8 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
endif() endif()
qt5_use_modules (synergy Core Widgets Network) qt5_use_modules (synergy Core Widgets Network)
target_compile_definitions (synergy PRIVATE -DVERSION_STAGE="${VERSION_STAGE}") target_compile_definitions (synergy PRIVATE -DSYNERGY_VERSION_STAGE="${SYNERGY_VERSION_STAGE}")
target_compile_definitions (synergy PRIVATE -DVERSION_REVISION="${SYNERGY_GIT_COMMIT}") target_compile_definitions (synergy PRIVATE -DSYNERGY_REVISION="${SYNERGY_REVISION}")
if (WIN32) if (WIN32)
target_link_libraries (synergy ${DNSSD_LIB}) target_link_libraries (synergy ${DNSSD_LIB})

View File

@ -29,7 +29,7 @@ AboutDialog::AboutDialog(QWidget* parent, const QString& synergyApp) :
m_versionChecker.setApp(synergyApp); m_versionChecker.setApp(synergyApp);
QString version = m_versionChecker.getVersion(); QString version = m_versionChecker.getVersion();
version = version + '-' + VERSION_STAGE + '-' + VERSION_REVISION; version = version + '-' + SYNERGY_VERSION_STAGE + '-' + SYNERGY_REVISION;
m_pLabelSynergyVersion->setText(version); m_pLabelSynergyVersion->setText(version);
QString buildDateString = QString::fromLocal8Bit(__DATE__).simplified(); QString buildDateString = QString::fromLocal8Bit(__DATE__).simplified();