diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-06-01 14:05:34 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-06-02 18:55:00 (GMT) |
commit | 87b71eec6257b0d9c43b446205d61f334278fe7d (patch) | |
tree | 727adaa232629c537ca47112fbc3f7fbeec36127 /Tests/RunCMake/find_file/NO_CACHE.cmake | |
parent | 2104cfe388f5d77b98727c89edff453b1d23fed6 (diff) | |
download | CMake-87b71eec6257b0d9c43b446205d61f334278fe7d.zip CMake-87b71eec6257b0d9c43b446205d61f334278fe7d.tar.gz CMake-87b71eec6257b0d9c43b446205d61f334278fe7d.tar.bz2 |
find_*: Add support for option NO_CACHE
Request that find result is stored in a normal variable rather than a
cache entry.
Fixes: #20687
Issue: #20743
Diffstat (limited to 'Tests/RunCMake/find_file/NO_CACHE.cmake')
-rw-r--r-- | Tests/RunCMake/find_file/NO_CACHE.cmake | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/Tests/RunCMake/find_file/NO_CACHE.cmake b/Tests/RunCMake/find_file/NO_CACHE.cmake new file mode 100644 index 0000000..65156b9 --- /dev/null +++ b/Tests/RunCMake/find_file/NO_CACHE.cmake @@ -0,0 +1,129 @@ +find_file(FILE_exists + NAMES PrefixInPATH.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/include + NO_CACHE + NO_DEFAULT_PATH + ) +if (DEFINED CACHE{FILE_exists}) + message(SEND_ERROR "Cache variable defined: FILE_exists") +endif() +message(STATUS "FILE_exists='${FILE_exists}'") + + +find_file(FILE_doNotExists + NAMES doNotExists.h + NO_CACHE + ) +if (DEFINED CACHE{FILE_doNotExists}) + message(SEND_ERROR "Cache variable defined: FILE_doNotExists") +endif() +message(STATUS "FILE_doNotExists='${FILE_doNotExists}'") + + +cmake_policy(SET CMP0125 OLD) +message(STATUS "") +message(STATUS "Policy CMP0125 = OLD") +file(REMOVE "${CMAKE_BINARY_DIR}/PrefixInPATH.h") + +set(FILE_cache "unknown" CACHE FILEPATH "") +find_file(FILE_cache + NAMES PrefixInPATH.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/include + NO_CACHE + NO_DEFAULT_PATH + ) +if (NOT DEFINED CACHE{FILE_cache}) + message(SEND_ERROR "Cache variable not defined: FILE_cache") +endif() +message(STATUS "CACHED FILE_cache='$CACHE{FILE_cache}'") +unset(FILE_cache CACHE) +message(STATUS "FILE_cache='${FILE_cache}'") + + +set(FILE_cache "PrefixInPATH.h" CACHE FILEPATH "") +unset(FILE_cache) +find_file(FILE_cache + NAMES PrefixInPATH.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/include + NO_CACHE + NO_DEFAULT_PATH + ) +if (NOT DEFINED CACHE{FILE_cache}) + message(SEND_ERROR "Cache variable not defined: FILE_cache") +endif() +message(STATUS "CACHED FILE_cache='$CACHE{FILE_cache}'") +unset(FILE_cache CACHE) +message(STATUS "FILE_cache='${FILE_cache}'") + + +set(FILE_cache "PrefixInPATH.h" CACHE FILEPATH "") +unset(FILE_cache) +# simulate cache variable defined in command line +file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/include/PrefixInPATH.h" DESTINATION "${CMAKE_BINARY_DIR}") +set_property(CACHE FILE_cache PROPERTY TYPE UNINITIALIZED) +find_file(FILE_cache + NAMES PrefixInPATH.h + NO_CACHE + NO_DEFAULT_PATH + ) +if (NOT DEFINED CACHE{FILE_cache}) + message(SEND_ERROR "Cache variable not defined: FILE_cache") +endif() +message(STATUS "CACHED FILE_cache='$CACHE{FILE_cache}'") +unset(FILE_cache CACHE) +message(STATUS "FILE_cache='${FILE_cache}'") + + +cmake_policy(SET CMP0125 NEW) +message(STATUS "") +message(STATUS "Policy CMP0125 = NEW") +file(REMOVE "${CMAKE_BINARY_DIR}/PrefixInPATH.h") + +set(FILE_cache "unknown" CACHE FILEPATH "") +unset(FILE_cache) +find_file(FILE_cache + NAMES PrefixInPATH.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/include + NO_CACHE + NO_DEFAULT_PATH + ) +if (NOT DEFINED CACHE{FILE_cache}) + message(SEND_ERROR "Cache variable not defined: FILE_cache") +endif() +message(STATUS "CACHED FILE_cache='$CACHE{FILE_cache}'") +unset(FILE_cache CACHE) +message(STATUS "FILE_cache='${FILE_cache}'") + + +set(FILE_cache "PrefixInPATH.h" CACHE FILEPATH "") +unset(FILE_cache) +find_file(FILE_cache + NAMES PrefixInPATH.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/include + NO_CACHE + NO_DEFAULT_PATH + ) +if (NOT DEFINED CACHE{FILE_cache}) + message(SEND_ERROR "Cache variable not defined: FILE_cache") +endif() +message(STATUS "CACHED FILE_cache='$CACHE{FILE_cache}'") +unset(FILE_cache CACHE) +message(STATUS "FILE_cache='${FILE_cache}'") + + +set(FILE_cache "PrefixInPATH.h" CACHE FILEPATH "") +unset(FILE_cache) +# simulate cache variable defined in command line +file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/include/PrefixInPATH.h" DESTINATION "${CMAKE_BINARY_DIR}") +set_property(CACHE FILE_cache PROPERTY TYPE UNINITIALIZED) +find_file(FILE_cache + NAMES PrefixInPATH.h + NO_CACHE + NO_DEFAULT_PATH + ) +if (NOT DEFINED CACHE{FILE_cache}) + message(SEND_ERROR "Cache variable not defined: FILE_cache") +endif() +message(STATUS "CACHED FILE_cache='$CACHE{FILE_cache}'") +unset(FILE_cache CACHE) +message(STATUS "FILE_cache='${FILE_cache}'") |