get_target_property: Error on non-existent target.
Introduce policy CMP0045 to control this behavior.
This commit is contained in:
parent
ab9f58f657
commit
73e93400e2
|
@ -94,3 +94,4 @@ All Policies
|
||||||
/policy/CMP0042
|
/policy/CMP0042
|
||||||
/policy/CMP0043
|
/policy/CMP0043
|
||||||
/policy/CMP0044
|
/policy/CMP0044
|
||||||
|
/policy/CMP0045
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
CMP0045
|
||||||
|
-------
|
||||||
|
|
||||||
|
Error on non-existent target in get_target_property.
|
||||||
|
|
||||||
|
In CMake 2.8.12 and lower, the :command:`get_target_property` command accepted
|
||||||
|
a non-existent target argument without issuing any error or warning. The
|
||||||
|
result variable is set to a ``-NOTFOUND`` value.
|
||||||
|
|
||||||
|
The OLD behavior for this policy is to issue no warning and set the result
|
||||||
|
variable to a ``-NOTFOUND`` value. The NEW behavior
|
||||||
|
for this policy is to issue a ``FATAL_ERROR`` if the command is called with a
|
||||||
|
non-existent target.
|
||||||
|
|
||||||
|
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.
|
|
@ -40,7 +40,36 @@ bool cmGetTargetPropertyCommand
|
||||||
cmTarget& target = *tgt;
|
cmTarget& target = *tgt;
|
||||||
prop = target.GetProperty(args[2].c_str());
|
prop = target.GetProperty(args[2].c_str());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool issueMessage = false;
|
||||||
|
cmOStringStream e;
|
||||||
|
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
||||||
|
switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0045))
|
||||||
|
{
|
||||||
|
case cmPolicies::WARN:
|
||||||
|
issueMessage = true;
|
||||||
|
e << this->Makefile->GetPolicies()
|
||||||
|
->GetPolicyWarning(cmPolicies::CMP0045) << "\n";
|
||||||
|
case cmPolicies::OLD:
|
||||||
|
break;
|
||||||
|
case cmPolicies::REQUIRED_IF_USED:
|
||||||
|
case cmPolicies::REQUIRED_ALWAYS:
|
||||||
|
case cmPolicies::NEW:
|
||||||
|
issueMessage = true;
|
||||||
|
messageType = cmake::FATAL_ERROR;
|
||||||
|
}
|
||||||
|
if (issueMessage)
|
||||||
|
{
|
||||||
|
e << "get_target_property() called with non-existent target \""
|
||||||
|
<< targetName << "\".";
|
||||||
|
this->Makefile->IssueMessage(messageType, e.str().c_str());
|
||||||
|
if (messageType == cmake::FATAL_ERROR)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (prop)
|
if (prop)
|
||||||
{
|
{
|
||||||
this->Makefile->AddDefinition(var.c_str(), prop);
|
this->Makefile->AddDefinition(var.c_str(), prop);
|
||||||
|
|
|
@ -326,6 +326,11 @@ cmPolicies::cmPolicies()
|
||||||
CMP0044, "CMP0044",
|
CMP0044, "CMP0044",
|
||||||
"Case sensitive <LANG>_COMPILER_ID generator expressions.",
|
"Case sensitive <LANG>_COMPILER_ID generator expressions.",
|
||||||
3,0,0,0, cmPolicies::WARN);
|
3,0,0,0, cmPolicies::WARN);
|
||||||
|
|
||||||
|
this->DefinePolicy(
|
||||||
|
CMP0045, "CMP0045",
|
||||||
|
"Error on non-existent target in get_target_property.",
|
||||||
|
3,0,0,0, cmPolicies::WARN);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmPolicies::~cmPolicies()
|
cmPolicies::~cmPolicies()
|
||||||
|
|
|
@ -98,6 +98,7 @@ public:
|
||||||
CMP0042, ///< Enable MACOSX_RPATH by default
|
CMP0042, ///< Enable MACOSX_RPATH by default
|
||||||
CMP0043, ///< Ignore COMPILE_DEFINITIONS_<Config> properties
|
CMP0043, ///< Ignore COMPILE_DEFINITIONS_<Config> properties
|
||||||
CMP0044, ///< Case sensitive <LANG>_COMPILER_ID generator expressions
|
CMP0044, ///< Case sensitive <LANG>_COMPILER_ID generator expressions
|
||||||
|
CMP0045, ///< Error on non-existent target in get_target_property
|
||||||
|
|
||||||
/** \brief Always the last entry.
|
/** \brief Always the last entry.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
1
|
|
@ -0,0 +1,4 @@
|
||||||
|
CMake Error at CMP0045-NEW.cmake:4 \(get_target_property\):
|
||||||
|
get_target_property\(\) called with non-existent target "tgt".
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
cmake_policy(SET CMP0045 NEW)
|
||||||
|
|
||||||
|
get_target_property(result tgt TYPE)
|
|
@ -0,0 +1 @@
|
||||||
|
0
|
|
@ -0,0 +1 @@
|
||||||
|
^$
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
cmake_policy(SET CMP0045 OLD)
|
||||||
|
|
||||||
|
get_target_property(result tgt TYPE)
|
|
@ -0,0 +1 @@
|
||||||
|
0
|
|
@ -0,0 +1,9 @@
|
||||||
|
CMake Warning \(dev\) at CMP0045-WARN.cmake:2 \(get_target_property\):
|
||||||
|
Policy CMP0045 is not set: Error on non-existent target in
|
||||||
|
get_target_property. Run "cmake --help-policy CMP0045" for policy details.
|
||||||
|
Use the cmake_policy command to set the policy and suppress this warning.
|
||||||
|
|
||||||
|
get_target_property\(\) called with non-existent target "tgt".
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
get_target_property(result tgt TYPE)
|
|
@ -0,0 +1,3 @@
|
||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
project(${RunCMake_TEST} CXX)
|
||||||
|
include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)
|
|
@ -0,0 +1,5 @@
|
||||||
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(CMP0045-OLD)
|
||||||
|
run_cmake(CMP0045-NEW)
|
||||||
|
run_cmake(CMP0045-WARN)
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifdef _WIN32
|
||||||
|
__declspec(dllexport)
|
||||||
|
#endif
|
||||||
|
int empty()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -65,6 +65,7 @@ if(CMAKE_SYSTEM_NAME MATCHES Darwin AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
|
||||||
add_RunCMake_test(CMP0042)
|
add_RunCMake_test(CMP0042)
|
||||||
endif()
|
endif()
|
||||||
add_RunCMake_test(CMP0043)
|
add_RunCMake_test(CMP0043)
|
||||||
|
add_RunCMake_test(CMP0045)
|
||||||
add_RunCMake_test(CTest)
|
add_RunCMake_test(CTest)
|
||||||
if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles")
|
if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles")
|
||||||
add_RunCMake_test(CompilerChange)
|
add_RunCMake_test(CompilerChange)
|
||||||
|
|
Loading…
Reference in New Issue