diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2018-06-21 18:53:11 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-07-09 11:48:28 (GMT) |
commit | 2a5f5c0e316d415e1b8207348b34761d34f191ae (patch) | |
tree | a17a979c357a3148424b71fc0bcac898b1ec7e4a /Tests | |
parent | 12e6f83319d089b3295b4211d0d4810575e8f7d5 (diff) | |
download | CMake-2a5f5c0e316d415e1b8207348b34761d34f191ae.zip CMake-2a5f5c0e316d415e1b8207348b34761d34f191ae.tar.gz CMake-2a5f5c0e316d415e1b8207348b34761d34f191ae.tar.bz2 |
option: respect existing normal variable
Add policy CMP0077 to change this behavior in a compatible way.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeOnly/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/CMakeOnly/option/CMakeLists.txt | 16 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/option/CMP0077-NEW.cmake | 14 | ||||
-rw-r--r-- | Tests/RunCMake/option/CMP0077-OLD.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/option/CMP0077-WARN-stderr.txt | 7 | ||||
-rw-r--r-- | Tests/RunCMake/option/CMP0077-WARN.cmake | 5 | ||||
-rw-r--r-- | Tests/RunCMake/option/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/option/RunCMakeTest.cmake | 5 |
9 files changed, 44 insertions, 17 deletions
diff --git a/Tests/CMakeOnly/CMakeLists.txt b/Tests/CMakeOnly/CMakeLists.txt index 8a3a83b..204d54c 100644 --- a/Tests/CMakeOnly/CMakeLists.txt +++ b/Tests/CMakeOnly/CMakeLists.txt @@ -49,7 +49,6 @@ add_CMakeOnly_test(TargetScope) add_CMakeOnly_test(find_library) add_CMakeOnly_test(find_path) -add_CMakeOnly_test(option) add_test(CMakeOnly.ProjectInclude ${CMAKE_CMAKE_COMMAND} -DTEST=ProjectInclude diff --git a/Tests/CMakeOnly/option/CMakeLists.txt b/Tests/CMakeOnly/option/CMakeLists.txt deleted file mode 100644 index d040fb5..0000000 --- a/Tests/CMakeOnly/option/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -cmake_minimum_required (VERSION 2.8) -project(OptionTest NONE) - -#Verify that normal variable take precedence over cache variables -option(OPT_LOCAL_VAR1 "TEST_VAR" ON) -set(OPT_LOCAL_VAR1 FALSE) -if(OPT_LOCAL_VAR1) - message(FATAL_ERROR "local variable didn't take precedence over cache variable") -endif() - -#Verify that option overwrites existing normal variable -set(OPT_LOCAL_VAR2 FALSE) -option(OPT_LOCAL_VAR2 "TEST_VAR" ON) -if(NOT OPT_LOCAL_VAR2) - message(FATAL_ERROR "option failed to overwrite existing normal variable") -endif() diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index daf3940..e55d97d 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -239,6 +239,7 @@ add_RunCMake_test(include_directories) add_RunCMake_test(include_guard) add_RunCMake_test(list) add_RunCMake_test(message) +add_RunCMake_test(option) add_RunCMake_test(project -DCMake_TEST_RESOURCES=${CMake_TEST_RESOURCES}) add_RunCMake_test(return) add_RunCMake_test(separate_arguments) diff --git a/Tests/RunCMake/option/CMP0077-NEW.cmake b/Tests/RunCMake/option/CMP0077-NEW.cmake new file mode 100644 index 0000000..d4c518b --- /dev/null +++ b/Tests/RunCMake/option/CMP0077-NEW.cmake @@ -0,0 +1,14 @@ + +#Verify that option DOESN'T overwrite existing normal variable when the policy +#is set to NEW +cmake_policy(SET CMP0077 NEW) +set(OPT_LOCAL_VAR FALSE) +option(OPT_LOCAL_VAR "TEST_VAR" ON) +if(OPT_LOCAL_VAR) + message(FATAL_ERROR "option failed to overwrite existing normal variable") +endif() + +get_property(_exists_in_cache CACHE OPT_LOCAL_VAR PROPERTY VALUE SET) +if(_exists_in_cache) + message(FATAL_ERROR "value should not exist in cache as it was already a local variable") +endif() diff --git a/Tests/RunCMake/option/CMP0077-OLD.cmake b/Tests/RunCMake/option/CMP0077-OLD.cmake new file mode 100644 index 0000000..4c52d4b --- /dev/null +++ b/Tests/RunCMake/option/CMP0077-OLD.cmake @@ -0,0 +1,9 @@ + +#Verify that option overwrites existing normal variable when the policy +#is set to OLD +cmake_policy(SET CMP0077 OLD) +set(OPT_LOCAL_VAR FALSE) +option(OPT_LOCAL_VAR "TEST_VAR" ON) +if(NOT OPT_LOCAL_VAR) + message(FATAL_ERROR "option failed to overwrite existing normal variable") +endif() diff --git a/Tests/RunCMake/option/CMP0077-WARN-stderr.txt b/Tests/RunCMake/option/CMP0077-WARN-stderr.txt new file mode 100644 index 0000000..0d02ffb --- /dev/null +++ b/Tests/RunCMake/option/CMP0077-WARN-stderr.txt @@ -0,0 +1,7 @@ +CMake Warning \(dev\) at CMP0077-WARN.cmake:5 \(option\): + Policy CMP0077 is not set: option\(\) honors normal variables. Run "cmake + --help-policy CMP0077" for policy details. Use the cmake_policy command to + set the policy and suppress this warning. + + For compatibility with older versions of CMake, option is clearing the + normal variable 'OPT_LOCAL_VAR'. diff --git a/Tests/RunCMake/option/CMP0077-WARN.cmake b/Tests/RunCMake/option/CMP0077-WARN.cmake new file mode 100644 index 0000000..7f99456 --- /dev/null +++ b/Tests/RunCMake/option/CMP0077-WARN.cmake @@ -0,0 +1,5 @@ + +#Verify that option overwrites existing normal variable when the policy +#is set to OLD +set(OPT_LOCAL_VAR FALSE) +option(OPT_LOCAL_VAR "TEST_VAR" ON) diff --git a/Tests/RunCMake/option/CMakeLists.txt b/Tests/RunCMake/option/CMakeLists.txt new file mode 100644 index 0000000..11dc49a --- /dev/null +++ b/Tests/RunCMake/option/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.12) +project(${RunCMake_TEST} CXX) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/option/RunCMakeTest.cmake b/Tests/RunCMake/option/RunCMakeTest.cmake new file mode 100644 index 0000000..0501624 --- /dev/null +++ b/Tests/RunCMake/option/RunCMakeTest.cmake @@ -0,0 +1,5 @@ +include(RunCMake) + +run_cmake(CMP0077-OLD) +run_cmake(CMP0077-NEW) +run_cmake(CMP0077-WARN) |