cmTarget: Deprecate COMPILE_DEFINITIONS_ properties with a policy.
This commit is contained in:
parent
855e8759fd
commit
5bb53f6b73
|
@ -92,3 +92,4 @@ All Policies
|
|||
/policy/CMP0040
|
||||
/policy/CMP0041
|
||||
/policy/CMP0042
|
||||
/policy/CMP0043
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
CMP0043
|
||||
-------
|
||||
|
||||
Ignore COMPILE_DEFINITIONS_<Config> properties
|
||||
|
||||
CMake 2.8.12 and lower allowed setting the
|
||||
:prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property and
|
||||
:prop_dir:`COMPILE_DEFINITIONS_<CONFIG>` directory property to apply
|
||||
configuration-specific compile definitions.
|
||||
|
||||
Since CMake 2.8.10, the :prop_tgt:`COMPILE_DEFINITIONS` property has supported
|
||||
:manual:`generator expressions <cmake-generator-expressions(7)>` for setting
|
||||
configuration-dependent content. The continued existence of the suffixed
|
||||
variables is redundant, and causes a maintenance burden. Population of the
|
||||
:prop_tgt:`COMPILE_DEFINITIONS_DEBUG <COMPILE_DEFINITIONS_<CONFIG>>` property
|
||||
may be replaced with a population of :prop_tgt:`COMPILE_DEFINITIONS` directly
|
||||
or via :command:`target_compile_definitions`:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
# Old Interface:
|
||||
set_property(TARGET tgt APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS_DEBUG DEBUG_MODE
|
||||
)
|
||||
|
||||
# New Interfaces:
|
||||
set_property(TARGET tgt APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUG_MODE>
|
||||
)
|
||||
target_compile_definitions(tgt PRIVATE $<$<CONFIG:Debug>:DEBUG_MODE>)
|
||||
|
||||
The OLD behavior for this policy is to consume the content of the suffixed
|
||||
:prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property when generating the
|
||||
compilation command. The NEW behavior for this policy is to ignore the content
|
||||
of the :prop_tgt:`COMPILE_DEFINITIONS_<CONFIG>` target property .
|
||||
|
||||
This policy was introduced in CMake version 3.0.0. CMake version
|
||||
|release| warns when the policy is not set and uses OLD behavior. Use
|
||||
the cmake_policy command to set it to OLD or NEW explicitly.
|
|
@ -1024,8 +1024,13 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
|
|||
/* else */ if (cmHasLiteralPrefix(propertyName.c_str(),
|
||||
"COMPILE_DEFINITIONS_"))
|
||||
{
|
||||
cmPolicies::PolicyStatus polSt =
|
||||
context->Makefile->GetPolicyStatus(cmPolicies::CMP0043);
|
||||
if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
|
||||
{
|
||||
interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
|
||||
}
|
||||
}
|
||||
#undef POPULATE_INTERFACE_PROPERTY_NAME
|
||||
|
||||
cmTarget const* headTarget = context->HeadTarget
|
||||
|
|
|
@ -1330,9 +1330,6 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
|
|||
const std::vector<cmValueWithOrigin> noconfig_compile_definitions =
|
||||
mf->GetCompileDefinitionsEntries();
|
||||
|
||||
std::vector<std::string> configs;
|
||||
mf->GetConfigurations(configs);
|
||||
|
||||
cmTargets& targets = mf->GetTargets();
|
||||
for(cmTargets::iterator ti = targets.begin();
|
||||
ti != targets.end(); ++ti)
|
||||
|
@ -1353,6 +1350,13 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
|
|||
t->InsertCompileDefinition(*it);
|
||||
}
|
||||
|
||||
cmPolicies::PolicyStatus polSt
|
||||
= mf->GetPolicyStatus(cmPolicies::CMP0043);
|
||||
if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
|
||||
{
|
||||
std::vector<std::string> configs;
|
||||
mf->GetConfigurations(configs);
|
||||
|
||||
for(std::vector<std::string>::const_iterator ci = configs.begin();
|
||||
ci != configs.end(); ++ci)
|
||||
{
|
||||
|
@ -1363,6 +1367,7 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -1601,6 +1601,8 @@ void cmMakefile::InitializeFromParent()
|
|||
}
|
||||
|
||||
// compile definitions property and per-config versions
|
||||
cmPolicies::PolicyStatus polSt = this->GetPolicyStatus(cmPolicies::CMP0043);
|
||||
if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
|
||||
{
|
||||
this->SetProperty("COMPILE_DEFINITIONS",
|
||||
parent->GetProperty("COMPILE_DEFINITIONS"));
|
||||
|
@ -1611,8 +1613,8 @@ void cmMakefile::InitializeFromParent()
|
|||
{
|
||||
std::string defPropName = "COMPILE_DEFINITIONS_";
|
||||
defPropName += cmSystemTools::UpperCase(*ci);
|
||||
this->SetProperty(defPropName.c_str(),
|
||||
parent->GetProperty(defPropName.c_str()));
|
||||
const char* prop = parent->GetProperty(defPropName.c_str());
|
||||
this->SetProperty(defPropName.c_str(), prop);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -316,6 +316,11 @@ cmPolicies::cmPolicies()
|
|||
CMP0042, "CMP0042",
|
||||
"MACOSX_RPATH is enabled by default.",
|
||||
3,0,0,0, cmPolicies::WARN);
|
||||
|
||||
this->DefinePolicy(
|
||||
CMP0043, "CMP0043",
|
||||
"Ignore COMPILE_DEFINITIONS_<Config> properties.",
|
||||
3,0,0,0, cmPolicies::WARN);
|
||||
}
|
||||
|
||||
cmPolicies::~cmPolicies()
|
||||
|
|
|
@ -96,6 +96,7 @@ public:
|
|||
/// add_custom_command() must exist.
|
||||
CMP0041, ///< Error on relative include with generator expression
|
||||
CMP0042, ///< Enable MACOSX_RPATH by default
|
||||
CMP0043, ///< Ignore COMPILE_DEFINITIONS_<Config> properties
|
||||
|
||||
/** \brief Always the last entry.
|
||||
*
|
||||
|
|
|
@ -2209,14 +2209,34 @@ void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
|
|||
std::string configPropName = "COMPILE_DEFINITIONS_"
|
||||
+ cmSystemTools::UpperCase(config);
|
||||
const char *configProp = this->GetProperty(configPropName.c_str());
|
||||
std::string defsString = (configProp ? configProp : "");
|
||||
|
||||
if (configProp)
|
||||
{
|
||||
switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
|
||||
{
|
||||
case cmPolicies::WARN:
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << this->Makefile->GetCMakeInstance()->GetPolicies()
|
||||
->GetPolicyWarning(cmPolicies::CMP0043);
|
||||
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
|
||||
e.str().c_str());
|
||||
}
|
||||
case cmPolicies::OLD:
|
||||
{
|
||||
cmGeneratorExpression ge(lfbt);
|
||||
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
|
||||
ge.Parse(defsString);
|
||||
ge.Parse(configProp);
|
||||
this->Internal
|
||||
->CachedLinkInterfaceCompileDefinitionsEntries[configString].push_back(
|
||||
new cmTargetInternals::TargetPropertyEntry(cge));
|
||||
->CachedLinkInterfaceCompileDefinitionsEntries[configString]
|
||||
.push_back(new cmTargetInternals::TargetPropertyEntry(cge));
|
||||
}
|
||||
break;
|
||||
case cmPolicies::NEW:
|
||||
case cmPolicies::REQUIRED_ALWAYS:
|
||||
case cmPolicies::REQUIRED_IF_USED:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
#error Unexpected LINK_LANGUAGE_IS_CXX
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MODE
|
||||
#error Unexpected DEBUG_MODE
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -35,6 +35,9 @@ set_property(TARGET target_prop_executable APPEND PROPERTY COMPILE_DEFINITIONS
|
|||
|
||||
add_executable(target_prop_c_executable ../compiletest.c)
|
||||
|
||||
cmake_policy(SET CMP0043 NEW)
|
||||
set_property(TARGET target_prop_c_executable APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG_MODE)
|
||||
|
||||
set_property(TARGET target_prop_c_executable APPEND PROPERTY COMPILE_DEFINITIONS
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:LINK_CXX_DEFINE>"
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:LINK_C_DEFINE>"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
0
|
|
@ -0,0 +1 @@
|
|||
^$
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
cmake_policy(SET CMP0043 NEW)
|
||||
|
||||
add_library(foo empty.cpp)
|
||||
set_property(TARGET foo
|
||||
PROPERTY COMPILE_DEFINITIONS_DEBUG "DEBUG_MODE"
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
0
|
|
@ -0,0 +1 @@
|
|||
^$
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
cmake_policy(SET CMP0043 OLD)
|
||||
|
||||
add_library(foo empty.cpp)
|
||||
set_property(TARGET foo
|
||||
PROPERTY COMPILE_DEFINITIONS_DEBUG "DEBUG_MODE"
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
0
|
|
@ -0,0 +1,5 @@
|
|||
CMake Warning \(dev\) in CMakeLists.txt:
|
||||
Policy CMP0043 is not set: Ignore COMPILE_DEFINITIONS_<Config> properties.
|
||||
Run "cmake --help-policy CMP0043" for policy details. Use the cmake_policy
|
||||
command to set the policy and suppress this warning.
|
||||
This warning is for project developers. Use -Wno-dev to suppress it.
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
add_library(foo empty.cpp)
|
||||
set_property(TARGET foo
|
||||
PROPERTY COMPILE_DEFINITIONS_DEBUG "DEBUG_MODE"
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
project(${RunCMake_TEST} CXX)
|
||||
include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)
|
|
@ -0,0 +1,7 @@
|
|||
include(RunCMake)
|
||||
|
||||
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
|
||||
|
||||
run_cmake(CMP0043-OLD)
|
||||
run_cmake(CMP0043-NEW)
|
||||
run_cmake(CMP0043-WARN)
|
|
@ -0,0 +1,7 @@
|
|||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int empty()
|
||||
{
|
||||
return 0;
|
||||
}
|
|
@ -64,6 +64,7 @@ add_RunCMake_test(CMP0041)
|
|||
if(CMAKE_SYSTEM_NAME MATCHES Darwin AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
|
||||
add_RunCMake_test(CMP0042)
|
||||
endif()
|
||||
add_RunCMake_test(CMP0043)
|
||||
add_RunCMake_test(CTest)
|
||||
if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles")
|
||||
add_RunCMake_test(CompilerChange)
|
||||
|
|
Loading…
Reference in New Issue