diff options
10 files changed, 141 insertions, 26 deletions
diff --git a/modules/ECMGeneratePriFile.cmake b/modules/ECMGeneratePriFile.cmake index d5d1ce66..c679cbd9 100644 --- a/modules/ECMGeneratePriFile.cmake +++ b/modules/ECMGeneratePriFile.cmake @@ -23,6 +23,7 @@ the default qmake ``mkspecs`` directory or of a directory that will be in the ecm_generate_pri_file(BASE_NAME <baseName> LIB_NAME <libName> + [VERSION <version>] # since 5.83 [DEPS "<dep> [<dep> [...]]"] [FILENAME_VAR <filename_variable>] [INCLUDE_INSTALL_DIR <dir>] @@ -32,12 +33,17 @@ If your CMake project produces a Qt-based library, you may expect there to be applications that wish to use it that use a qmake-based build system, rather than a CMake-based one. Creating a ``.pri`` file will make use of your library convenient for them, in much the same way that CMake config files make -things convenient for CMake-based applications. - -ecm_generate_pri_file() generates just such a file. It requires the -``PROJECT_VERSION_STRING`` variable to be set. This is typically set by -:module:`ECMSetupVersion`, although the project() command in CMake 3.0.0 and -later can also set this. +things convenient for CMake-based applications. ``ecm_generate_pri_file()`` +generates just such a file. + +VERSION specifies the version of the library the ``.pri`` file describes. If +not set, the value is taken from the context variable ``PROJECT_VERSION``. +This variable is usually set by the ``project(... VERSION ...)`` command or, +if CMake policy CMP0048 is not NEW, by :module:`ECMSetupVersion`. +For backward-compatibility with older ECM versions the +``PROJECT_VERSION_STRING`` variable as set by :module:`ECMSetupVersion` +will be preferred over ``PROJECT_VERSION`` if set, unless the minimum +required version of ECM is 5.83 and newer. Since 5.83. BASE_NAME specifies the name qmake project (.pro) files should use to refer to the library (eg: KArchive). LIB_NAME is the name of the actual library to @@ -64,6 +70,7 @@ Example usage: LIB_NAME KF5KArchive DEPS "core" FILENAME_VAR pri_filename + VERSION 4.2.0 ) install(FILES ${pri_filename} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) @@ -106,7 +113,7 @@ endif() function(ECM_GENERATE_PRI_FILE) set(options ) - set(oneValueArgs BASE_NAME LIB_NAME DEPS FILENAME_VAR INCLUDE_INSTALL_DIR LIB_INSTALL_DIR) + set(oneValueArgs BASE_NAME LIB_NAME DEPS FILENAME_VAR INCLUDE_INSTALL_DIR LIB_INSTALL_DIR VERSION) set(multiValueArgs ) cmake_parse_arguments(EGPF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -115,14 +122,28 @@ function(ECM_GENERATE_PRI_FILE) message(FATAL_ERROR "Unknown keywords given to ECM_GENERATE_PRI_FILE(): \"${EGPF_UNPARSED_ARGUMENTS}\"") endif() + if("${ECM_GLOBAL_FIND_VERSION}" VERSION_LESS "5.83.0") + set(_support_backward_compat_version_string_var TRUE) + else() + set(_support_backward_compat_version_string_var FALSE) + endif() + if(NOT EGPF_BASE_NAME) message(FATAL_ERROR "Required argument BASE_NAME missing in ECM_GENERATE_PRI_FILE() call") endif() if(NOT EGPF_LIB_NAME) message(FATAL_ERROR "Required argument LIB_NAME missing in ECM_GENERATE_PRI_FILE() call") endif() - if(NOT PROJECT_VERSION_STRING) - message(FATAL_ERROR "Required variable PROJECT_VERSION_STRING not set before ECM_GENERATE_PRI_FILE() call. Did you call ecm_setup_version?") + if(NOT EGPF_VERSION) + if(_support_backward_compat_version_string_var) + if(NOT PROJECT_VERSION_STRING AND NOT PROJECT_VERSION) + message(FATAL_ERROR "Required variable PROJECT_VERSION_STRING or PROJECT_VERSION not set before ECM_GENERATE_PRI_FILE() call. Missing call of ecm_setup_version() or project(VERSION)?") + endif() + else() + if(NOT PROJECT_VERSION) + message(FATAL_ERROR "Required variable PROJECT_VERSION not set before ECM_GENERATE_PRI_FILE() call. Missing call of ecm_setup_version() or project(VERSION)?") + endif() + endif() endif() if(NOT EGPF_INCLUDE_INSTALL_DIR) if(INCLUDE_INSTALL_DIR) @@ -143,9 +164,22 @@ function(ECM_GENERATE_PRI_FILE) endif() endif() - string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" PROJECT_VERSION_MAJOR "${PROJECT_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" PROJECT_VERSION_MINOR "${PROJECT_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PROJECT_VERSION_PATCH "${PROJECT_VERSION_STRING}") + if(EGPF_VERSION) + set(PRI_VERSION "${EGPF_VERSION}") + else() + if(_support_backward_compat_version_string_var AND PROJECT_VERSION_STRING) + set(PRI_VERSION "${PROJECT_VERSION_STRING}") + if(NOT PROJECT_VERSION_STRING STREQUAL PROJECT_VERSION) + message(DEPRECATION "ECM_GENERATE_PRI_FILE() will no longer support PROJECT_VERSION_STRING when the required minimum version of ECM is 5.83 or newer. Set VERSION parameter or use PROJECT_VERSION instead.") + endif() + else() + set(PRI_VERSION "${PROJECT_VERSION}") + endif() + endif() + + string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" PRI_VERSION_MAJOR "${PRI_VERSION}") + string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" PRI_VERSION_MINOR "${PRI_VERSION}") + string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PRI_VERSION_PATCH "${PRI_VERSION}") # Prepare the right number of "../.." to go from ECM_MKSPECS_INSTALL_DIR to the install prefix # This allows to make the generated pri files relocatable (no absolute paths) @@ -191,10 +225,10 @@ function(ECM_GENERATE_PRI_FILE) file(GENERATE OUTPUT ${PRI_FILENAME} CONTENT - "QT.${PRI_TARGET_BASENAME}.VERSION = ${PROJECT_VERSION_STRING} -QT.${PRI_TARGET_BASENAME}.MAJOR_VERSION = ${PROJECT_VERSION_MAJOR} -QT.${PRI_TARGET_BASENAME}.MINOR_VERSION = ${PROJECT_VERSION_MINOR} -QT.${PRI_TARGET_BASENAME}.PATCH_VERSION = ${PROJECT_VERSION_PATCH} + "QT.${PRI_TARGET_BASENAME}.VERSION = ${PRI_VERSION} +QT.${PRI_TARGET_BASENAME}.MAJOR_VERSION = ${PRI_VERSION_MAJOR} +QT.${PRI_TARGET_BASENAME}.MINOR_VERSION = ${PRI_VERSION_MINOR} +QT.${PRI_TARGET_BASENAME}.PATCH_VERSION = ${PRI_VERSION_PATCH} QT.${PRI_TARGET_BASENAME}.name = ${PRI_TARGET_LIBNAME} QT.${PRI_TARGET_BASENAME}.module = ${PRI_TARGET_LIBNAME} QT.${PRI_TARGET_BASENAME}.defines = ${PRI_TARGET_DEFINES} diff --git a/modules/ECMSetupVersion.cmake b/modules/ECMSetupVersion.cmake index 3164a620..b67ed0d0 100644 --- a/modules/ECMSetupVersion.cmake +++ b/modules/ECMSetupVersion.cmake @@ -29,9 +29,13 @@ set:: <prefix>_VERSION_MINOR - <minor> <prefix>_VERSION_PATCH - <patch> <prefix>_VERSION - <version> - <prefix>_VERSION_STRING - <version> (for compatibility: use <prefix>_VERSION instead) <prefix>_SOVERSION - <soversion>, or <major> if SOVERSION was not given +For backward-compatibility also this variable is set (only if the minimum required +version of ECM is < 5.83):: + + <prefix>_VERSION_STRING - <version> (use <prefix>_VERSION instead) + If CMake policy CMP0048 is not NEW, the following CMake variables will also be set:: @@ -39,7 +43,11 @@ be set:: PROJECT_VERSION_MINOR - <minor> PROJECT_VERSION_PATCH - <patch> PROJECT_VERSION - <version> - PROJECT_VERSION_STRING - <version> (for compatibility: use PROJECT_VERSION instead) + +For backward-compatibility, if CMake policy CMP0048 is not NEW, also this variable is set +(only if the minimum required version of ECM is < 5.83):: + + PROJECT_VERSION_STRING - <version> (use PROJECT_VERSION instead) If the VERSION_HEADER option is used, a simple C header is generated with the given filename. If filename is a relative path, it is interpreted as relative @@ -142,6 +150,12 @@ function(ecm_setup_version _version) set(ESV_SOVERSION ${_major}) endif() + if("${ECM_GLOBAL_FIND_VERSION}" VERSION_LESS "5.83.0") + set(_set_backward_compat_version_string_vars TRUE) + else() + set(_set_backward_compat_version_string_vars FALSE) + endif() + if(should_set_prefixed_vars) set(${ESV_VARIABLE_PREFIX}_VERSION "${_version}") set(${ESV_VARIABLE_PREFIX}_VERSION_MAJOR ${_major}) @@ -158,9 +172,10 @@ function(ecm_setup_version _version) set(PROJECT_VERSION_PATCH "${_patch}") endif() - # compat - set(PROJECT_VERSION_STRING "${PROJECT_VERSION}") - set(${ESV_VARIABLE_PREFIX}_VERSION_STRING "${${ESV_VARIABLE_PREFIX}_VERSION}") + if(_set_backward_compat_version_string_vars) + set(PROJECT_VERSION_STRING "${PROJECT_VERSION}") + set(${ESV_VARIABLE_PREFIX}_VERSION_STRING "${${ESV_VARIABLE_PREFIX}_VERSION}") + endif() if(ESV_VERSION_HEADER) set(HEADER_PREFIX "${ESV_VARIABLE_PREFIX}") @@ -195,8 +210,8 @@ function(ecm_setup_version _version) set(PROJECT_VERSION_PATCH "${PROJECT_VERSION_PATCH}" PARENT_SCOPE) endif() - # always set the compatibility variables - set(PROJECT_VERSION_STRING "${PROJECT_VERSION_STRING}" PARENT_SCOPE) - set(${ESV_VARIABLE_PREFIX}_VERSION_STRING "${${ESV_VARIABLE_PREFIX}_VERSION}" PARENT_SCOPE) - + if(_set_backward_compat_version_string_vars) + set(PROJECT_VERSION_STRING "${PROJECT_VERSION_STRING}" PARENT_SCOPE) + set(${ESV_VARIABLE_PREFIX}_VERSION_STRING "${${ESV_VARIABLE_PREFIX}_VERSION}" PARENT_SCOPE) + endif() endfunction() diff --git a/tests/ECMSetupVersionTest/CMakeLists.txt b/tests/ECMSetupVersionTest/CMakeLists.txt index b0845e57..cfda7c91 100644 --- a/tests/ECMSetupVersionTest/CMakeLists.txt +++ b/tests/ECMSetupVersionTest/CMakeLists.txt @@ -14,6 +14,7 @@ macro(add_version_test NAME COMMAND) endmacro() add_version_test(old_simple dummy) +add_version_test(old_simple_no_version_string_vars dummy) add_version_test(old_soversion dummy) add_version_test(old_version_file dummy) add_version_test(old_version_file_abspath dummy) @@ -27,6 +28,7 @@ if(CMAKE_MAJOR_VERSION GREATER 2) add_version_test(new_explicit_header check_header) add_version_test(new_explicit_header_abspath check_header) add_version_test(new_explicit_simple dummy) + add_version_test(new_explicit_simple_no_version_string_vars dummy) add_version_test(new_explicit_soversion dummy) add_version_test(new_explicit_version_file dummy) add_version_test(new_explicit_version_file_abspath dummy) @@ -34,6 +36,7 @@ if(CMAKE_MAJOR_VERSION GREATER 2) add_version_test(new_project_header_abspath check_header) add_version_test(new_project_header_prefix check_header) add_version_test(new_project_simple dummy) + add_version_test(new_project_simple_no_version_string_vars dummy) add_version_test(new_project_simple_prefix dummy) add_version_test(new_project_soversion dummy) add_version_test(new_project_soversion_prefix dummy) diff --git a/tests/ECMSetupVersionTest/new_explicit_simple_no_version_string_vars/CMakeLists.txt b/tests/ECMSetupVersionTest/new_explicit_simple_no_version_string_vars/CMakeLists.txt new file mode 100644 index 00000000..8d370906 --- /dev/null +++ b/tests/ECMSetupVersionTest/new_explicit_simple_no_version_string_vars/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.0.0) + +project(new_explicit_simple VERSION 1.5.6.7) + +# trigger *_VERSION_STRING vars no longer being set +set(ECM_GLOBAL_FIND_VERSION 5.83) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../modules) +include(ECMSetupVersion) + +ecm_setup_version(2.3.4 VARIABLE_PREFIX Foo) + +include(../version_helpers.cmake) +project_version_var_checks(1.5.6.7) +version_var_checks(Foo 2.3.4) +assert_var_num_value(Foo_SOVERSION 2) + +add_executable(dummy main.c) diff --git a/tests/ECMSetupVersionTest/new_explicit_simple_no_version_string_vars/main.c b/tests/ECMSetupVersionTest/new_explicit_simple_no_version_string_vars/main.c new file mode 100644 index 00000000..c13815ce --- /dev/null +++ b/tests/ECMSetupVersionTest/new_explicit_simple_no_version_string_vars/main.c @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/tests/ECMSetupVersionTest/new_project_simple_no_version_string_vars/CMakeLists.txt b/tests/ECMSetupVersionTest/new_project_simple_no_version_string_vars/CMakeLists.txt new file mode 100644 index 00000000..2bb390a9 --- /dev/null +++ b/tests/ECMSetupVersionTest/new_project_simple_no_version_string_vars/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.0.0) + +project(new_project_simple VERSION 2.3.4) + +# trigger *_VERSION_STRING vars no longer being set +set(ECM_GLOBAL_FIND_VERSION 5.83) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../modules) +include(ECMSetupVersion) + +ecm_setup_version(PROJECT) + +include(../version_helpers.cmake) +# NB: name comes from project() command +standard_version_var_checks(new_project_simple 2.3.4) + +add_executable(dummy main.c) diff --git a/tests/ECMSetupVersionTest/new_project_simple_no_version_string_vars/main.c b/tests/ECMSetupVersionTest/new_project_simple_no_version_string_vars/main.c new file mode 100644 index 00000000..c13815ce --- /dev/null +++ b/tests/ECMSetupVersionTest/new_project_simple_no_version_string_vars/main.c @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/tests/ECMSetupVersionTest/old_simple_no_version_string_vars/CMakeLists.txt b/tests/ECMSetupVersionTest/old_simple_no_version_string_vars/CMakeLists.txt new file mode 100644 index 00000000..5b3a9b09 --- /dev/null +++ b/tests/ECMSetupVersionTest/old_simple_no_version_string_vars/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5) + +cmake_policy(SET CMP0048 OLD) +project(old_simple) + +# trigger *_VERSION_STRING vars no longer being set +set(ECM_GLOBAL_FIND_VERSION 5.83) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../modules) +include(ECMSetupVersion) + +ecm_setup_version(2.3.4 VARIABLE_PREFIX Foo) + +include(../version_helpers.cmake) +standard_version_var_checks(Foo 2.3.4) + +add_executable(dummy main.c) diff --git a/tests/ECMSetupVersionTest/old_simple_no_version_string_vars/main.c b/tests/ECMSetupVersionTest/old_simple_no_version_string_vars/main.c new file mode 100644 index 00000000..c13815ce --- /dev/null +++ b/tests/ECMSetupVersionTest/old_simple_no_version_string_vars/main.c @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/tests/ECMSetupVersionTest/version_helpers.cmake b/tests/ECMSetupVersionTest/version_helpers.cmake index de0a36b5..6254322f 100644 --- a/tests/ECMSetupVersionTest/version_helpers.cmake +++ b/tests/ECMSetupVersionTest/version_helpers.cmake @@ -43,7 +43,9 @@ endmacro() macro(version_var_checks prefix version) assert_var_str_value(${prefix}_VERSION "${version}") - assert_var_str_value(${prefix}_VERSION_STRING "${version}") + if("${ECM_GLOBAL_FIND_VERSION}" VERSION_LESS "5.83.0") + assert_var_str_value(${prefix}_VERSION_STRING "${version}") + endif() if("${version}" MATCHES "^([0-9]+)") assert_var_num_value(${prefix}_VERSION_MAJOR ${CMAKE_MATCH_1}) endif() |