diff options
author | Brad King <brad.king@kitware.com> | 2009-01-22 18:16:47 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-01-22 18:16:47 (GMT) |
commit | 3028ca756c8621b3cc37032987eb01fbe61da248 (patch) | |
tree | 1a32991d7d25cefaa5b214759d84ab2c20a3c0b5 /Tests | |
parent | 18eadebc4c0b43443861f40ca243e18dbabb2324 (diff) | |
download | CMake-3028ca756c8621b3cc37032987eb01fbe61da248.zip CMake-3028ca756c8621b3cc37032987eb01fbe61da248.tar.gz CMake-3028ca756c8621b3cc37032987eb01fbe61da248.tar.bz2 |
ENH: Better policies for functions and macros
This teaches functions and macros to use policies recorded at creation
time when they are invoked. It restores the policies as a weak policy
stack entry so that any policies set by a function escape to its caller
as before.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/PolicyScope/CMakeLists.txt | 55 | ||||
-rw-r--r-- | Tests/PolicyScope/main.c | 4 |
3 files changed, 60 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 7efb150..7091844 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -102,6 +102,7 @@ IF(BUILD_TESTING) ADD_TEST_MACRO(Preprocess Preprocess) ADD_TEST_MACRO(ExportImport ExportImport) ADD_TEST_MACRO(Unset Unset) + ADD_TEST_MACRO(PolicyScope PolicyScope) SET(CMAKE_BUILD_TEST_SOURCE_DIR "${CMake_SOURCE_DIR}/Tests/COnly") SET(CMAKE_BUILD_TEST_BINARY_DIR "${CMake_BINARY_DIR}/Tests/CMakeBuildCOnly") diff --git a/Tests/PolicyScope/CMakeLists.txt b/Tests/PolicyScope/CMakeLists.txt new file mode 100644 index 0000000..ccb64de --- /dev/null +++ b/Tests/PolicyScope/CMakeLists.txt @@ -0,0 +1,55 @@ +cmake_minimum_required(VERSION 2.6.3) +project(PolicyScope C) + +#----------------------------------------------------------------------------- +# 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 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) diff --git a/Tests/PolicyScope/main.c b/Tests/PolicyScope/main.c new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/PolicyScope/main.c @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} |