summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/find_library
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2021-06-01 14:05:34 (GMT)
committerBrad King <brad.king@kitware.com>2021-06-02 18:55:00 (GMT)
commit87b71eec6257b0d9c43b446205d61f334278fe7d (patch)
tree727adaa232629c537ca47112fbc3f7fbeec36127 /Tests/RunCMake/find_library
parent2104cfe388f5d77b98727c89edff453b1d23fed6 (diff)
downloadCMake-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_library')
-rw-r--r--Tests/RunCMake/find_library/NO_CACHE-stdout.txt18
-rw-r--r--Tests/RunCMake/find_library/NO_CACHE.cmake133
-rw-r--r--Tests/RunCMake/find_library/RunCMakeTest.cmake1
3 files changed, 152 insertions, 0 deletions
diff --git a/Tests/RunCMake/find_library/NO_CACHE-stdout.txt b/Tests/RunCMake/find_library/NO_CACHE-stdout.txt
new file mode 100644
index 0000000..1b4c2a9
--- /dev/null
+++ b/Tests/RunCMake/find_library/NO_CACHE-stdout.txt
@@ -0,0 +1,18 @@
+-- LIB_exists='.+/Tests/RunCMake/find_library/lib/libPrefixInPATH.a'
+-- LIB_doNotExists='LIB_doNotExists-NOTFOUND'
+--[ ]+
+-- Policy CMP0125 = OLD
+-- CACHED LIB_cache='unknown'
+-- LIB_cache='unknown'
+-- CACHED LIB_cache='libPrefixInPATH.a'
+-- LIB_cache='libPrefixInPATH.a'
+-- CACHED LIB_cache='libPrefixInPATH.a'
+-- LIB_cache='libPrefixInPATH.a'
+--[ ]+
+-- Policy CMP0125 = NEW
+-- CACHED LIB_cache='unknown'
+-- LIB_cache='unknown'
+-- CACHED LIB_cache='libPrefixInPATH.a'
+-- LIB_cache='libPrefixInPATH.a'
+-- CACHED LIB_cache='libPrefixInPATH.a'
+-- LIB_cache='.+/Tests/RunCMake/find_library/NO_CACHE-build/libPrefixInPATH.a'
diff --git a/Tests/RunCMake/find_library/NO_CACHE.cmake b/Tests/RunCMake/find_library/NO_CACHE.cmake
new file mode 100644
index 0000000..a94b828
--- /dev/null
+++ b/Tests/RunCMake/find_library/NO_CACHE.cmake
@@ -0,0 +1,133 @@
+list(APPEND CMAKE_FIND_LIBRARY_PREFIXES lib)
+list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .a)
+
+find_library(LIB_exists
+ NAMES PrefixInPATH
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib
+ NO_CACHE
+ NO_DEFAULT_PATH
+ )
+if (DEFINED CACHE{LIB_exists})
+ message(SEND_ERROR "Cache variable defined: LIB_exists")
+endif()
+message(STATUS "LIB_exists='${LIB_exists}'")
+
+
+find_library(LIB_doNotExists
+ NAMES doNotExists
+ NO_CACHE
+ )
+if (DEFINED CACHE{LIB_doNotExists})
+ message(SEND_ERROR "Cache variable defined: LIB_doNotExists")
+endif()
+message(STATUS "LIB_doNotExists='${LIB_doNotExists}'")
+
+
+cmake_policy(SET CMP0125 OLD)
+message(STATUS "")
+message(STATUS "Policy CMP0125 = OLD")
+file(REMOVE "${CMAKE_BINARY_DIR}/libPrefixInPATH.a")
+
+set(LIB_cache "unknown" CACHE FILEPATH "")
+find_library(LIB_cache
+ NAMES PrefixInPATH
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib
+ NO_CACHE
+ NO_DEFAULT_PATH
+ )
+if (NOT DEFINED CACHE{LIB_cache})
+ message(SEND_ERROR "Cache variable not defined: LIB_cache")
+endif()
+message(STATUS "CACHED LIB_cache='$CACHE{LIB_cache}'")
+unset(LIB_cache CACHE)
+message(STATUS "LIB_cache='${LIB_cache}'")
+
+
+set(LIB_cache "libPrefixInPATH.a" CACHE FILEPATH "")
+unset(LIB_cache)
+find_library(LIB_cache
+ NAMES PrefixInPATH
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib
+ NO_CACHE
+ NO_DEFAULT_PATH
+ )
+if (NOT DEFINED CACHE{LIB_cache})
+ message(SEND_ERROR "Cache variable not defined: LIB_cache")
+endif()
+message(STATUS "CACHED LIB_cache='$CACHE{LIB_cache}'")
+unset(LIB_cache CACHE)
+message(STATUS "LIB_cache='${LIB_cache}'")
+
+
+set(LIB_cache "libPrefixInPATH.a" CACHE FILEPATH "")
+unset(LIB_cache)
+# simulate cache variable defined in command line
+file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/lib/libPrefixInPATH.a" DESTINATION "${CMAKE_BINARY_DIR}")
+set_property(CACHE LIB_cache PROPERTY TYPE UNINITIALIZED)
+find_library(LIB_cache
+ NAMES PrefixInPATH
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib
+ NO_CACHE
+ NO_DEFAULT_PATH
+ )
+if (NOT DEFINED CACHE{LIB_cache})
+ message(SEND_ERROR "Cache variable not defined: LIB_cache")
+endif()
+message(STATUS "CACHED LIB_cache='$CACHE{LIB_cache}'")
+unset(LIB_cache CACHE)
+message(STATUS "LIB_cache='${LIB_cache}'")
+
+
+cmake_policy(SET CMP0125 NEW)
+message(STATUS "")
+message(STATUS "Policy CMP0125 = NEW")
+file(REMOVE "${CMAKE_BINARY_DIR}/libPrefixInPATH.a")
+
+set(LIB_cache "unknown" CACHE FILEPATH "")
+find_library(LIB_cache
+ NAMES PrefixInPATH
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib
+ NO_CACHE
+ NO_DEFAULT_PATH
+ )
+if (NOT DEFINED CACHE{LIB_cache})
+ message(SEND_ERROR "Cache variable not defined: LIB_cache")
+endif()
+message(STATUS "CACHED LIB_cache='$CACHE{LIB_cache}'")
+unset(LIB_cache CACHE)
+message(STATUS "LIB_cache='${LIB_cache}'")
+
+
+set(LIB_cache "libPrefixInPATH.a" CACHE FILEPATH "")
+unset(LIB_cache)
+find_library(LIB_cache
+ NAMES PrefixInPATH
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib
+ NO_CACHE
+ NO_DEFAULT_PATH
+ )
+if (NOT DEFINED CACHE{LIB_cache})
+ message(SEND_ERROR "Cache variable not defined: LIB_cache")
+endif()
+message(STATUS "CACHED LIB_cache='$CACHE{LIB_cache}'")
+unset(LIB_cache CACHE)
+message(STATUS "LIB_cache='${LIB_cache}'")
+
+
+set(LIB_cache "libPrefixInPATH.a" CACHE FILEPATH "")
+unset(LIB_cache)
+# simulate cache variable defined in command line
+file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/lib/libPrefixInPATH.a" DESTINATION "${CMAKE_BINARY_DIR}")
+set_property(CACHE LIB_cache PROPERTY TYPE UNINITIALIZED)
+find_library(LIB_cache
+ NAMES PrefixInPATH
+ PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib
+ NO_CACHE
+ NO_DEFAULT_PATH
+ )
+if (NOT DEFINED CACHE{LIB_cache})
+ message(SEND_ERROR "Cache variable not defined: LIB_cache")
+endif()
+message(STATUS "CACHED LIB_cache='$CACHE{LIB_cache}'")
+unset(LIB_cache CACHE)
+message(STATUS "LIB_cache='${LIB_cache}'")
diff --git a/Tests/RunCMake/find_library/RunCMakeTest.cmake b/Tests/RunCMake/find_library/RunCMakeTest.cmake
index c7d69e4..e297173 100644
--- a/Tests/RunCMake/find_library/RunCMakeTest.cmake
+++ b/Tests/RunCMake/find_library/RunCMakeTest.cmake
@@ -9,3 +9,4 @@ if(UNIX AND NOT CYGWIN)
endif()
run_cmake(PrefixInPATH)
run_cmake(Required)
+run_cmake(NO_CACHE)