Option: Add a test that verifies interaction with normal variables

This commit is contained in:
Robert Maynard
2018-06-21 14:52:12 -04:00
parent 5bb3d40a28
commit 12e6f83319
2 changed files with 17 additions and 0 deletions

View File

@@ -49,6 +49,7 @@ 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

View File

@@ -0,0 +1,16 @@
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()