summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZsolt Parragi <zsolt.parragi@cancellar.hu>2019-02-26 13:36:11 (GMT)
committerBrad King <brad.king@kitware.com>2019-02-26 19:35:55 (GMT)
commitc7213ca87064ba47984b4dd07192389366d5856a (patch)
tree12469f6a8290de8aae94775e208657a15789bb0b
parent7c292b37cfb28407f7716c63561c8ff7f0dc5540 (diff)
downloadCMake-c7213ca87064ba47984b4dd07192389366d5856a.zip
CMake-c7213ca87064ba47984b4dd07192389366d5856a.tar.gz
CMake-c7213ca87064ba47984b4dd07192389366d5856a.tar.bz2
Features: Do not use a lower-than-default standard for requested features
`AddRequiredTargetC(xx)` feature didn't take the default compiler standard into account, which possibly resulted in the use of an older standard when some features requested it. Fixes: #18686
-rw-r--r--Source/cmMakefile.cxx14
-rw-r--r--Tests/CompileFeatures/CMakeLists.txt4
-rw-r--r--Tests/CompileFeatures/genex_test.cpp4
3 files changed, 18 insertions, 4 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index a0b09da..ab37774 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4725,6 +4725,13 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target,
needCxx17, needCxx20);
const char* existingCxxStandard = target->GetProperty("CXX_STANDARD");
+ if (existingCxxStandard == nullptr) {
+ const char* defaultCxxStandard =
+ this->GetDefinition("CMAKE_CXX_STANDARD_DEFAULT");
+ if (defaultCxxStandard && *defaultCxxStandard) {
+ existingCxxStandard = defaultCxxStandard;
+ }
+ }
const char* const* existingCxxLevel = nullptr;
if (existingCxxStandard) {
existingCxxLevel =
@@ -4827,6 +4834,13 @@ bool cmMakefile::AddRequiredTargetCFeature(cmTarget* target,
this->CheckNeededCLanguage(feature, needC90, needC99, needC11);
const char* existingCStandard = target->GetProperty("C_STANDARD");
+ if (existingCStandard == nullptr) {
+ const char* defaultCStandard =
+ this->GetDefinition("CMAKE_C_STANDARD_DEFAULT");
+ if (defaultCStandard && *defaultCStandard) {
+ existingCStandard = defaultCStandard;
+ }
+ }
if (existingCStandard) {
if (std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS),
cmStrCmp(existingCStandard)) == cm::cend(C_STANDARDS)) {
diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt
index b0bc656..6ccdcc3 100644
--- a/Tests/CompileFeatures/CMakeLists.txt
+++ b/Tests/CompileFeatures/CMakeLists.txt
@@ -338,11 +338,11 @@ else()
add_executable(CompileFeaturesGenex2 genex_test.cpp)
target_compile_features(CompileFeaturesGenex2 PRIVATE cxx_std_11)
- target_compile_definitions(CompileFeaturesGenex2 PRIVATE ${genex_test_defs})
+ target_compile_definitions(CompileFeaturesGenex2 PRIVATE ${genex_test_defs} ALLOW_LATER_STANDARDS=1)
add_library(std_11_iface INTERFACE)
target_compile_features(std_11_iface INTERFACE cxx_std_11)
add_executable(CompileFeaturesGenex3 genex_test.cpp)
target_link_libraries(CompileFeaturesGenex3 PRIVATE std_11_iface)
- target_compile_definitions(CompileFeaturesGenex3 PRIVATE ${genex_test_defs})
+ target_compile_definitions(CompileFeaturesGenex3 PRIVATE ${genex_test_defs} ALLOW_LATER_STANDARDS=1)
endif()
diff --git a/Tests/CompileFeatures/genex_test.cpp b/Tests/CompileFeatures/genex_test.cpp
index 59f9006..4539789 100644
--- a/Tests/CompileFeatures/genex_test.cpp
+++ b/Tests/CompileFeatures/genex_test.cpp
@@ -15,10 +15,10 @@
# if !HAVE_CXX_STD_11
# error HAVE_CXX_STD_11 is false with CXX_STANDARD == 11
# endif
-# if HAVE_CXX_STD_14
+# if HAVE_CXX_STD_14 && !defined(ALLOW_LATER_STANDARDS)
# error HAVE_CXX_STD_14 is true with CXX_STANDARD == 11
# endif
-# if HAVE_CXX_STD_17
+# if HAVE_CXX_STD_17 && !defined(ALLOW_LATER_STANDARDS)
# error HAVE_CXX_STD_17 is true with CXX_STANDARD == 11
# endif
#endif