From dc7639bdabee1d2b8c82b64a65607e7dbe29cd5a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 6 May 2014 21:20:49 +0200 Subject: [PATCH 1/7] Tests: Fix name of cache variable. --- Tests/ExportImport/Import/Interface/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/ExportImport/Import/Interface/CMakeLists.txt b/Tests/ExportImport/Import/Interface/CMakeLists.txt index 1f30c6722..18d9b76d6 100644 --- a/Tests/ExportImport/Import/Interface/CMakeLists.txt +++ b/Tests/ExportImport/Import/Interface/CMakeLists.txt @@ -50,9 +50,9 @@ macro(do_try_compile prefix) auto value = 0; return value; } - " ${prefix}IMPORTED_IFACE_CONSTEXPR) + " ${prefix}IMPORTED_IFACE_AUTO_TYPE) - if(NOT ${prefix}IMPORTED_IFACE_CONSTEXPR) + if(NOT ${prefix}IMPORTED_IFACE_AUTO_TYPE) message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}") endif() endif() From 0d9c99bf04513bd2fd69e3673f9469c4cd69dc4c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 6 May 2014 21:21:46 +0200 Subject: [PATCH 2/7] Help: Fix order of help entries. --- Help/manual/cmake-properties.7.rst | 2 +- Help/manual/cmake-variables.7.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index da21e2973..01fe42d80 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -108,8 +108,8 @@ Properties on Targets /prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG /prop_tgt/CONFIG_OUTPUT_NAME /prop_tgt/CONFIG_POSTFIX - /prop_tgt/CXX_STANDARD /prop_tgt/CXX_EXTENSIONS + /prop_tgt/CXX_STANDARD /prop_tgt/DEBUG_POSTFIX /prop_tgt/DEFINE_SYMBOL /prop_tgt/EchoString diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 82242f52c..e2958a170 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -258,8 +258,8 @@ Variables for Languages /variable/CMAKE_COMPILER_IS_GNULANG /variable/CMAKE_CXX_COMPILE_FEATURES - /variable/CMAKE_CXX_STANDARD /variable/CMAKE_CXX_EXTENSIONS + /variable/CMAKE_CXX_STANDARD /variable/CMAKE_Fortran_MODDIR_DEFAULT /variable/CMAKE_Fortran_MODDIR_FLAG /variable/CMAKE_Fortran_MODOUT_FLAG From 64254e7a74455d194092c9dba64e8d5c910a8f21 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 6 May 2014 21:23:36 +0200 Subject: [PATCH 3/7] Project: Remove extern from static string in feature tests. --- Modules/Internal/FeatureTesting.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake index 0fff36b31..f4adb35fa 100644 --- a/Modules/Internal/FeatureTesting.cmake +++ b/Modules/Internal/FeatureTesting.cmake @@ -5,7 +5,7 @@ macro(record_compiler_features lang compile_flags feature_list) string(TOLOWER ${lang} lang_lc) file(REMOVE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.bin") file(WRITE "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" " - extern const char features[] = {\"\"\n") + const char features[] = {\"\"\n") get_property(known_features GLOBAL PROPERTY CMAKE_${lang}_KNOWN_FEATURES) From 5bb7ce724c8b93d390adb17ec0eb7970520ed114 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 6 May 2014 21:24:02 +0200 Subject: [PATCH 4/7] Project: Use nullary form of main for compile feature tests. --- Modules/Internal/FeatureTesting.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake index f4adb35fa..7bf6d9121 100644 --- a/Modules/Internal/FeatureTesting.cmake +++ b/Modules/Internal/FeatureTesting.cmake @@ -20,7 +20,7 @@ macro(record_compiler_features lang compile_flags feature_list) endif() endforeach() file(APPEND "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" - "\n};\n\nint main(int, char **) { return 0; }\n") + "\n};\n\nint main() { return 0; }\n") try_compile(CMAKE_${lang}_FEATURE_TEST ${CMAKE_BINARY_DIR} "${CMAKE_BINARY_DIR}/CMakeFiles/feature_tests.${lang_lc}" From c4f4dac2d550f0a8a44530187eac2ad03191c981 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 6 May 2014 21:31:30 +0200 Subject: [PATCH 5/7] Project: Fix exit-on-error with compile feature tests. --- Modules/Compiler/GNU-CXX.cmake | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake index 6ec3958fc..74645258a 100644 --- a/Modules/Compiler/GNU-CXX.cmake +++ b/Modules/Compiler/GNU-CXX.cmake @@ -27,14 +27,13 @@ endif() macro(cmake_record_cxx_compile_features) macro(_get_gcc_features std_version list) record_compiler_features(CXX "-std=${std_version}" ${list}) - if (NOT _result EQUAL 0) - return() - endif() endmacro() if (UNIX AND NOT APPLE AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) _get_gcc_features(c++11 CMAKE_CXX11_COMPILE_FEATURES) - _get_gcc_features(c++98 CMAKE_CXX98_COMPILE_FEATURES) + if (_result EQUAL 0) + _get_gcc_features(c++98 CMAKE_CXX98_COMPILE_FEATURES) + endif() else() set(_result 0) endif() From 1df2116bfaa4c575404ae1eef225aed1530d668a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 28 Mar 2014 16:09:35 +0100 Subject: [PATCH 6/7] Features: Decay language flag if requested is not available. Use the highest standard compile flags available if requested language version is too new. This supports use-cases like set(CMAKE_CXX_STANDARD 14) # Compiled with -std=c++11 with GNU 4.7, which has no -std=c++14 # or equivalent flag add_executable(main main.cpp) This can be used in combination with preprocessor defines which communicate the availability of certain language features for optional use. --- Help/prop_tgt/CXX_STANDARD.rst | 16 ++++++++++-- Modules/Compiler/GNU-CXX.cmake | 2 ++ Source/cmLocalGenerator.cxx | 48 +++++++++++++++++++++++++++++----- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/Help/prop_tgt/CXX_STANDARD.rst b/Help/prop_tgt/CXX_STANDARD.rst index e1b6e7873..fb72f3e19 100644 --- a/Help/prop_tgt/CXX_STANDARD.rst +++ b/Help/prop_tgt/CXX_STANDARD.rst @@ -1,14 +1,26 @@ CXX_STANDARD ------------ -The C++ standard whose features are required to build this target. +The C++ standard whose features are requested to build this target. -This property specifies the C++ standard whose features are required +This property specifies the C++ standard whose features are requested to build this target. For some compilers, this results in adding a flag such as ``-std=c++11`` to the compile line. Supported values are ``98`` and ``11``. +If the value requested does not result in a compile flag being added for +the compiler in use, a previous standard flag will be added instead. This +means that using: + +.. code-block:: cmake + + set_property(TARGET tgt PROPERTY CXX_STANDARD 11) + +with a compiler which does not support ``-std=c++11`` or an equivalent +flag will not result in an error or warning, but will instead add the +``-std=c++98`` flag if supported. + This property is initialized by the value of the :variable:`CMAKE_CXX_STANDARD` variable if it is set when a target is created. diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake index 74645258a..d3249850e 100644 --- a/Modules/Compiler/GNU-CXX.cmake +++ b/Modules/Compiler/GNU-CXX.cmake @@ -24,6 +24,8 @@ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3) set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x") endif() +set(CMAKE_CXX_STANDARD_DEFAULT 98) + macro(cmake_record_cxx_compile_features) macro(_get_gcc_features std_version list) record_compiler_features(CXX "-std=${std_version}" ${list}) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f375b5f3c..a29a0cd8b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2152,8 +2152,8 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget* target, return; } std::string stdProp = lang + "_STANDARD"; - const char *standard = target->GetProperty(stdProp); - if (!standard) + const char *standardProp = target->GetProperty(stdProp); + if (!standardProp) { return; } @@ -2161,12 +2161,46 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget* target, bool ext = target->GetPropertyAsBool(extProp); std::string type = ext ? "EXTENSION" : "STANDARD"; - std::string compile_option = - "CMAKE_" + lang + std::string(standard) - + "_" + type + "_COMPILE_OPTION"; - if (const char *opt = target->GetMakefile()->GetDefinition(compile_option)) + static std::map > langStdMap; + if (langStdMap.empty()) { - this->AppendFlags(flags, opt); + // Maintain sorted order, most recent first. + langStdMap["CXX"].push_back("11"); + langStdMap["CXX"].push_back("98"); + } + + std::string standard(standardProp); + + std::vector& stds = langStdMap[lang]; + + std::vector::const_iterator stdIt = + std::find(stds.begin(), stds.end(), standard); + assert(stdIt != stds.end()); + + const char* defaultStd + = this->Makefile->GetDefinition("CMAKE_" + lang + "_STANDARD_DEFAULT"); + std::vector::const_iterator defaultStdIt; + if (defaultStd) + { + defaultStdIt = std::find(stds.begin(), stds.end(), defaultStd); + assert(defaultStdIt != stds.end()); + } + else + { + defaultStdIt = stds.end() - 1; + } + + for ( ; stdIt <= defaultStdIt; ++stdIt) + { + std::string option_flag = + "CMAKE_" + lang + *stdIt + + "_" + type + "_COMPILE_OPTION"; + + if (const char *opt = target->GetMakefile()->GetDefinition(option_flag)) + { + this->AppendFlags(flags, opt); + return; + } } } From 205215fb8a8aa950026d914377a54ae358a1c02a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 30 Apr 2014 18:07:38 +0200 Subject: [PATCH 7/7] cmTarget: Add CXX_STANDARD_REQUIRED to control decay. --- Help/manual/cmake-properties.7.rst | 1 + Help/manual/cmake-variables.7.rst | 1 + Help/prop_tgt/CXX_STANDARD.rst | 3 ++- Help/prop_tgt/CXX_STANDARD_REQUIRED.rst | 14 +++++++++++++ Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst | 8 ++++++++ Source/cmLocalGenerator.cxx | 20 +++++++++++++++++++ Source/cmTarget.cxx | 1 + Tests/CompileFeatures/CMakeLists.txt | 3 +++ .../CompileFeatures/RequireCXX11-result.txt | 1 + .../CompileFeatures/RequireCXX11-stderr.txt | 3 +++ .../CompileFeatures/RequireCXX11.cmake | 4 ++++ .../RequireCXX11Ext-result.txt | 1 + .../RequireCXX11Ext-stderr.txt | 3 +++ .../CompileFeatures/RequireCXX11Ext.cmake | 5 +++++ .../RequireCXX11ExtVariable-result.txt | 1 + .../RequireCXX11ExtVariable-stderr.txt | 3 +++ .../RequireCXX11ExtVariable.cmake | 5 +++++ .../RequireCXX11Variable-result.txt | 1 + .../RequireCXX11Variable-stderr.txt | 3 +++ .../RequireCXX11Variable.cmake | 4 ++++ .../CompileFeatures/RequireCXX98-result.txt | 1 + .../CompileFeatures/RequireCXX98-stderr.txt | 3 +++ .../CompileFeatures/RequireCXX98.cmake | 4 ++++ .../RequireCXX98Ext-result.txt | 1 + .../RequireCXX98Ext-stderr.txt | 3 +++ .../CompileFeatures/RequireCXX98Ext.cmake | 5 +++++ .../RequireCXX98ExtVariable-result.txt | 1 + .../RequireCXX98ExtVariable-stderr.txt | 3 +++ .../RequireCXX98ExtVariable.cmake | 5 +++++ .../RequireCXX98Variable-result.txt | 1 + .../RequireCXX98Variable-stderr.txt | 3 +++ .../RequireCXX98Variable.cmake | 4 ++++ .../CompileFeatures/RunCMakeTest.cmake | 15 ++++++++++++++ .../generate_feature_list.cmake | 19 ++++++++++++++++++ 34 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 Help/prop_tgt/CXX_STANDARD_REQUIRED.rst create mode 100644 Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11-result.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11-stderr.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11.cmake create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11Ext-result.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11Ext-stderr.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11Ext.cmake create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-result.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-stderr.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable.cmake create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11Variable-result.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11Variable-stderr.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX11Variable.cmake create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98-result.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98-stderr.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98.cmake create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98Ext-result.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98Ext-stderr.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98Ext.cmake create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-result.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-stderr.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable.cmake create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98Variable-result.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98Variable-stderr.txt create mode 100644 Tests/RunCMake/CompileFeatures/RequireCXX98Variable.cmake diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 01fe42d80..14d2e7fa3 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -110,6 +110,7 @@ Properties on Targets /prop_tgt/CONFIG_POSTFIX /prop_tgt/CXX_EXTENSIONS /prop_tgt/CXX_STANDARD + /prop_tgt/CXX_STANDARD_REQUIRED /prop_tgt/DEBUG_POSTFIX /prop_tgt/DEFINE_SYMBOL /prop_tgt/EchoString diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index e2958a170..7313cd1a0 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -260,6 +260,7 @@ Variables for Languages /variable/CMAKE_CXX_COMPILE_FEATURES /variable/CMAKE_CXX_EXTENSIONS /variable/CMAKE_CXX_STANDARD + /variable/CMAKE_CXX_STANDARD_REQUIRED /variable/CMAKE_Fortran_MODDIR_DEFAULT /variable/CMAKE_Fortran_MODDIR_FLAG /variable/CMAKE_Fortran_MODOUT_FLAG diff --git a/Help/prop_tgt/CXX_STANDARD.rst b/Help/prop_tgt/CXX_STANDARD.rst index fb72f3e19..fdd5aac0f 100644 --- a/Help/prop_tgt/CXX_STANDARD.rst +++ b/Help/prop_tgt/CXX_STANDARD.rst @@ -19,7 +19,8 @@ means that using: with a compiler which does not support ``-std=c++11`` or an equivalent flag will not result in an error or warning, but will instead add the -``-std=c++98`` flag if supported. +``-std=c++98`` flag if supported. This "decay" behavior may be controlled +with the :prop_tgt:`CXX_STANDARD_REQUIRED` target property. This property is initialized by the value of the :variable:`CMAKE_CXX_STANDARD` variable if it is set when a target diff --git a/Help/prop_tgt/CXX_STANDARD_REQUIRED.rst b/Help/prop_tgt/CXX_STANDARD_REQUIRED.rst new file mode 100644 index 000000000..f0828051f --- /dev/null +++ b/Help/prop_tgt/CXX_STANDARD_REQUIRED.rst @@ -0,0 +1,14 @@ +CXX_STANDARD_REQUIRED +--------------------- + +Boolean describing whether the value of :prop_tgt:`CXX_STANDARD` is a requirement. + +If this property is set to ``ON``, then the value of the +:prop_tgt:`CXX_STANDARD` target property is treated as a requirement. If this +property is ``OFF`` or unset, the :prop_tgt:`CXX_STANDARD` target property is +treated as optional and may "decay" to a previous standard if the requested is +not available. + +This property is initialized by the value of +the :variable:`CMAKE_CXX_STANDARD_REQUIRED` variable if it is set when a +target is created. diff --git a/Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst b/Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst new file mode 100644 index 000000000..ff005dafb --- /dev/null +++ b/Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst @@ -0,0 +1,8 @@ +CMAKE_CXX_STANDARD_REQUIRED +--------------------------- + +Default value for ``CXX_STANDARD_REQUIRED`` property of targets. + +This variable is used to initialize the :prop_tgt:`CXX_STANDARD_REQUIRED` +property on all targets. See that target property for additional +information. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index a29a0cd8b..afb2ce8bd 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2161,6 +2161,26 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget* target, bool ext = target->GetPropertyAsBool(extProp); std::string type = ext ? "EXTENSION" : "STANDARD"; + if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED")) + { + std::string option_flag = + "CMAKE_" + lang + standardProp + + "_" + type + "_COMPILE_OPTION"; + + const char *opt = target->GetMakefile()->GetDefinition(option_flag); + if (!opt) + { + cmOStringStream e; + e << "Target \"" << target->GetName() << "\" requires the language " + "dialect \"" << lang << standardProp << "\" " + << (ext ? "(with compiler extensions)" : "") << ", but CMake " + "does not know the compile flags to use to enable it."; + this->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str()); + } + this->AppendFlags(flags, opt); + return; + } + static std::map > langStdMap; if (langStdMap.empty()) { diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ee6cb44a2..3436bb485 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -315,6 +315,7 @@ void cmTarget::SetMakefile(cmMakefile* mf) this->SetPropertyDefault("MACOSX_RPATH", 0); this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0); this->SetPropertyDefault("CXX_STANDARD", 0); + this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0); this->SetPropertyDefault("CXX_EXTENSIONS", 0); } diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 501138df3..a991e778a 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -31,6 +31,9 @@ add_executable(CompileFeatures main.cpp) set_property(TARGET CompileFeatures PROPERTY COMPILE_FEATURES "cxx_auto_type" ) +set_property(TARGET CompileFeatures + PROPERTY CXX_STANDARD_REQUIRED TRUE +) add_executable(GenexCompileFeatures main.cpp) set_property(TARGET GenexCompileFeatures diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11-stderr.txt new file mode 100644 index 000000000..0fc9112f8 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11-stderr.txt @@ -0,0 +1,3 @@ +CMake Error in CMakeLists.txt: + Target "foo" requires the language dialect "CXX11" , but CMake does not + know the compile flags to use to enable it. diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX11.cmake new file mode 100644 index 000000000..10b251aa4 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11.cmake @@ -0,0 +1,4 @@ + +add_library(foo empty.cpp) +set_property(TARGET foo PROPERTY CXX_STANDARD 11) +set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED TRUE) diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-stderr.txt new file mode 100644 index 000000000..5c68a1cf7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext-stderr.txt @@ -0,0 +1,3 @@ +CMake Error in CMakeLists.txt: + Target "foo" requires the language dialect "CXX11" \(with compiler + extensions\), but CMake does not know the compile flags to use to enable it. diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Ext.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext.cmake new file mode 100644 index 000000000..9e726c835 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Ext.cmake @@ -0,0 +1,5 @@ + +add_library(foo empty.cpp) +set_property(TARGET foo PROPERTY CXX_STANDARD 11) +set_property(TARGET foo PROPERTY CXX_EXTENSIONS TRUE) +set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED TRUE) diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-stderr.txt new file mode 100644 index 000000000..5c68a1cf7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable-stderr.txt @@ -0,0 +1,3 @@ +CMake Error in CMakeLists.txt: + Target "foo" requires the language dialect "CXX11" \(with compiler + extensions\), but CMake does not know the compile flags to use to enable it. diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable.cmake new file mode 100644 index 000000000..8f6755fc6 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11ExtVariable.cmake @@ -0,0 +1,5 @@ + +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +add_library(foo empty.cpp) +set_property(TARGET foo PROPERTY CXX_STANDARD 11) +set_property(TARGET foo PROPERTY CXX_EXTENSIONS TRUE) diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-stderr.txt new file mode 100644 index 000000000..0fc9112f8 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable-stderr.txt @@ -0,0 +1,3 @@ +CMake Error in CMakeLists.txt: + Target "foo" requires the language dialect "CXX11" , but CMake does not + know the compile flags to use to enable it. diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX11Variable.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable.cmake new file mode 100644 index 000000000..29703db68 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX11Variable.cmake @@ -0,0 +1,4 @@ + +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +add_library(foo empty.cpp) +set_property(TARGET foo PROPERTY CXX_STANDARD 11) diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98-stderr.txt new file mode 100644 index 000000000..47c86889f --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98-stderr.txt @@ -0,0 +1,3 @@ +CMake Error in CMakeLists.txt: + Target "foo" requires the language dialect "CXX98" , but CMake does not + know the compile flags to use to enable it. diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX98.cmake new file mode 100644 index 000000000..4ea595edb --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98.cmake @@ -0,0 +1,4 @@ + +add_library(foo empty.cpp) +set_property(TARGET foo PROPERTY CXX_STANDARD 98) +set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED TRUE) diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-stderr.txt new file mode 100644 index 000000000..b4fdf8a45 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext-stderr.txt @@ -0,0 +1,3 @@ +CMake Error in CMakeLists.txt: + Target "foo" requires the language dialect "CXX98" \(with compiler + extensions\), but CMake does not know the compile flags to use to enable it. diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Ext.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext.cmake new file mode 100644 index 000000000..fdf4cc777 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Ext.cmake @@ -0,0 +1,5 @@ + +add_library(foo empty.cpp) +set_property(TARGET foo PROPERTY CXX_STANDARD 98) +set_property(TARGET foo PROPERTY CXX_EXTENSIONS TRUE) +set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED TRUE) diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-stderr.txt new file mode 100644 index 000000000..b4fdf8a45 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable-stderr.txt @@ -0,0 +1,3 @@ +CMake Error in CMakeLists.txt: + Target "foo" requires the language dialect "CXX98" \(with compiler + extensions\), but CMake does not know the compile flags to use to enable it. diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable.cmake new file mode 100644 index 000000000..a26a22d42 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98ExtVariable.cmake @@ -0,0 +1,5 @@ + +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +add_library(foo empty.cpp) +set_property(TARGET foo PROPERTY CXX_STANDARD 98) +set_property(TARGET foo PROPERTY CXX_EXTENSIONS TRUE) diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-result.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-stderr.txt b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-stderr.txt new file mode 100644 index 000000000..47c86889f --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable-stderr.txt @@ -0,0 +1,3 @@ +CMake Error in CMakeLists.txt: + Target "foo" requires the language dialect "CXX98" , but CMake does not + know the compile flags to use to enable it. diff --git a/Tests/RunCMake/CompileFeatures/RequireCXX98Variable.cmake b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable.cmake new file mode 100644 index 000000000..0e3ef8dfb --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/RequireCXX98Variable.cmake @@ -0,0 +1,4 @@ + +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +add_library(foo empty.cpp) +set_property(TARGET foo PROPERTY CXX_STANDARD 98) diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index 43d4cb3ea..f083751c2 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -18,3 +18,18 @@ if (NOT FEATURES) run_cmake(NoSupportedCxxFeatures) run_cmake(NoSupportedCxxFeaturesGenex) endif() + +foreach(standard 98 11) + file(READ + "${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx${standard}_flag.txt" + CXX${standard}_FLAG + ) + if (CXX${standard}_FLAG STREQUAL NOTFOUND) + run_cmake(RequireCXX${standard}) + run_cmake(RequireCXX${standard}Variable) + endif() + if (CXX${standard}EXT_FLAG STREQUAL NOTFOUND) + run_cmake(RequireCXX${standard}Ext) + run_cmake(RequireCXX${standard}ExtVariable) + endif() +endforeach() diff --git a/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake b/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake index 2bbbd17ff..06c4f739b 100644 --- a/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake +++ b/Tests/RunCMake/CompileFeatures/generate_feature_list.cmake @@ -2,3 +2,22 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/features.txt" "${CMAKE_CXX_COMPILE_FEATURES}" ) + +foreach(standard 98 11) + set(CXX${standard}_FLAG NOTFOUND) + if (DEFINED CMAKE_CXX${standard}_STANDARD_COMPILE_OPTION) + set(CXX${standard}_FLAG ${CMAKE_CXX${standard}_STANDARD_COMPILE_OPTION}) + endif() + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx${standard}_flag.txt" + "${CXX${standard}_FLAG}" + ) + set(CXX${standard}EXT_FLAG NOTFOUND) + if (DEFINED CMAKE_CXX${standard}_EXTENSION_COMPILE_OPTION) + set(CXX${standard}EXT_FLAG ${CMAKE_CXX${standard}_EXTENSION_COMPILE_OPTION}) + endif() + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx${standard}ext_flag.txt" + "${CXX${standard}EXT_FLAG}" + ) +endforeach()