Использовать номер версии, установленный в функции project()

This commit is contained in:
Andrei Astafev 2019-02-20 17:18:32 +03:00
parent 9c4c3ae2e4
commit 331d9079c5
6 changed files with 11 additions and 33 deletions

View File

@ -1,4 +1,4 @@
get_property(CPACK_PACKAGE_VERSION GLOBAL PROPERTY VERSION_STR) get_property(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SOURCE_GENERATOR TXZ) set(CPACK_SOURCE_GENERATOR TXZ)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_IGNORE_FILE "cmake/etc/cpack_ignore.txt") set(CPACK_IGNORE_FILE "cmake/etc/cpack_ignore.txt")

View File

@ -31,6 +31,7 @@ include(CMLibBuildTypes)
include(CMLibCodeAnalysisPvsStudio) include(CMLibCodeAnalysisPvsStudio)
include(cotire) include(cotire)
include(CMLibBreathe)
include(CMLibQtTranslation) include(CMLibQtTranslation)
include(CMLibToday) include(CMLibToday)
include(CMLibConfigHPPGenerate) include(CMLibConfigHPPGenerate)

View File

@ -9,11 +9,9 @@ function(add_common_library LIBNAME SOURCES)
set_target_properties(${LIBNAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(${LIBNAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_library(${LIBNAME}_shared SHARED $<TARGET_OBJECTS:${LIBNAME}>) add_library(${LIBNAME}_shared SHARED $<TARGET_OBJECTS:${LIBNAME}>)
get_property(_ver GLOBAL PROPERTY VERSION_STR)
get_property(_sover GLOBAL PROPERTY VERSION_MAJOR)
set_target_properties(${LIBNAME}_shared set_target_properties(${LIBNAME}_shared
PROPERTIES VERSION ${_ver} PROPERTIES VERSION ${PROJECT_VERSION}
SOVERSION ${_sover} SOVERSION ${PROJECT_VERSION_MAJOR}
OUTPUT_NAME ${LIBNAME} OUTPUT_NAME ${LIBNAME}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR}) LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR})

View File

@ -2,8 +2,7 @@ function(cmlib_config_hpp_generate)
include(CMLibLargeFiles) include(CMLibLargeFiles)
cmlib_test_large_files(HAVE_LARGEFILES) cmlib_test_large_files(HAVE_LARGEFILES)
get_property(VERSION_INT GLOBAL PROPERTY VERSION_INT) get_property(PROJECT_VERSION_INT GLOBAL PROPERTY PROJECT_VERSION_INT)
get_property(VERSION_STR GLOBAL PROPERTY VERSION_STR)
get_property(ORGANIZATION_NAME GLOBAL PROPERTY ORGANIZATION_NAME) get_property(ORGANIZATION_NAME GLOBAL PROPERTY ORGANIZATION_NAME)
configure_file(${CMLIB_MODULE_DIR}/hpp/config.hpp.in configure_file(${CMLIB_MODULE_DIR}/hpp/config.hpp.in
${CMAKE_BINARY_DIR}/include/config.hpp) ${CMAKE_BINARY_DIR}/include/config.hpp)

View File

@ -1,30 +1,10 @@
# 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) function(set_project_version)
set(_version_file "${CMAKE_SOURCE_DIR}/cmake/etc/version.txt") if(NOT ${PROJECT_VERSION_PATCH} MATCHES "([0-9]+)")
if(NOT EXISTS "${_version_file}") message(FATAL_ERROR "Please set project version in X.Y.Z format")
message(FATAL_ERROR "File ${_version_file} doesn't exists")
endif()
file(READ "${_version_file}" _version)
set_property(DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS ${_version_file})
if(NOT "${_version}" MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\n")
message(FATAL_ERROR "${_version_file} has wrong format")
endif() 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})
math(EXPR _version_int math(EXPR _version_int
"(${CMAKE_MATCH_1} << 16) + (${CMAKE_MATCH_2} << 8) + ${CMAKE_MATCH_3}") "(${PROJECT_VERSION_MAJOR} << 16) + (${PROJECT_VERSION_MINOR} << 8) + ${PROJECT_VERSION_PATCH}")
set_property(GLOBAL PROPERTY VERSION_INT ${_version_int}) set_property(GLOBAL PROPERTY PROJECT_VERSION_INT ${_version_int})
set_property(GLOBAL
PROPERTY VERSION_STR
"${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
endfunction() endfunction()

View File

@ -1,8 +1,8 @@
#ifndef @CMLIB_PROJECT_NAME_CANONICAL@_CONFIG_HPP_ #ifndef @CMLIB_PROJECT_NAME_CANONICAL@_CONFIG_HPP_
#define @CMLIB_PROJECT_NAME_CANONICAL@_CONFIG_HPP_ #define @CMLIB_PROJECT_NAME_CANONICAL@_CONFIG_HPP_
#define @CMLIB_PROJECT_NAME_CANONICAL@_VERSION_STR "@VERSION_STR@" #define @CMLIB_PROJECT_NAME_CANONICAL@_VERSION_STR "@PROJECT_VERSION@"
#define @CMLIB_PROJECT_NAME_CANONICAL@_VERSION_INT @VERSION_INT@ #define @CMLIB_PROJECT_NAME_CANONICAL@_VERSION_INT @PROJECT_VERSION_INT@
#define ORGANIZATION_NAME "@ORGANIZATION_NAME@" #define ORGANIZATION_NAME "@ORGANIZATION_NAME@"
#define PROJECT_NAME "@CMAKE_PROJECT_NAME@" #define PROJECT_NAME "@CMAKE_PROJECT_NAME@"
#define BUILD_TYPE "@CMAKE_BUILD_TYPE@" #define BUILD_TYPE "@CMAKE_BUILD_TYPE@"