Merge topic 'decay-language-version'
205215fb
cmTarget: Add CXX_STANDARD_REQUIRED to control decay.1df2116b
Features: Decay language flag if requested is not available.c4f4dac2
Project: Fix exit-on-error with compile feature tests.5bb7ce72
Project: Use nullary form of main for compile feature tests.64254e7a
Project: Remove extern from static string in feature tests.0d9c99bf
Help: Fix order of help entries.dc7639bd
Tests: Fix name of cache variable.
This commit is contained in:
commit
7b3def93b6
|
@ -108,8 +108,9 @@ 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/CXX_STANDARD_REQUIRED
|
||||
/prop_tgt/DEBUG_POSTFIX
|
||||
/prop_tgt/DEFINE_SYMBOL
|
||||
/prop_tgt/EchoString
|
||||
|
|
|
@ -258,8 +258,9 @@ 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_CXX_STANDARD_REQUIRED
|
||||
/variable/CMAKE_Fortran_MODDIR_DEFAULT
|
||||
/variable/CMAKE_Fortran_MODDIR_FLAG
|
||||
/variable/CMAKE_Fortran_MODOUT_FLAG
|
||||
|
|
|
@ -1,14 +1,27 @@
|
|||
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 "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
|
||||
is created.
|
||||
|
|
|
@ -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.
|
|
@ -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.
|
|
@ -24,17 +24,18 @@ 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})
|
||||
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)
|
||||
if (_result EQUAL 0)
|
||||
_get_gcc_features(c++98 CMAKE_CXX98_COMPILE_FEATURES)
|
||||
endif()
|
||||
else()
|
||||
set(_result 0)
|
||||
endif()
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
@ -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}"
|
||||
|
|
|
@ -2166,8 +2166,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;
|
||||
}
|
||||
|
@ -2175,12 +2175,66 @@ 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)
|
||||
if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED"))
|
||||
{
|
||||
std::string option_flag =
|
||||
"CMAKE_" + lang + standardProp
|
||||
+ "_" + type + "_COMPILE_OPTION";
|
||||
if (const char *opt = target->GetMakefile()->GetDefinition(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<std::string, std::vector<std::string> > langStdMap;
|
||||
if (langStdMap.empty())
|
||||
{
|
||||
// Maintain sorted order, most recent first.
|
||||
langStdMap["CXX"].push_back("11");
|
||||
langStdMap["CXX"].push_back("98");
|
||||
}
|
||||
|
||||
std::string standard(standardProp);
|
||||
|
||||
std::vector<std::string>& stds = langStdMap[lang];
|
||||
|
||||
std::vector<std::string>::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<std::string>::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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.
|
|
@ -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)
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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.
|
|
@ -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)
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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.
|
|
@ -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)
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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.
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
add_library(foo empty.cpp)
|
||||
set_property(TARGET foo PROPERTY CXX_STANDARD 11)
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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.
|
|
@ -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)
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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.
|
|
@ -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)
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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.
|
|
@ -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)
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -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.
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
add_library(foo empty.cpp)
|
||||
set_property(TARGET foo PROPERTY CXX_STANDARD 98)
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue