Commit a6a67397 authored by Brad King's avatar Brad King

ENH: Add "if(POLICY policy-id)" option for IF command.

  - This will help projects support multiple CMake versions.
  - In order to set a policy when using a newer CMake but still
    working with an older CMake one may write
      if(POLICY CMP1234)
        cmake_policy(SET CMP1234 NEW)
      endif(POLICY CMP1234)
  - Note that since CMake 2.4 does not have if(POLICY) supporting
    it will also require using "if(COMMAND cmake_policy)"
parent 8e2f45c2
......@@ -357,6 +357,23 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
IncrementArguments(newArgs,argP1,argP2);
reducible = 1;
}
// does a policy exist
if (*arg == "POLICY" && argP1 != newArgs.end())
{
cmPolicies::PolicyID pid;
if(makefile->GetPolicies()->GetPolicyID((argP1)->c_str(), pid))
{
*arg = "1";
}
else
{
*arg = "0";
}
newArgs.erase(argP1);
argP1 = arg;
IncrementArguments(newArgs,argP1,argP2);
reducible = 1;
}
// is a variable defined
if (*arg == "DEFINED" && argP1 != newArgs.end())
{
......
......@@ -139,6 +139,9 @@ public:
" if(COMMAND command-name)\n"
"True if the given name is a command, macro or function that can be "
"invoked.\n"
" if(POLICY policy-id)\n"
"True if the given name is an existing policy "
"(of the form CMP<NNNN>).\n"
" if(EXISTS file-name)\n"
" if(EXISTS directory-name)\n"
"True if the named file or directory exists. "
......
......@@ -4,6 +4,11 @@
SET(CMAKE_BACKWARDS_COMPATIBILITY 1.4)
PROJECT (Complex)
# Try setting a new policy. The IF test is for coverage.
IF(POLICY CMP0003)
CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(POLICY CMP0003)
# Choose whether to test CMakeLib.
SET(COMPLEX_TEST_CMAKELIB 1)
IF(CMAKE_TEST_DIFFERENT_GENERATOR)
......
......@@ -4,6 +4,11 @@
SET(CMAKE_BACKWARDS_COMPATIBILITY 1.4)
PROJECT (Complex)
# Try setting a new policy. The IF test is for coverage.
IF(POLICY CMP0003)
CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(POLICY CMP0003)
# Choose whether to test CMakeLib.
SET(COMPLEX_TEST_CMAKELIB 1)
IF(CMAKE_TEST_DIFFERENT_GENERATOR)
......
......@@ -4,6 +4,11 @@
SET(CMAKE_BACKWARDS_COMPATIBILITY 1.4)
PROJECT (Complex)
# Try setting a new policy. The IF test is for coverage.
IF(POLICY CMP0003)
CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(POLICY CMP0003)
# Choose whether to test CMakeLib.
SET(COMPLEX_TEST_CMAKELIB 1)
IF(CMAKE_TEST_DIFFERENT_GENERATOR)
......
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