Merge topic 'if-test'
14e49ed1
if: Add "TEST <test>" condition623dcc85
ExternalProject: Avoid if() auto-dereference of a "TEST" variable
This commit is contained in:
commit
7ac2b1256b
|
@ -71,6 +71,10 @@ Possible expressions are:
|
||||||
created by the :command:`add_executable`, :command:`add_library`, or
|
created by the :command:`add_executable`, :command:`add_library`, or
|
||||||
:command:`add_custom_target` commands.
|
:command:`add_custom_target` commands.
|
||||||
|
|
||||||
|
``if(TEST test-name)``
|
||||||
|
True if the given name is an existing test name created by the
|
||||||
|
:command:`add_test` command.
|
||||||
|
|
||||||
``if(EXISTS path-to-file-or-directory)``
|
``if(EXISTS path-to-file-or-directory)``
|
||||||
True if the named file or directory exists. Behavior is well-defined
|
True if the named file or directory exists. Behavior is well-defined
|
||||||
only for full paths.
|
only for full paths.
|
||||||
|
|
|
@ -121,3 +121,4 @@ All Policies
|
||||||
/policy/CMP0061
|
/policy/CMP0061
|
||||||
/policy/CMP0062
|
/policy/CMP0062
|
||||||
/policy/CMP0063
|
/policy/CMP0063
|
||||||
|
/policy/CMP0064
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
CMP0064
|
||||||
|
-------
|
||||||
|
|
||||||
|
Recognize ``TEST`` as a operator for the :command:`if` command.
|
||||||
|
|
||||||
|
The ``TEST`` operator was added to the :command:`if` command to determine if a
|
||||||
|
given test name was created by the :command:`add_test` command.
|
||||||
|
|
||||||
|
The ``OLD`` behavior for this policy is to ignore the ``TEST`` operator.
|
||||||
|
The ``NEW`` behavior is to interpret the ``TEST`` operator.
|
||||||
|
|
||||||
|
This policy was introduced in CMake version 3.4. CMake version
|
||||||
|
|release| warns when the policy is not set and uses ``OLD`` behavior. Use
|
||||||
|
the :command:`cmake_policy()` command to set it to ``OLD`` or ``NEW``
|
||||||
|
explicitly.
|
||||||
|
|
||||||
|
.. include:: DEPRECATED.txt
|
|
@ -0,0 +1,5 @@
|
||||||
|
if-TEST
|
||||||
|
-------
|
||||||
|
|
||||||
|
* Add a new TEST operator to if() that evaluates to true
|
||||||
|
if a given test name has been defined.
|
|
@ -1211,7 +1211,7 @@ function(_ep_get_build_command name step cmd_var)
|
||||||
if(step STREQUAL "INSTALL")
|
if(step STREQUAL "INSTALL")
|
||||||
set(args install)
|
set(args install)
|
||||||
endif()
|
endif()
|
||||||
if(step STREQUAL "TEST")
|
if("x${step}x" STREQUAL "xTESTx")
|
||||||
set(args test)
|
set(args test)
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
|
@ -1230,7 +1230,7 @@ function(_ep_get_build_command name step cmd_var)
|
||||||
list(APPEND args --target install)
|
list(APPEND args --target install)
|
||||||
endif()
|
endif()
|
||||||
# But for "TEST" drive the project with corresponding "ctest".
|
# But for "TEST" drive the project with corresponding "ctest".
|
||||||
if(step STREQUAL "TEST")
|
if("x${step}x" STREQUAL "xTESTx")
|
||||||
string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
|
string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
|
||||||
set(args "")
|
set(args "")
|
||||||
endif()
|
endif()
|
||||||
|
@ -1246,7 +1246,7 @@ function(_ep_get_build_command name step cmd_var)
|
||||||
if(step STREQUAL "INSTALL")
|
if(step STREQUAL "INSTALL")
|
||||||
set(args install)
|
set(args install)
|
||||||
endif()
|
endif()
|
||||||
if(step STREQUAL "TEST")
|
if("x${step}x" STREQUAL "xTESTx")
|
||||||
set(args test)
|
set(args test)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -16,7 +16,8 @@ cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile):
|
||||||
Makefile(makefile),
|
Makefile(makefile),
|
||||||
Policy12Status(makefile.GetPolicyStatus(cmPolicies::CMP0012)),
|
Policy12Status(makefile.GetPolicyStatus(cmPolicies::CMP0012)),
|
||||||
Policy54Status(makefile.GetPolicyStatus(cmPolicies::CMP0054)),
|
Policy54Status(makefile.GetPolicyStatus(cmPolicies::CMP0054)),
|
||||||
Policy57Status(makefile.GetPolicyStatus(cmPolicies::CMP0057))
|
Policy57Status(makefile.GetPolicyStatus(cmPolicies::CMP0057)),
|
||||||
|
Policy64Status(makefile.GetPolicyStatus(cmPolicies::CMP0064))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -493,6 +494,29 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList &newArgs,
|
||||||
this->Makefile.FindTargetToUse(argP1->GetValue())?true:false,
|
this->Makefile.FindTargetToUse(argP1->GetValue())?true:false,
|
||||||
reducible, arg, newArgs, argP1, argP2);
|
reducible, arg, newArgs, argP1, argP2);
|
||||||
}
|
}
|
||||||
|
// does a test exist
|
||||||
|
if(this->Policy64Status != cmPolicies::OLD &&
|
||||||
|
this->Policy64Status != cmPolicies::WARN)
|
||||||
|
{
|
||||||
|
if (this->IsKeyword("TEST", *arg) && argP1 != newArgs.end())
|
||||||
|
{
|
||||||
|
const cmTest* haveTest = this->Makefile.GetTest(argP1->c_str());
|
||||||
|
this->HandlePredicate(
|
||||||
|
haveTest?true:false,
|
||||||
|
reducible, arg, newArgs, argP1, argP2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(this->Policy64Status == cmPolicies::WARN &&
|
||||||
|
this->IsKeyword("TEST", *arg))
|
||||||
|
{
|
||||||
|
std::ostringstream e;
|
||||||
|
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0064) << "\n";
|
||||||
|
e << "TEST will be interpreted as an operator "
|
||||||
|
"when the policy is set to NEW. "
|
||||||
|
"Since the policy is not set the OLD behavior will be used.";
|
||||||
|
|
||||||
|
this->Makefile.IssueMessage(cmake::AUTHOR_WARNING, e.str());
|
||||||
|
}
|
||||||
// is a variable defined
|
// is a variable defined
|
||||||
if (this->IsKeyword("DEFINED", *arg) && argP1 != newArgs.end())
|
if (this->IsKeyword("DEFINED", *arg) && argP1 != newArgs.end())
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,6 +94,7 @@ private:
|
||||||
cmPolicies::PolicyStatus Policy12Status;
|
cmPolicies::PolicyStatus Policy12Status;
|
||||||
cmPolicies::PolicyStatus Policy54Status;
|
cmPolicies::PolicyStatus Policy54Status;
|
||||||
cmPolicies::PolicyStatus Policy57Status;
|
cmPolicies::PolicyStatus Policy57Status;
|
||||||
|
cmPolicies::PolicyStatus Policy64Status;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -217,6 +217,9 @@ class cmPolicy;
|
||||||
3, 3, 0, cmPolicies::WARN) \
|
3, 3, 0, cmPolicies::WARN) \
|
||||||
SELECT(POLICY, CMP0063, \
|
SELECT(POLICY, CMP0063, \
|
||||||
"Honor visibility properties for all target types.", \
|
"Honor visibility properties for all target types.", \
|
||||||
|
3, 3, 0, cmPolicies::WARN) \
|
||||||
|
SELECT(POLICY, CMP0064, \
|
||||||
|
"Support new TEST if() operator.", \
|
||||||
3, 3, 0, cmPolicies::WARN)
|
3, 3, 0, cmPolicies::WARN)
|
||||||
|
|
||||||
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
|
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
cmake_policy(SET CMP0064 NEW)
|
||||||
|
|
||||||
|
if(NOT TEST TestThatDoesNotExist)
|
||||||
|
message(STATUS "if NOT TestThatDoesNotExist is true")
|
||||||
|
endif()
|
|
@ -0,0 +1,7 @@
|
||||||
|
cmake_policy(SET CMP0064 OLD)
|
||||||
|
|
||||||
|
if(TEST)
|
||||||
|
message(FATAL_ERROR "TEST was not recognized to be undefined")
|
||||||
|
else()
|
||||||
|
message(STATUS "TEST was treated as a variable")
|
||||||
|
endif()
|
|
@ -0,0 +1,7 @@
|
||||||
|
cmake_policy(SET CMP0064 OLD)
|
||||||
|
|
||||||
|
if(TEST)
|
||||||
|
message(FATAL_ERROR "TEST was not recognized to be undefined")
|
||||||
|
else()
|
||||||
|
message(STATUS "TEST was treated as a variable")
|
||||||
|
endif()
|
|
@ -0,0 +1,3 @@
|
||||||
|
cmake_minimum_required(VERSION 3.3)
|
||||||
|
project(${RunCMake_TEST} NONE)
|
||||||
|
include(${RunCMake_TEST}.cmake)
|
|
@ -0,0 +1,5 @@
|
||||||
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(CMP0064-OLD)
|
||||||
|
run_cmake(CMP0064-WARN)
|
||||||
|
run_cmake(CMP0064-NEW)
|
|
@ -103,6 +103,7 @@ add_RunCMake_test(CMP0055)
|
||||||
add_RunCMake_test(CMP0057)
|
add_RunCMake_test(CMP0057)
|
||||||
add_RunCMake_test(CMP0059)
|
add_RunCMake_test(CMP0059)
|
||||||
add_RunCMake_test(CMP0060)
|
add_RunCMake_test(CMP0060)
|
||||||
|
add_RunCMake_test(CMP0064)
|
||||||
if(CMAKE_GENERATOR MATCHES "Make")
|
if(CMAKE_GENERATOR MATCHES "Make")
|
||||||
add_RunCMake_test(Make)
|
add_RunCMake_test(Make)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -4,3 +4,6 @@ run_cmake(InvalidArgument1)
|
||||||
run_cmake(IsDirectory)
|
run_cmake(IsDirectory)
|
||||||
run_cmake(IsDirectoryLong)
|
run_cmake(IsDirectoryLong)
|
||||||
run_cmake(elseif-message)
|
run_cmake(elseif-message)
|
||||||
|
|
||||||
|
run_cmake(TestNameThatExists)
|
||||||
|
run_cmake(TestNameThatDoesNotExist)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
TestThatDoesNotExist is false
|
|
@ -0,0 +1,6 @@
|
||||||
|
cmake_policy(SET CMP0064 NEW)
|
||||||
|
if(TEST TestThatDoesNotExist)
|
||||||
|
message(FATAL_ERROR "if TestThatDoesNotExist is true")
|
||||||
|
else()
|
||||||
|
message(STATUS "if TestThatDoesNotExist is false")
|
||||||
|
endif()
|
|
@ -0,0 +1 @@
|
||||||
|
TestThatExists is true
|
|
@ -0,0 +1,7 @@
|
||||||
|
cmake_policy(SET CMP0064 NEW)
|
||||||
|
add_test(NAME TestThatExists COMMAND ${CMAKE_COMMAND} -E echo "A CMake Test")
|
||||||
|
if(TEST TestThatExists)
|
||||||
|
message(STATUS "if TestThatExists is true")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "if TestThatExists is false")
|
||||||
|
endif()
|
Loading…
Reference in New Issue