mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-24 07:08:38 -05:00
Merge topic 'set-cache-keep-normal-variable'
d96eb55282 set(CACHE): do not remove normal variable
Acked-by: Kitware Robot <kwrobot@kitware.com>
Reviewed-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !6146
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
|
||||
# enforce policy CMP0125 to ensure predictable result of find_* commands
|
||||
cmake_policy(SET CMP0125 NEW)
|
||||
|
||||
cmake_policy(SET CMP0126 NEW)
|
||||
|
||||
set(VAR 1)
|
||||
set(VAR 2 CACHE STRING "")
|
||||
|
||||
if (NOT VAR EQUAL 1)
|
||||
message(FATAL_ERROR "normal variable does not exist anymore.")
|
||||
endif()
|
||||
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/file.txt" "")
|
||||
set(VAR file.txt)
|
||||
set(VAR "" CACHE STRING "" FORCE)
|
||||
set_property(CACHE VAR PROPERTY TYPE UNINITIALIZED)
|
||||
|
||||
find_file(VAR NAMES file.txt PATHS "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
unset(VAR CACHE)
|
||||
if (NOT DEFINED VAR)
|
||||
message(FATAL_ERROR "find_file: normal variable does not exist anymore.")
|
||||
endif()
|
||||
if (NOT VAR STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/file.txt")
|
||||
message(FATAL_ERROR "find_file: failed to set normal variable.")
|
||||
endif()
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
cmake_policy(SET CMP0126 NEW)
|
||||
|
||||
set(VAR 1)
|
||||
set(VAR 2 CACHE STRING "")
|
||||
|
||||
if (NOT VAR EQUAL 1)
|
||||
message(FATAL_ERROR "normal variable does not exist anymore.")
|
||||
endif()
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
# enforce policy CMP0125 to ensure predictable result of find_* commands
|
||||
cmake_policy(SET CMP0125 NEW)
|
||||
|
||||
cmake_policy(SET CMP0126 OLD)
|
||||
|
||||
set(VAR 1)
|
||||
set(VAR 2 CACHE STRING "")
|
||||
|
||||
if (VAR EQUAL 1)
|
||||
message(FATAL_ERROR "normal variable still exist.")
|
||||
endif()
|
||||
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/file.txt" "")
|
||||
set(VAR file.txt)
|
||||
set(VAR "" CACHE STRING "" FORCE)
|
||||
set_property(CACHE VAR PROPERTY TYPE UNINITIALIZED)
|
||||
|
||||
find_file(VAR NAMES file.txt PATHS "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
unset(VAR CACHE)
|
||||
if (DEFINED VAR)
|
||||
message(FATAL_ERROR "find_file: normal variable still exist.")
|
||||
endif()
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
cmake_policy(SET CMP0126 OLD)
|
||||
|
||||
set(VAR 1)
|
||||
set(VAR 2 CACHE STRING "")
|
||||
|
||||
if (NOT VAR EQUAL 3)
|
||||
message(FATAL_ERROR "normal variable still exist.")
|
||||
endif()
|
||||
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
||||
@@ -0,0 +1,6 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake(CMP0126-OLD)
|
||||
run_cmake_with_options(CMP0126-OLD_CL -DVAR=3)
|
||||
run_cmake(CMP0126-NEW)
|
||||
run_cmake_with_options(CMP0126-NEW_CL -DVAR=3)
|
||||
@@ -140,6 +140,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "(Linux|Darwin)")
|
||||
add_RunCMake_test(CMP0125 -DCMAKE_SHARED_LIBRARY_PREFIX=${CMAKE_SHARED_LIBRARY_PREFIX}
|
||||
-DCMAKE_SHARED_LIBRARY_SUFFIX=${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
endif()
|
||||
add_RunCMake_test(CMP0126)
|
||||
|
||||
# The test for Policy 65 requires the use of the
|
||||
# CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode
|
||||
|
||||
Reference in New Issue
Block a user