[Cmake-commits] [cmake-commits] hoffman committed Bar.cmake NONE 1.1.2.2 CMakeLists.txt NONE 1.2.2.2 FindFoo.cmake NONE 1.1.2.2 main.c NONE 1.1.2.2

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Feb 4 11:44:21 EST 2009


Update of /cvsroot/CMake/CMake/Tests/PolicyScope
In directory public:/mounts/ram/cvs-serv32179/Tests/PolicyScope

Added Files:
      Tag: CMake-2-6
	Bar.cmake CMakeLists.txt FindFoo.cmake main.c 
Log Message:
ENH: merge in changes to 2.6 RC 10


--- NEW FILE: FindFoo.cmake ---
cmake_minimum_required(VERSION 2.6.3)
cmake_policy(SET CMP0003 OLD)

--- NEW FILE: CMakeLists.txt ---
project(PolicyScope C)
# No cmake_minimum_required(VERSION), it's in FindFoo.

#-----------------------------------------------------------------------------
# Helper function to report results.
function(check msg lhs rhs)
  if(NOT "${lhs}" STREQUAL "${rhs}")
    message(FATAL_ERROR "${msg}: expected [${lhs}], got [${rhs}]")
  endif()
endfunction(check)

#-----------------------------------------------------------------------------
# Test using a development framework that sets policies for us.

# Policy CMP0011 should not be set at this point.
cmake_policy(GET CMP0011 cmp)
check(CMP0011 "" "${cmp}")

# Put the test modules in the search path.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

# The included file should set policies for us.
find_package(Foo)

# Check policies set by the package.
cmake_policy(GET CMP0003 cmp)
check(CMP0003 "OLD" "${cmp}")
cmake_policy(GET CMP0002 cmp)
check(CMP0002 "NEW" "${cmp}")
cmake_policy(GET CMP0011 cmp)
check(CMP0011 "NEW" "${cmp}")

# Make sure an included file cannot change policies.
include(Bar)
cmake_policy(GET CMP0003 cmp)
check(CMP0003 "OLD" "${cmp}")

# Allow the included file to change policies.
include(Bar NO_POLICY_SCOPE)
cmake_policy(GET CMP0003 cmp)
check(CMP0003 "NEW" "${cmp}")

#-----------------------------------------------------------------------------
# Test function and macro policy recording.

# Create the functions in an isolated scope in which we change policies.
cmake_policy(PUSH)
if(1)
  # Change CMP0002
  cmake_policy(SET CMP0002 OLD)
  function(func1)
    # CMP0002 should be changed when this function is invoked
    cmake_policy(GET CMP0002 cmp)
    check(CMP0002 "OLD" "${cmp}")
  endfunction(func1)

  # Unset CMP0002
  cmake_policy(VERSION 2.4)
  macro(macro1)
    # CMP0002 should be unset when this macro is invoked
    cmake_policy(GET CMP0002 cmp)
    check(CMP0002 "" "${cmp}")

    # Setting the policy should work here and also in the caller.
    cmake_policy(SET CMP0002 OLD)
    cmake_policy(GET CMP0002 cmp)
    check(CMP0002 "OLD" "${cmp}")
  endmacro(macro1)
endif(1)
cmake_policy(POP)

# CMP0002 should still be NEW in this context.
cmake_policy(GET CMP0002 cmp)
check(CMP0002 "NEW" "${cmp}")

# Check the recorded policies
func1()
macro1()

# The macro should have changed CMP0002.
cmake_policy(GET CMP0002 cmp)
check(CMP0002 "OLD" "${cmp}")

#-----------------------------------------------------------------------------
# Dummy executable so the project can build and run.
add_executable(PolicyScope main.c)

--- NEW FILE: main.c ---
int main()
{
  return 0;
}

--- NEW FILE: Bar.cmake ---
cmake_minimum_required(VERSION 2.6.3)

# Make sure a policy set differently by our includer is now correct.
cmake_policy(GET CMP0003 cmp)
check(CMP0003 "NEW" "${cmp}")

# Test allowing the top-level file to not have cmake_minimum_required.
cmake_policy(SET CMP0000 OLD)



More information about the Cmake-commits mailing list