Commit 205215fb authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmTarget: Add CXX_STANDARD_REQUIRED to control decay.

parent 1df2116b
......@@ -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
......
......@@ -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
......
......@@ -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
......
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.
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.
......@@ -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<std::string, std::vector<std::string> > langStdMap;
if (langStdMap.empty())
{
......
......@@ -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
......
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.
add_library(foo empty.cpp)
set_property(TARGET foo PROPERTY CXX_STANDARD 11)
set_property(TARGET foo PROPERTY CXX_STANDARD_REQUIRED TRUE)
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.
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)
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.
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)
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.
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
add_library(foo empty.cpp)
set_property(TARGET foo PROPERTY CXX_STANDARD 11)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment