aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2021-04-21 14:59:29 +0200
committerFriedrich W. H. Kossebau <kossebau@kde.org>2021-04-24 15:42:46 +0200
commit7f47f20babb936a1b5422d03f79491e6017455db (patch)
tree68425ac858cdf5f050f385b6ad80f7524e0d6e43 /tests
parent5512e03562694ebfe571a3b6068a7d35d9ddfd7a (diff)
downloadextra-cmake-modules-7f47f20babb936a1b5422d03f79491e6017455db.tar.gz
extra-cmake-modules-7f47f20babb936a1b5422d03f79491e6017455db.tar.bz2
ECMGenerateExportHeader: add macros for enumerator deprecation warning
Diffstat (limited to 'tests')
-rw-r--r--tests/ECMGenerateExportHeaderTest/consumer/CMakeLists.txt11
-rw-r--r--tests/ECMGenerateExportHeaderTest/consumer/testAPI_DISABLE_DEPRECATED_BEFORE_AND_AT.cmake31
-rw-r--r--tests/ECMGenerateExportHeaderTest/consumer/testAPI_NO_DEPRECATED.cmake25
-rw-r--r--tests/ECMGenerateExportHeaderTest/library/library.hpp5
4 files changed, 55 insertions, 17 deletions
diff --git a/tests/ECMGenerateExportHeaderTest/consumer/CMakeLists.txt b/tests/ECMGenerateExportHeaderTest/consumer/CMakeLists.txt
index ba5940cd..ee042969 100644
--- a/tests/ECMGenerateExportHeaderTest/consumer/CMakeLists.txt
+++ b/tests/ECMGenerateExportHeaderTest/consumer/CMakeLists.txt
@@ -24,7 +24,16 @@ include(testAPI_${TEST_VARIANT}.cmake)
# for each API element test their visibility to the compiler and if a warning is emitted
set(_code "Enum enumerator = Enumerator_deprecatedAt2_0;")
-testAPI(_code DEPRECATED_AT 2.0 BUILD_TIME_ONLY_DISABLABLE NO_WARNING)
+testAPI(_code DEPRECATED_AT 2.0 CXX_STANDARD 11 BUILD_TIME_ONLY_DISABLABLE NO_WARNING)
+
+set(_code "Enum enumerator = Enumerator_deprecatedAt2_0;")
+testAPI(_code DEPRECATED_AT 2.0 CXX_STANDARD 17 BUILD_TIME_ONLY_DISABLABLE)
+
+set(_code "Enum enumerator = Enumerator_deprecatedAt2_12;")
+testAPI(_code DEPRECATED_AT 2.12 CXX_STANDARD 11 NO_WARNING)
+
+set(_code "Enum enumerator = Enumerator_deprecatedAt2_12;")
+testAPI(_code DEPRECATED_AT 2.12 CXX_STANDARD 17)
set(_code "Enum enumerator = Enumerator_not_deprecated;")
testAPI(_code)
diff --git a/tests/ECMGenerateExportHeaderTest/consumer/testAPI_DISABLE_DEPRECATED_BEFORE_AND_AT.cmake b/tests/ECMGenerateExportHeaderTest/consumer/testAPI_DISABLE_DEPRECATED_BEFORE_AND_AT.cmake
index 70065cdf..df7716a1 100644
--- a/tests/ECMGenerateExportHeaderTest/consumer/testAPI_DISABLE_DEPRECATED_BEFORE_AND_AT.cmake
+++ b/tests/ECMGenerateExportHeaderTest/consumer/testAPI_DISABLE_DEPRECATED_BEFORE_AND_AT.cmake
@@ -24,7 +24,7 @@ endif()
function(testAPI code_var_name)
set(options BUILD_TIME_ONLY_DISABLABLE NO_WARNING)
- set(oneValueArgs DEPRECATED_AT)
+ set(oneValueArgs DEPRECATED_AT CXX_STANDARD)
set(multiValueArgs)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@@ -36,6 +36,17 @@ function(testAPI code_var_name)
set(_build_result_expected FALSE)
endif()
+ if (ARGS_CXX_STANDARD)
+ if(MSVC)
+ set(std_flag "/std:c++${ARGS_CXX_STANDARD}")
+ else()
+ set(std_flag "-std=c++${ARGS_CXX_STANDARD}")
+ endif()
+ else()
+ set(std_flag)
+ endif()
+
+ set(CMAKE_REQUIRED_FLAGS "${std_flag}")
set(CMAKE_REQUIRED_LIBRARIES library)
set(CMAKE_REQUIRED_DEFINITIONS "-D${_deprecation_macros_base_name}_DISABLE_DEPRECATED_BEFORE_AND_AT=${disable_deprecated_before_and_at_hexnumber}")
@@ -54,24 +65,26 @@ int main(int, char**)
# check warning
if(_build_result_expected)
- if((ARGS_BUILD_TIME_ONLY_DISABLABLE AND NOT ARGS_NO_WARNING) OR
- (NOT ARGS_BUILD_TIME_ONLY_DISABLABLE AND ARGS_DEPRECATED_AT AND
- ARGS_DEPRECATED_AT VERSION_GREATER LIBRARY_DISABLE_DEPRECATED_BEFORE_AND_AT))
- set(_dep_warning_result_expected FALSE)
+ if(NOT ARGS_NO_WARNING AND
+ ((ARGS_BUILD_TIME_ONLY_DISABLABLE) OR
+ (NOT ARGS_BUILD_TIME_ONLY_DISABLABLE AND ARGS_DEPRECATED_AT AND
+ ARGS_DEPRECATED_AT VERSION_GREATER LIBRARY_DISABLE_DEPRECATED_BEFORE_AND_AT)))
+ set(_dep_warning_as_error_result_expected FALSE)
else()
- set(_dep_warning_result_expected TRUE)
+ set(_dep_warning_as_error_result_expected TRUE)
endif()
if(MSVC)
# warning C4996 warns about deprecated declarations
- set(CMAKE_REQUIRED_FLAGS "-we4996")
+ set(dep_warning_as_error_flag "-we4996")
else()
- set(CMAKE_REQUIRED_FLAGS "-Werror=deprecated-declarations")
+ set(dep_warning_as_error_flag "-Werror=deprecated-declarations")
endif()
+ set(CMAKE_REQUIRED_FLAGS "${std_flag} ${dep_warning_as_error_flag}")
set(CMAKE_REQUIRED_DEFINITIONS) # unset LIBRARY_DISABLE_DEPRECATED_BEFORE_AND_AT, as LIBRARY_DEPRECATED_WARNINGS_SINCE defaults to it
unset(_dep_warning_result CACHE) # clear out as check_cxx_source_compiles caches the result
check_cxx_source_compiles("${_code}" _dep_warning_result)
- assert_var_bool_value(_dep_warning_result ${_dep_warning_result_expected})
+ assert_var_bool_value(_dep_warning_result ${_dep_warning_as_error_result_expected})
endif()
endfunction()
diff --git a/tests/ECMGenerateExportHeaderTest/consumer/testAPI_NO_DEPRECATED.cmake b/tests/ECMGenerateExportHeaderTest/consumer/testAPI_NO_DEPRECATED.cmake
index fa6a63ec..b01dfc3d 100644
--- a/tests/ECMGenerateExportHeaderTest/consumer/testAPI_NO_DEPRECATED.cmake
+++ b/tests/ECMGenerateExportHeaderTest/consumer/testAPI_NO_DEPRECATED.cmake
@@ -6,7 +6,7 @@ endif()
function(testAPI code_var_name)
set(options BUILD_TIME_ONLY_DISABLABLE NO_WARNING)
- set(oneValueArgs DEPRECATED_AT)
+ set(oneValueArgs DEPRECATED_AT CXX_STANDARD)
set(multiValueArgs)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@@ -17,6 +17,17 @@ function(testAPI code_var_name)
set(_build_result_expected FALSE)
endif()
+ if (ARGS_CXX_STANDARD)
+ if(MSVC)
+ set(std_flag "/std:c++${ARGS_CXX_STANDARD}")
+ else()
+ set(std_flag "-std=c++${ARGS_CXX_STANDARD}")
+ endif()
+ else()
+ set(std_flag)
+ endif()
+
+ set(CMAKE_REQUIRED_FLAGS "${std_flag}")
set(CMAKE_REQUIRED_LIBRARIES library)
set(CMAKE_REQUIRED_DEFINITIONS "-D${_deprecation_macros_base_name}_NO_DEPRECATED")
@@ -36,20 +47,22 @@ int main(int, char**)
# check warning
if(_build_result_expected)
if(ARGS_BUILD_TIME_ONLY_DISABLABLE AND NOT ARGS_NO_WARNING)
- set(_dep_warning_result_expected FALSE)
+ set(_dep_warning_as_error_result_expected FALSE)
else()
- set(_dep_warning_result_expected TRUE)
+ set(_dep_warning_as_error_result_expected TRUE)
endif()
if(MSVC)
# warning C4996 warns about deprecated declarations
- set(CMAKE_REQUIRED_FLAGS "-we4996")
+ set(dep_warning_as_error_flag "-we4996")
else()
- set(CMAKE_REQUIRED_FLAGS "-Werror=deprecated-declarations")
+ set(dep_warning_as_error_flag "-Werror=deprecated-declarations")
endif()
+
+ set(CMAKE_REQUIRED_FLAGS "${std_flag} ${dep_warning_as_error_flag}")
set(CMAKE_REQUIRED_DEFINITIONS) # unset LIBRARY_DISABLE_DEPRECATED_BEFORE_AND_AT, as LIBRARY_DEPRECATED_WARNINGS_SINCE defaults to it
unset(_dep_warning_result CACHE) # clear out as check_cxx_source_compiles caches the result
check_cxx_source_compiles("${_code}" _dep_warning_result)
- assert_var_bool_value(_dep_warning_result ${_dep_warning_result_expected})
+ assert_var_bool_value(_dep_warning_result ${_dep_warning_as_error_result_expected})
endif()
endfunction()
diff --git a/tests/ECMGenerateExportHeaderTest/library/library.hpp b/tests/ECMGenerateExportHeaderTest/library/library.hpp
index 2124bf8a..4afe87ac 100644
--- a/tests/ECMGenerateExportHeaderTest/library/library.hpp
+++ b/tests/ECMGenerateExportHeaderTest/library/library.hpp
@@ -2,9 +2,12 @@
enum Enum {
#if LIBRARY_BUILD_DEPRECATED_SINCE(2, 0)
- Enumerator_deprecatedAt2_0,
+ Enumerator_deprecatedAt2_0 LIBRARY_ENUMERATOR_DEPRECATED_VERSION(2, 0, "Deprecated at 2.0"),
#endif
Enumerator_not_deprecated,
+#if LIBRARY_ENABLE_DEPRECATED_SINCE(2, 12)
+ Enumerator_deprecatedAt2_12 LIBRARY_ENUMERATOR_DEPRECATED_VERSION(2, 12, "Deprecated at 2.12"),
+#endif
};
#if LIBRARY_ENABLE_DEPRECATED_SINCE(2, 0)