From e13dd52535bd68c33106dfc9027ce15cabf68ccf Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sun, 23 Jan 2022 23:08:44 +0200 Subject: XL: Detect default extensions mode for legacy compiler The legacy non-Clang variant seems to support a GNU-like extensions mode, which is the default. Enable detection for it. --- Modules/CMakeCCompilerId.c.in | 2 +- Modules/CMakeCXXCompilerId.cpp.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in index 30ad9824..0cb8724 100644 --- a/Modules/CMakeCCompilerId.c.in +++ b/Modules/CMakeCCompilerId.c.in @@ -61,7 +61,7 @@ const char* info_language_standard_default = const char* info_language_extensions_default = "INFO" ":" "extensions_default[" /* !defined(_MSC_VER) to exclude Clang's MSVC compatibility mode. */ -#if (defined(__clang__) || defined(__GNUC__) || \ +#if (defined(__clang__) || defined(__GNUC__) || defined(__xlC__) || \ defined(__TI_COMPILER_VERSION__)) && \ !defined(__STRICT_ANSI__) && !defined(_MSC_VER) "ON" diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in index e7a5487..4904249 100644 --- a/Modules/CMakeCXXCompilerId.cpp.in +++ b/Modules/CMakeCXXCompilerId.cpp.in @@ -67,7 +67,7 @@ const char* info_language_standard_default = "INFO" ":" "standard_default[" const char* info_language_extensions_default = "INFO" ":" "extensions_default[" /* !defined(_MSC_VER) to exclude Clang's MSVC compatibility mode. */ -#if (defined(__clang__) || defined(__GNUC__) || \ +#if (defined(__clang__) || defined(__GNUC__) || defined(__xlC__) || \ defined(__TI_COMPILER_VERSION__)) && \ !defined(__STRICT_ANSI__) && !defined(_MSC_VER) "ON" -- cgit v0.12 From 3a089cd2560db80f9534b9c86a0a7af495533466 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sat, 22 Jan 2022 17:40:10 +0200 Subject: CMP0128: Prefix test names with mode Makes clear that these tests are for the NEW behaviour. --- .../CMP0128NewExtensionsStandardDefault-build-check.cmake | 12 ++++++++++++ .../CMP0128NewExtensionsStandardDefault.cmake | 9 +++++++++ .../CMP0128NewExtensionsStandardUnset-build-check.cmake | 12 ++++++++++++ .../CMP0128NewExtensionsStandardUnset.cmake | 8 ++++++++ .../CMP0128NewNoUnnecessaryFlag-build-check.cmake | 8 ++++++++ .../CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake | 9 +++++++++ .../ExtensionsStandardDefault-build-check.cmake | 12 ------------ .../CompileFeatures/ExtensionsStandardDefault.cmake | 9 --------- .../ExtensionsStandardUnset-build-check.cmake | 12 ------------ .../RunCMake/CompileFeatures/ExtensionsStandardUnset.cmake | 8 -------- .../CompileFeatures/NoUnnecessaryFlag-build-check.cmake | 8 -------- Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake | 9 --------- Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake | 14 +++++++------- 13 files changed, 65 insertions(+), 65 deletions(-) create mode 100644 Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault-build-check.cmake create mode 100644 Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault.cmake create mode 100644 Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset-build-check.cmake create mode 100644 Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset.cmake create mode 100644 Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag-build-check.cmake create mode 100644 Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake delete mode 100644 Tests/RunCMake/CompileFeatures/ExtensionsStandardDefault-build-check.cmake delete mode 100644 Tests/RunCMake/CompileFeatures/ExtensionsStandardDefault.cmake delete mode 100644 Tests/RunCMake/CompileFeatures/ExtensionsStandardUnset-build-check.cmake delete mode 100644 Tests/RunCMake/CompileFeatures/ExtensionsStandardUnset.cmake delete mode 100644 Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake delete mode 100644 Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake diff --git a/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault-build-check.cmake b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault-build-check.cmake new file mode 100644 index 0000000..4e85397 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault-build-check.cmake @@ -0,0 +1,12 @@ +foreach(flag @flags@) + string(FIND "${actual_stdout}" "${flag}" position) + + if(NOT position EQUAL -1) + set(found TRUE) + break() + endif() +endforeach() + +if(NOT found) + set(RunCMake_TEST_FAILED "No compile flags from \"@flags@\" found for LANG_STANDARD=default and @lang@_EXTENSIONS=@extensions_opposite@.") +endif() diff --git a/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault.cmake b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault.cmake new file mode 100644 index 0000000..32578d1 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault.cmake @@ -0,0 +1,9 @@ +enable_language(@lang@) + +# Make sure the compile command is not hidden. +string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") +string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") + +set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@) +set(CMAKE_@lang@_STANDARD @standard_default@) +add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset-build-check.cmake b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset-build-check.cmake new file mode 100644 index 0000000..abe293c --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset-build-check.cmake @@ -0,0 +1,12 @@ +foreach(flag @flags@) + string(FIND "${actual_stdout}" "${flag}" position) + + if(NOT position EQUAL -1) + set(found TRUE) + break() + endif() +endforeach() + +if(NOT found) + set(RunCMake_TEST_FAILED "No compile flags from \"@flags@\" found for CMAKE_@lang@_EXTENSIONS=@extensions_opposite@.") +endif() diff --git a/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset.cmake b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset.cmake new file mode 100644 index 0000000..99bb3f0 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset.cmake @@ -0,0 +1,8 @@ +enable_language(@lang@) + +# Make sure the compile command is not hidden. +string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") +string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") + +set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@) +add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag-build-check.cmake b/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag-build-check.cmake new file mode 100644 index 0000000..4f767fa --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag-build-check.cmake @@ -0,0 +1,8 @@ +foreach(flag @flags@) + string(FIND "${actual_stdout}" "${flag}" position) + + if(NOT position EQUAL -1) + set(RunCMake_TEST_FAILED "\"${flag}\" compile flag found.") + break() + endif() +endforeach() diff --git a/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake b/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake new file mode 100644 index 0000000..8ef3a72 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake @@ -0,0 +1,9 @@ +enable_language(@lang@) + +# Make sure the compile command is not hidden. +string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") +string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") + +set(CMAKE_@lang@_EXTENSIONS @extensions_default@) +set(CMAKE_@lang@_STANDARD @standard_default@) +add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/ExtensionsStandardDefault-build-check.cmake b/Tests/RunCMake/CompileFeatures/ExtensionsStandardDefault-build-check.cmake deleted file mode 100644 index 4e85397..0000000 --- a/Tests/RunCMake/CompileFeatures/ExtensionsStandardDefault-build-check.cmake +++ /dev/null @@ -1,12 +0,0 @@ -foreach(flag @flags@) - string(FIND "${actual_stdout}" "${flag}" position) - - if(NOT position EQUAL -1) - set(found TRUE) - break() - endif() -endforeach() - -if(NOT found) - set(RunCMake_TEST_FAILED "No compile flags from \"@flags@\" found for LANG_STANDARD=default and @lang@_EXTENSIONS=@extensions_opposite@.") -endif() diff --git a/Tests/RunCMake/CompileFeatures/ExtensionsStandardDefault.cmake b/Tests/RunCMake/CompileFeatures/ExtensionsStandardDefault.cmake deleted file mode 100644 index 32578d1..0000000 --- a/Tests/RunCMake/CompileFeatures/ExtensionsStandardDefault.cmake +++ /dev/null @@ -1,9 +0,0 @@ -enable_language(@lang@) - -# Make sure the compile command is not hidden. -string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") -string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") - -set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@) -set(CMAKE_@lang@_STANDARD @standard_default@) -add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/ExtensionsStandardUnset-build-check.cmake b/Tests/RunCMake/CompileFeatures/ExtensionsStandardUnset-build-check.cmake deleted file mode 100644 index abe293c..0000000 --- a/Tests/RunCMake/CompileFeatures/ExtensionsStandardUnset-build-check.cmake +++ /dev/null @@ -1,12 +0,0 @@ -foreach(flag @flags@) - string(FIND "${actual_stdout}" "${flag}" position) - - if(NOT position EQUAL -1) - set(found TRUE) - break() - endif() -endforeach() - -if(NOT found) - set(RunCMake_TEST_FAILED "No compile flags from \"@flags@\" found for CMAKE_@lang@_EXTENSIONS=@extensions_opposite@.") -endif() diff --git a/Tests/RunCMake/CompileFeatures/ExtensionsStandardUnset.cmake b/Tests/RunCMake/CompileFeatures/ExtensionsStandardUnset.cmake deleted file mode 100644 index 99bb3f0..0000000 --- a/Tests/RunCMake/CompileFeatures/ExtensionsStandardUnset.cmake +++ /dev/null @@ -1,8 +0,0 @@ -enable_language(@lang@) - -# Make sure the compile command is not hidden. -string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") -string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") - -set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@) -add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake b/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake deleted file mode 100644 index 4f767fa..0000000 --- a/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake +++ /dev/null @@ -1,8 +0,0 @@ -foreach(flag @flags@) - string(FIND "${actual_stdout}" "${flag}" position) - - if(NOT position EQUAL -1) - set(RunCMake_TEST_FAILED "\"${flag}\" compile flag found.") - break() - endif() -endforeach() diff --git a/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake b/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake deleted file mode 100644 index 8ef3a72..0000000 --- a/Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake +++ /dev/null @@ -1,9 +0,0 @@ -enable_language(@lang@) - -# Make sure the compile command is not hidden. -string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") -string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") - -set(CMAKE_@lang@_EXTENSIONS @extensions_default@) -set(CMAKE_@lang@_STANDARD @standard_default@) -add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index ebd981b..fc2fa06 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -68,7 +68,7 @@ macro(mangle_flags variable) list(APPEND flags "${result}") endmacro() -function(test_extensions_opposite) +function(test_cmp0128_new_extensions_opposite) if(extensions_opposite) set(flag_ext "_EXT") endif() @@ -83,16 +83,16 @@ function(test_extensions_opposite) # Make sure we enable/disable extensions when: # 1. LANG_STANDARD is unset. - set(name ExtensionsStandardUnset) + set(name CMP0128NewExtensionsStandardUnset) set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0128=NEW) test_build(--verbose) # 2. LANG_STANDARD matches CMAKE_LANG_STANDARD_DEFAULT. - set(name ExtensionsStandardDefault) + set(name CMP0128NewExtensionsStandardDefault) test_build(--verbose) endfunction() -function(test_no_unnecessary_flag) +function(test_cmp0128_new_no_unnecessary_flag) set(standard_flag "${${lang}${${lang}_STANDARD_DEFAULT}_FLAG}") set(extension_flag "${${lang}${${lang}_STANDARD_DEFAULT}_EXT_FLAG}") @@ -103,7 +103,7 @@ function(test_no_unnecessary_flag) mangle_flags(standard_flag) mangle_flags(extension_flag) - set(name NoUnnecessaryFlag) + set(name CMP0128NewNoUnnecessaryFlag) set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0128=NEW) test_build(--verbose) endfunction() @@ -144,8 +144,8 @@ function(test_lang lang ext) set(extensions_opposite ON) endif() - test_extensions_opposite() - test_no_unnecessary_flag() + test_cmp0128_new_extensions_opposite() + test_cmp0128_new_no_unnecessary_flag() test_cmp0128_warn_match() test_cmp0128_warn_unset() endfunction() -- cgit v0.12 From b2c25de8e0e2d53d3ff2ad37ed33d4b8a9bf8b1a Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sat, 22 Jan 2022 17:45:14 +0200 Subject: CMP0128: Avoid test code duplication --- Tests/RunCMake/CompileFeatures/CMP0128Common.cmake | 7 +++++++ .../CompileFeatures/CMP0128NewExtensionsStandardDefault.cmake | 7 ------- .../CompileFeatures/CMP0128NewExtensionsStandardUnset.cmake | 7 ------- Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake | 7 ------- Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake | 2 -- Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake | 2 -- Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake | 4 +++- 7 files changed, 10 insertions(+), 26 deletions(-) create mode 100644 Tests/RunCMake/CompileFeatures/CMP0128Common.cmake diff --git a/Tests/RunCMake/CompileFeatures/CMP0128Common.cmake b/Tests/RunCMake/CompileFeatures/CMP0128Common.cmake new file mode 100644 index 0000000..b309d74 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128Common.cmake @@ -0,0 +1,7 @@ +enable_language(@lang@) + +# Make sure the compile command is not hidden. +string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") +string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") + +add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault.cmake b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault.cmake index 32578d1..5b7358a 100644 --- a/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault.cmake +++ b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardDefault.cmake @@ -1,9 +1,2 @@ -enable_language(@lang@) - -# Make sure the compile command is not hidden. -string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") -string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") - set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@) set(CMAKE_@lang@_STANDARD @standard_default@) -add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset.cmake b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset.cmake index 99bb3f0..6923c11 100644 --- a/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset.cmake +++ b/Tests/RunCMake/CompileFeatures/CMP0128NewExtensionsStandardUnset.cmake @@ -1,8 +1 @@ -enable_language(@lang@) - -# Make sure the compile command is not hidden. -string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") -string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") - set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@) -add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake b/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake index 8ef3a72..73c0641 100644 --- a/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake +++ b/Tests/RunCMake/CompileFeatures/CMP0128NewNoUnnecessaryFlag.cmake @@ -1,9 +1,2 @@ -enable_language(@lang@) - -# Make sure the compile command is not hidden. -string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") -string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}") - set(CMAKE_@lang@_EXTENSIONS @extensions_default@) set(CMAKE_@lang@_STANDARD @standard_default@) -add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake b/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake index 0a5606a..7974093 100644 --- a/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake +++ b/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake @@ -1,7 +1,5 @@ -enable_language(@lang@) cmake_policy(SET CMP0128 OLD) set(CMAKE_POLICY_WARNING_CMP0128 ON) set(CMAKE_@lang@_EXTENSIONS @extensions_default@) set(CMAKE_@lang@_STANDARD @standard_default@) -add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake b/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake index cd7af2c..33425a1 100644 --- a/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake +++ b/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake @@ -1,6 +1,4 @@ -enable_language(@lang@) cmake_policy(SET CMP0128 OLD) set(CMAKE_POLICY_WARNING_CMP0128 ON) set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@) -add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@") diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index fc2fa06..35b01e3 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -35,11 +35,13 @@ elseif (cxx_std_98 IN_LIST CXX_FEATURES AND cxx_std_11 IN_LIST CXX_FEATURES) endif() configure_file("${RunCMake_SOURCE_DIR}/CMakeLists.txt" "${RunCMake_BINARY_DIR}/CMakeLists.txt" COPYONLY) +file(READ "${RunCMake_SOURCE_DIR}/CMP0128Common.cmake" cmp0128_common) function(test_build) set(test ${name}-${lang}) - configure_file("${RunCMake_SOURCE_DIR}/${name}.cmake" "${RunCMake_BINARY_DIR}/${test}.cmake" @ONLY) + file(READ "${RunCMake_SOURCE_DIR}/${name}.cmake" cmake) + file(CONFIGURE OUTPUT "${RunCMake_BINARY_DIR}/${test}.cmake" CONTENT "${cmake}${cmp0128_common}" @ONLY) if(EXISTS "${RunCMake_SOURCE_DIR}/${name}-build-check.cmake") configure_file("${RunCMake_SOURCE_DIR}/${name}-build-check.cmake" "${RunCMake_BINARY_DIR}/${test}-build-check.cmake" @ONLY) endif() -- cgit v0.12 From ee1396e29e98dbd3a4517ce364a534c80bc6fb4a Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sat, 22 Jan 2022 17:29:45 +0200 Subject: CMP0128: Add flag in OLD mode even when standard matches the default Commit 4a0485be (cmStandardLevelResolver: Avoid unnecessary flags, fix unset level logic, 2021-04-29) unintentionally changed the behavior by modifying the code to match a pre-existing comment. The resulting behavior change however matches the intentions of CMP0128, so we simply need to guard it. Fixes #23122. --- Help/release/3.22.rst | 6 ++++++ Source/cmStandardLevelResolver.cxx | 5 +++-- .../CMP0128OldSameStandard-build-check.cmake | 12 ++++++++++++ .../CompileFeatures/CMP0128OldSameStandard.cmake | 1 + Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/CompileFeatures/CMP0128OldSameStandard-build-check.cmake create mode 100644 Tests/RunCMake/CompileFeatures/CMP0128OldSameStandard.cmake diff --git a/Help/release/3.22.rst b/Help/release/3.22.rst index fcb655d..4cc34fa 100644 --- a/Help/release/3.22.rst +++ b/Help/release/3.22.rst @@ -142,3 +142,9 @@ Other Changes This became available as of VS 16.10 (toolchain version 14.29.30037). * The :cpack_gen:`CPack NSIS Generator` now requires NSIS 3.03 or later. + +3.22.2 +------ + +* The ``OLD`` behavior of :policy:`CMP0128` was fixed to add flags even when + the specified standard matches the compiler default. diff --git a/Source/cmStandardLevelResolver.cxx b/Source/cmStandardLevelResolver.cxx index 61416e0..acc2ed2 100644 --- a/Source/cmStandardLevelResolver.cxx +++ b/Source/cmStandardLevelResolver.cxx @@ -206,8 +206,9 @@ struct StandardLevelComputer // If the standard requested is older than the compiler's default or the // extension mode doesn't match then we need to use a flag. - if (stdIt < defaultStdIt || - (cmp0128 == cmPolicies::NEW && ext != defaultExt)) { + if ((cmp0128 != cmPolicies::NEW && stdIt <= defaultStdIt) || + (cmp0128 == cmPolicies::NEW && + (stdIt < defaultStdIt || ext != defaultExt))) { auto offset = std::distance(cm::cbegin(stds), stdIt); return cmStrCat("CMAKE_", this->Language, stdsStrings[offset], "_", type, "_COMPILE_OPTION"); diff --git a/Tests/RunCMake/CompileFeatures/CMP0128OldSameStandard-build-check.cmake b/Tests/RunCMake/CompileFeatures/CMP0128OldSameStandard-build-check.cmake new file mode 100644 index 0000000..8074b9d --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128OldSameStandard-build-check.cmake @@ -0,0 +1,12 @@ +foreach(flag @flags@) + string(FIND "${actual_stdout}" "${flag}" position) + + if(NOT position EQUAL -1) + set(found TRUE) + break() + endif() +endforeach() + +if(NOT found) + set(RunCMake_TEST_FAILED "No compile flags from \"@flags@\" found for LANG_STANDARD=default.") +endif() diff --git a/Tests/RunCMake/CompileFeatures/CMP0128OldSameStandard.cmake b/Tests/RunCMake/CompileFeatures/CMP0128OldSameStandard.cmake new file mode 100644 index 0000000..3be0f10 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/CMP0128OldSameStandard.cmake @@ -0,0 +1 @@ +set(CMAKE_@lang@_STANDARD @standard_default@) diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index 35b01e3..ad9619e 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -70,6 +70,23 @@ macro(mangle_flags variable) list(APPEND flags "${result}") endmacro() +function(test_cmp0128_old_same_standard) + if(extensions_default) + set(flag_ext "_EXT") + endif() + + set(flag "${${lang}${${lang}_STANDARD_DEFAULT}${flag_ext}_FLAG}") + + if(NOT flag) + return() + endif() + + mangle_flags(flag) + + set(name CMP0128OldSameStandard) + test_build(--verbose) +endfunction() + function(test_cmp0128_new_extensions_opposite) if(extensions_opposite) set(flag_ext "_EXT") @@ -148,6 +165,7 @@ function(test_lang lang ext) test_cmp0128_new_extensions_opposite() test_cmp0128_new_no_unnecessary_flag() + test_cmp0128_old_same_standard() test_cmp0128_warn_match() test_cmp0128_warn_unset() endfunction() -- cgit v0.12