Merge topic 'features-from-default-standard'

c7213ca870 Features: Do not use a lower-than-default standard for requested features

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3023
This commit is contained in:
Brad King
2019-02-28 16:41:32 +00:00
committed by Kitware Robot
3 changed files with 18 additions and 4 deletions

View File

@@ -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)) {

View File

@@ -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()

View File

@@ -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