2 # No cmake_minimum_required(VERSION), it's in FindFoo.
4 #-----------------------------------------------------------------------------
5 # Helper function to report results.
6 function(check msg lhs rhs)
7 if(NOT "${lhs}" STREQUAL "${rhs}")
8 message(FATAL_ERROR "${msg}: expected [${lhs}], got [${rhs}]")
12 #-----------------------------------------------------------------------------
13 # Test using a development framework that sets policies for us.
15 # Policy CMP0011 should not be set at this point.
16 cmake_policy(GET CMP0011 cmp)
17 check(CMP0011 "" "${cmp}")
19 # Put the test modules in the search path.
20 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
22 # The included file should set policies for us.
25 # Check policies set by the package.
26 cmake_policy(GET CMP0003 cmp)
27 check(CMP0003 "OLD" "${cmp}")
28 cmake_policy(GET CMP0002 cmp)
29 check(CMP0002 "NEW" "${cmp}")
30 cmake_policy(GET CMP0011 cmp)
31 check(CMP0011 "NEW" "${cmp}")
33 # Make sure an included file cannot change policies.
35 cmake_policy(GET CMP0003 cmp)
36 check(CMP0003 "OLD" "${cmp}")
38 # Allow the included file to change policies.
39 include(Bar NO_POLICY_SCOPE)
40 cmake_policy(GET CMP0003 cmp)
41 check(CMP0003 "NEW" "${cmp}")
43 #-----------------------------------------------------------------------------
44 # Test function and macro policy recording.
46 # Create the functions in an isolated scope in which we change policies.
50 cmake_policy(SET CMP0002 OLD)
52 # CMP0002 should be changed when this function is invoked
53 cmake_policy(GET CMP0002 cmp)
54 check(CMP0002 "OLD" "${cmp}")
58 cmake_policy(VERSION 2.4)
60 # CMP0002 should be unset when this macro is invoked
61 cmake_policy(GET CMP0002 cmp)
62 check(CMP0002 "" "${cmp}")
64 # Setting the policy should work here and also in the caller.
65 cmake_policy(SET CMP0002 OLD)
66 cmake_policy(GET CMP0002 cmp)
67 check(CMP0002 "OLD" "${cmp}")
72 # CMP0002 should still be NEW in this context.
73 cmake_policy(GET CMP0002 cmp)
74 check(CMP0002 "NEW" "${cmp}")
76 # Check the recorded policies
80 # The macro should have changed CMP0002.
81 cmake_policy(GET CMP0002 cmp)
82 check(CMP0002 "OLD" "${cmp}")
84 #-----------------------------------------------------------------------------
85 # Dummy executable so the project can build and run.
86 add_executable(PolicyScope main.c)