CMake/Source/CMakeVersionCompute.cmake
Brad King 588a1afe76 CMakeVersion.rc: Avoid leading zeros in integer version components
The split in commit v3.11.0-rc1~232^2 (CMakeVersion RC file: Split patch
into 2 components, 2017-12-01) can leave components "2018,0309", but the
latter is an octal constant with digit "9" out of range.  Strip the
leading zero to express the components as "2018,309" so the resource
compiler treats them as decimal.
2018-03-09 10:52:49 -05:00

45 lines
1.7 KiB
CMake

# Load version number components.
include(${CMake_SOURCE_DIR}/Source/CMakeVersion.cmake)
# Releases define a small patch level.
if("${CMake_VERSION_PATCH}" VERSION_LESS 20000000)
set(CMake_VERSION_IS_DIRTY 0)
set(CMake_VERSION_IS_RELEASE 1)
set(CMake_VERSION_SOURCE "")
else()
set(CMake_VERSION_IS_DIRTY 0) # may be set to 1 by CMakeVersionSource
set(CMake_VERSION_IS_RELEASE 0)
include(${CMake_SOURCE_DIR}/Source/CMakeVersionSource.cmake)
endif()
# Compute the full version string.
set(CMake_VERSION ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH})
if(CMake_VERSION_SOURCE)
set(CMake_VERSION_SUFFIX "${CMake_VERSION_SOURCE}")
elseif(CMake_VERSION_RC)
set(CMake_VERSION_SUFFIX "rc${CMake_VERSION_RC}")
else()
set(CMake_VERSION_SUFFIX "")
endif()
if(CMake_VERSION_SUFFIX)
set(CMake_VERSION ${CMake_VERSION}-${CMake_VERSION_SUFFIX})
endif()
if(CMake_VERSION_IS_DIRTY)
set(CMake_VERSION ${CMake_VERSION}-dirty)
endif()
# Compute the binary version that appears in the RC file. Version
# components in the RC file are 16-bit integers so we may have to
# split the patch component.
if(CMake_VERSION_PATCH MATCHES "^([0-9]+)([0-9][0-9][0-9][0-9])$")
set(CMake_RCVERSION_YEAR "${CMAKE_MATCH_1}")
set(CMake_RCVERSION_MONTH_DAY "${CMAKE_MATCH_2}")
string(REGEX REPLACE "^0+" "" CMake_RCVERSION_MONTH_DAY "${CMake_RCVERSION_MONTH_DAY}")
set(CMake_RCVERSION ${CMake_VERSION_MAJOR},${CMake_VERSION_MINOR},${CMake_RCVERSION_YEAR},${CMake_RCVERSION_MONTH_DAY})
unset(CMake_RCVERSION_MONTH_DAY)
unset(CMake_RCVERSION_YEAR)
else()
set(CMake_RCVERSION ${CMake_VERSION_MAJOR},${CMake_VERSION_MINOR},${CMake_VERSION_PATCH})
endif()
set(CMake_RCVERSION_STR ${CMake_VERSION})