2008-08-30 18:32:52 +04:00
|
|
|
cmake_minimum_required(VERSION 2.6)
|
|
|
|
project(Unset C)
|
2008-08-25 18:31:29 +04:00
|
|
|
|
|
|
|
# Local variable
|
|
|
|
set(x 42)
|
|
|
|
if(NOT x EQUAL 42)
|
|
|
|
message(FATAL_ERROR "x!=42")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-08-25 18:31:29 +04:00
|
|
|
|
|
|
|
if(NOT DEFINED x)
|
|
|
|
message(FATAL_ERROR "x should be defined!")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-08-25 18:31:29 +04:00
|
|
|
|
|
|
|
unset(x)
|
|
|
|
if(DEFINED x)
|
|
|
|
message(FATAL_ERROR "x should be undefined now!")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-08-25 18:31:29 +04:00
|
|
|
|
|
|
|
# Local variable test unset via set()
|
|
|
|
set(x 43)
|
|
|
|
if(NOT x EQUAL 43)
|
|
|
|
message(FATAL_ERROR "x!=43")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-08-25 18:31:29 +04:00
|
|
|
set(x)
|
|
|
|
if(DEFINED x)
|
|
|
|
message(FATAL_ERROR "x should be undefined now!")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-08-25 18:31:29 +04:00
|
|
|
|
|
|
|
# Cache variable
|
|
|
|
set(BAR "test" CACHE STRING "documentation")
|
|
|
|
if(NOT DEFINED BAR)
|
|
|
|
message(FATAL_ERROR "BAR not defined")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-08-25 18:31:29 +04:00
|
|
|
|
2008-09-25 18:21:15 +04:00
|
|
|
# Test interaction of cache entries with variables.
|
|
|
|
set(BAR "test-var")
|
|
|
|
if(NOT "$CACHE{BAR}" STREQUAL "test")
|
|
|
|
message(FATAL_ERROR "\$CACHE{BAR} changed by variable BAR")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-09-25 18:21:15 +04:00
|
|
|
if(NOT "${BAR}" STREQUAL "test-var")
|
|
|
|
message(FATAL_ERROR "\${BAR} not separate from \$CACHE{BAR}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-09-25 18:21:15 +04:00
|
|
|
unset(BAR)
|
|
|
|
if(NOT "${BAR}" STREQUAL "test")
|
|
|
|
message(FATAL_ERROR "\${BAR} does not fall through to \$CACHE{BAR}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-09-25 18:21:15 +04:00
|
|
|
|
|
|
|
# Test unsetting of CACHE entry.
|
2008-08-25 18:31:29 +04:00
|
|
|
unset(BAR CACHE)
|
|
|
|
if(DEFINED BAR)
|
|
|
|
message(FATAL_ERROR "BAR still defined")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-08-25 18:31:29 +04:00
|
|
|
|
2013-10-08 16:37:47 +04:00
|
|
|
# Test unset(... PARENT_SCOPE)
|
|
|
|
function(unset_zots)
|
|
|
|
if(NOT DEFINED ZOT1)
|
|
|
|
message(FATAL_ERROR "ZOT1 is not defined inside function")
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED ZOT2)
|
|
|
|
message(FATAL_ERROR "ZOT2 is not defined inside function")
|
|
|
|
endif()
|
|
|
|
unset(ZOT1)
|
|
|
|
unset(ZOT2 PARENT_SCOPE)
|
|
|
|
if(DEFINED ZOT1)
|
|
|
|
message(FATAL_ERROR "ZOT1 is defined inside function after unset")
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED ZOT2)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"ZOT2 is not defined inside function after unset(... PARENT_SCOPE)")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
set(ZOT1 1)
|
|
|
|
set(ZOT2 2)
|
|
|
|
unset_zots()
|
|
|
|
if(NOT DEFINED ZOT1)
|
|
|
|
message(FATAL_ERROR "ZOT1 is not still defined after function")
|
|
|
|
endif()
|
|
|
|
if(DEFINED ZOT2)
|
|
|
|
message(FATAL_ERROR "ZOT2 is still defined after function unset PARENT_SCOPE")
|
|
|
|
endif()
|
2008-08-25 18:31:29 +04:00
|
|
|
|
2008-08-30 18:32:52 +04:00
|
|
|
add_executable(Unset unset.c)
|