Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Brad King
CMake
Commits
5bb53f6b
Commit
5bb53f6b
authored
Dec 30, 2013
by
Stephen Kelly
Browse files
cmTarget: Deprecate COMPILE_DEFINITIONS_ properties with a policy.
parent
855e8759
Changes
23
Hide whitespace changes
Inline
Side-by-side
Help/manual/cmake-policies.7.rst
View file @
5bb53f6b
...
...
@@ -92,3 +92,4 @@ All Policies
/policy/CMP0040
/policy/CMP0041
/policy/CMP0042
/policy/CMP0043
Help/policy/CMP0043.rst
0 → 100644
View file @
5bb53f6b
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.
Source/cmGeneratorExpressionEvaluator.cxx
View file @
5bb53f6b
...
...
@@ -1024,7 +1024,12 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
/* else */
if
(
cmHasLiteralPrefix
(
propertyName
.
c_str
(),
"COMPILE_DEFINITIONS_"
))
{
interfacePropertyName
=
"INTERFACE_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
...
...
Source/cmGlobalGenerator.cxx
View file @
5bb53f6b
...
...
@@ -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,13 +1350,21 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
t
->
InsertCompileDefinition
(
*
it
);
}
for
(
std
::
vector
<
std
::
string
>::
const_iterator
ci
=
configs
.
begin
();
ci
!=
configs
.
end
();
++
ci
)
cmPolicies
::
PolicyStatus
polSt
=
mf
->
GetPolicyStatus
(
cmPolicies
::
CMP0043
);
if
(
polSt
==
cmPolicies
::
WARN
||
polSt
==
cmPolicies
::
OLD
)
{
std
::
string
defPropName
=
"COMPILE_DEFINITIONS_"
;
defPropName
+=
cmSystemTools
::
UpperCase
(
*
ci
);
t
->
AppendProperty
(
defPropName
.
c_str
(),
mf
->
GetProperty
(
defPropName
.
c_str
()));
std
::
vector
<
std
::
string
>
configs
;
mf
->
GetConfigurations
(
configs
);
for
(
std
::
vector
<
std
::
string
>::
const_iterator
ci
=
configs
.
begin
();
ci
!=
configs
.
end
();
++
ci
)
{
std
::
string
defPropName
=
"COMPILE_DEFINITIONS_"
;
defPropName
+=
cmSystemTools
::
UpperCase
(
*
ci
);
t
->
AppendProperty
(
defPropName
.
c_str
(),
mf
->
GetProperty
(
defPropName
.
c_str
()));
}
}
}
}
...
...
Source/cmMakefile.cxx
View file @
5bb53f6b
...
...
@@ -1601,20 +1601,22 @@ void cmMakefile::InitializeFromParent()
}
// compile definitions property and per-config versions
{
this
->
SetProperty
(
"COMPILE_DEFINITIONS"
,
parent
->
GetProperty
(
"COMPILE_DEFINITIONS"
));
std
::
vector
<
std
::
string
>
configs
;
this
->
GetConfigurations
(
configs
);
for
(
std
::
vector
<
std
::
string
>::
const_iterator
ci
=
configs
.
begin
();
ci
!=
configs
.
end
();
++
ci
)
{
std
::
string
defPropName
=
"COMPILE_DEFINITIONS_"
;
defPropName
+=
cmSystemTools
::
UpperCase
(
*
ci
);
this
->
SetProperty
(
defPropName
.
c_str
(),
parent
->
GetProperty
(
defPropName
.
c_str
()));
cmPolicies
::
PolicyStatus
polSt
=
this
->
GetPolicyStatus
(
cmPolicies
::
CMP0043
);
if
(
polSt
==
cmPolicies
::
WARN
||
polSt
==
cmPolicies
::
OLD
)
{
this
->
SetProperty
(
"COMPILE_DEFINITIONS"
,
parent
->
GetProperty
(
"COMPILE_DEFINITIONS"
));
std
::
vector
<
std
::
string
>
configs
;
this
->
GetConfigurations
(
configs
);
for
(
std
::
vector
<
std
::
string
>::
const_iterator
ci
=
configs
.
begin
();
ci
!=
configs
.
end
();
++
ci
)
{
std
::
string
defPropName
=
"COMPILE_DEFINITIONS_"
;
defPropName
+=
cmSystemTools
::
UpperCase
(
*
ci
);
const
char
*
prop
=
parent
->
GetProperty
(
defPropName
.
c_str
());
this
->
SetProperty
(
defPropName
.
c_str
(),
prop
);
}
}
}
// link libraries
this
->
LinkLibraries
=
parent
->
LinkLibraries
;
...
...
Source/cmPolicies.cxx
View file @
5bb53f6b
...
...
@@ -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
()
...
...
Source/cmPolicies.h
View file @
5bb53f6b
...
...
@@ -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.
*
...
...
Source/cmTarget.cxx
View file @
5bb53f6b
...
...
@@ -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
:
""
);
cmGeneratorExpression
ge
(
lfbt
);
cmsys
::
auto_ptr
<
cmCompiledGeneratorExpression
>
cge
=
ge
.
Parse
(
defsString
);
this
->
Internal
->
CachedLinkInterfaceCompileDefinitionsEntries
[
configString
].
push_back
(
new
cmTargetInternals
::
TargetPropertyEntry
(
cge
));
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
(
configProp
);
this
->
Internal
->
CachedLinkInterfaceCompileDefinitionsEntries
[
configString
]
.
push_back
(
new
cmTargetInternals
::
TargetPropertyEntry
(
cge
));
}
break
;
case
cmPolicies
::
NEW
:
case
cmPolicies
::
REQUIRED_ALWAYS
:
case
cmPolicies
::
REQUIRED_IF_USED
:
break
;
}
}
}
}
...
...
Tests/CompileDefinitions/compiletest.c
View file @
5bb53f6b
...
...
@@ -13,6 +13,10 @@
#error Unexpected LINK_LANGUAGE_IS_CXX
#endif
#ifdef DEBUG_MODE
#error Unexpected DEBUG_MODE
#endif
int
main
(
void
)
{
return
0
;
...
...
Tests/CompileDefinitions/target_prop/CMakeLists.txt
View file @
5bb53f6b
...
...
@@ -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>"
...
...
Tests/RunCMake/CMP0043/CMP0043-NEW-result.txt
0 → 100644
View file @
5bb53f6b
0
Tests/RunCMake/CMP0043/CMP0043-NEW-stderr.txt
0 → 100644
View file @
5bb53f6b
^$
Tests/RunCMake/CMP0043/CMP0043-NEW.cmake
0 → 100644
View file @
5bb53f6b
cmake_policy
(
SET CMP0043 NEW
)
add_library
(
foo empty.cpp
)
set_property
(
TARGET foo
PROPERTY COMPILE_DEFINITIONS_DEBUG
"DEBUG_MODE"
)
Tests/RunCMake/CMP0043/CMP0043-OLD-result.txt
0 → 100644
View file @
5bb53f6b
0
Tests/RunCMake/CMP0043/CMP0043-OLD-stderr.txt
0 → 100644
View file @
5bb53f6b
^$
Tests/RunCMake/CMP0043/CMP0043-OLD.cmake
0 → 100644
View file @
5bb53f6b
cmake_policy
(
SET CMP0043 OLD
)
add_library
(
foo empty.cpp
)
set_property
(
TARGET foo
PROPERTY COMPILE_DEFINITIONS_DEBUG
"DEBUG_MODE"
)
Tests/RunCMake/CMP0043/CMP0043-WARN-result.txt
0 → 100644
View file @
5bb53f6b
0
Tests/RunCMake/CMP0043/CMP0043-WARN-stderr.txt
0 → 100644
View file @
5bb53f6b
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.
Tests/RunCMake/CMP0043/CMP0043-WARN.cmake
0 → 100644
View file @
5bb53f6b
add_library
(
foo empty.cpp
)
set_property
(
TARGET foo
PROPERTY COMPILE_DEFINITIONS_DEBUG
"DEBUG_MODE"
)
Tests/RunCMake/CMP0043/CMakeLists.txt
0 → 100644
View file @
5bb53f6b
cmake_minimum_required
(
VERSION 2.8
)
project
(
${
RunCMake_TEST
}
CXX
)
include
(
${
RunCMake_TEST
}
.cmake NO_POLICY_SCOPE
)
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment