aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2021-03-31 11:41:40 +0200
committerFriedrich W. H. Kossebau <kossebau@kde.org>2021-03-31 11:41:40 +0200
commitd88db6a1469bdcb48e64f265d35a6f7867767b54 (patch)
tree5acdf6e89f15760e79f25942fda778358240ce3b
parent04f4675cbb874b53f4e6024ecea5b0d9c472bf7c (diff)
downloadextra-cmake-modules-5.81.0.tar.gz
extra-cmake-modules-5.81.0.tar.bz2
ECMGenerateExportHeader: do sanity check for version argument valuesv5.81.0-rc2v5.81.0-rc1v5.81.0
To prevent accidental use of the C++-side hex number-style version variants on the cmake side where human-readable style is used instead (which can happen due to the similar names of the cmake variables/arguments and C++ macros which screws up developers' brain) we better do some proper input checks also on the arguments EXCLUDE_DEPRECATED_BEFORE_AND_AT and DEPRECATED_BASE_VERSION
-rw-r--r--modules/ECMGenerateExportHeader.cmake17
1 files changed, 14 insertions, 3 deletions
diff --git a/modules/ECMGenerateExportHeader.cmake b/modules/ECMGenerateExportHeader.cmake
index 310c2194..0ee3b411 100644
--- a/modules/ECMGenerateExportHeader.cmake
+++ b/modules/ECMGenerateExportHeader.cmake
@@ -44,7 +44,9 @@
# If not set, the generated code will ignore any such macros.
#
# ``DEPRECATED_BASE_VERSION`` specifies the default version before and at which
-# deprecated API is disabled. The default is the value of
+# deprecated API is disabled. Possible values are "0", "CURRENT" (which
+# resolves to <version>) and a version string in the format
+# "<major>.<minor>.<patchlevel>". The default is the value of
# "<exclude_deprecated_before_and_at_version>" if set, or "<major>.0.0", with
# <major> taken from <version>.
#
@@ -437,9 +439,13 @@ function(ecm_generate_export_header target)
)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ # helper string
+ set(_version_triple_regexp "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$")
# args sanity check
if (NOT ARGS_VERSION)
message(FATAL_ERROR "No VERSION passed when calling ecm_generate_export_header().")
+ elseif(NOT ARGS_VERSION MATCHES ${_version_triple_regexp})
+ message(FATAL_ERROR "VERSION expected to be in x.y.z format when calling ecm_generate_export_header().")
endif()
if (ARGS_INCLUDE_GUARD_NAME AND CMAKE_VERSION VERSION_LESS 3.11)
message(FATAL_ERROR "Argument INCLUDE_GUARD_NAME needs at least CMake 3.11 when calling ecm_generate_export_header().")
@@ -448,18 +454,23 @@ function(ecm_generate_export_header target)
set(ARGS_EXCLUDE_DEPRECATED_BEFORE_AND_AT 0)
elseif(ARGS_EXCLUDE_DEPRECATED_BEFORE_AND_AT STREQUAL "CURRENT")
set(ARGS_EXCLUDE_DEPRECATED_BEFORE_AND_AT ${ARGS_VERSION})
+ elseif(NOT ARGS_EXCLUDE_DEPRECATED_BEFORE_AND_AT MATCHES ${_version_triple_regexp} AND
+ NOT ARGS_EXCLUDE_DEPRECATED_BEFORE_AND_AT STREQUAL "0")
+ message(FATAL_ERROR "EXCLUDE_DEPRECATED_BEFORE_AND_AT expected to be in \"x.y.z\" format, \"0\" or \"CURRENT\" when calling ecm_generate_export_header().")
endif()
if (NOT DEFINED ARGS_DEPRECATED_BASE_VERSION)
if (ARGS_EXCLUDE_DEPRECATED_BEFORE_AND_AT)
set(ARGS_DEPRECATED_BASE_VERSION "${ARGS_EXCLUDE_DEPRECATED_BEFORE_AND_AT}")
else()
- string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\1"
- _version_major "${ARGS_VERSION}")
+ string(REGEX REPLACE ${_version_triple_regexp} "\\1" _version_major "${ARGS_VERSION}")
set(ARGS_DEPRECATED_BASE_VERSION "${_version_major}.0.0")
endif()
else()
if(ARGS_DEPRECATED_BASE_VERSION STREQUAL "CURRENT")
set(ARGS_DEPRECATED_BASE_VERSION ${ARGS_VERSION})
+ elseif(NOT ARGS_DEPRECATED_BASE_VERSION MATCHES ${_version_triple_regexp} AND
+ NOT ARGS_DEPRECATED_BASE_VERSION STREQUAL "0")
+ message(FATAL_ERROR "DEPRECATED_BASE_VERSION expected to be in \"x.y.z\" format, \"0\" or \"CURRENT\" when calling ecm_generate_export_header().")
endif()
if (ARGS_DEPRECATED_BASE_VERSION VERSION_LESS ARGS_EXCLUDE_DEPRECATED_BEFORE_AND_AT)
message(STATUS "DEPRECATED_BASE_VERSION (${ARGS_DEPRECATED_BASE_VERSION}) was lower than EXCLUDE_DEPRECATED_BEFORE_AND_AT (${ARGS_EXCLUDE_DEPRECATED_BEFORE_AND_AT}) when calling ecm_generate_export_header(), raising to that.")