cmlib/CMLibProjectVersion.cmake

31 lines
1.2 KiB
CMake
Raw Normal View History

2019-02-12 16:31:17 +00:00
# read file cmake/etc/version.txt and set global properties
# VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_INT and VERSION_STR
function(set_project_version)
set(_version_file "${CMAKE_SOURCE_DIR}/cmake/etc/version.txt")
if(NOT EXISTS "${_version_file}")
message(FATAL_ERROR "File ${_version_file} doesn't exists")
endif()
file(READ "${_version_file}" _version)
2019-02-16 10:10:12 +00:00
set_property(DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${_version_file})
2019-02-12 16:31:17 +00:00
if(NOT "${_version}" MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\n")
message(FATAL_ERROR "${_version_file} has wrong format")
endif()
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\n" _ ${_version})
set_property(GLOBAL PROPERTY VERSION_MAJOR ${CMAKE_MATCH_1})
set_property(GLOBAL PROPERTY VERSION_MINOR ${CMAKE_MATCH_2})
set_property(GLOBAL PROPERTY VERSION_PATCH ${CMAKE_MATCH_3})
2019-02-16 10:10:12 +00:00
math(EXPR _version_int
"(${CMAKE_MATCH_1} << 16) + (${CMAKE_MATCH_2} << 8) + ${CMAKE_MATCH_3}")
2019-02-12 16:31:17 +00:00
set_property(GLOBAL PROPERTY VERSION_INT ${_version_int})
2019-02-16 10:10:12 +00:00
set_property(GLOBAL
PROPERTY VERSION_STR
"${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
2019-02-12 16:31:17 +00:00
endfunction()