summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-06-26 10:33:16 (GMT)
committerBrad King <brad.king@kitware.com>2020-06-29 11:50:47 (GMT)
commitf2c903fb9a02b129c6673385363f2a99f2f153ce (patch)
treed8c203b97395da6ef70d4e5d0bd3c84cb1a7d08a
parente66fe75792a2fbe9f3ffe237c748008906ae7116 (diff)
downloadCMake-f2c903fb9a02b129c6673385363f2a99f2f153ce.zip
CMake-f2c903fb9a02b129c6673385363f2a99f2f153ce.tar.gz
CMake-f2c903fb9a02b129c6673385363f2a99f2f153ce.tar.bz2
find_library: Check that library files are readable
Refactoring in commit 6b85166920 (ENH: Refactor find_library search logic, 2008-09-22, v2.8.0~1665) dropped a call to `FileExists` on the path under the assumption that the presence of a file in a directory listing means it exists. However, dropping that also dropped a check that verifies the file is readable. Restore the `FileExists` call to ensure that we only find readable libraries.
-rw-r--r--Source/cmFindLibraryCommand.cxx3
-rw-r--r--Tests/RunCMake/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/find_library/LibSymLink-stderr.txt2
-rw-r--r--Tests/RunCMake/find_library/LibSymLink.cmake17
-rw-r--r--Tests/RunCMake/find_library/RunCMakeTest.cmake3
5 files changed, 24 insertions, 3 deletions
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx
index 31f1201..3242b6d 100644
--- a/Source/cmFindLibraryCommand.cxx
+++ b/Source/cmFindLibraryCommand.cxx
@@ -433,7 +433,8 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path,
#endif
if (name.Regex.find(testName)) {
this->TestPath = cmStrCat(path, origName);
- if (!cmSystemTools::FileIsDirectory(this->TestPath)) {
+ // Make sure the path is readable and is not a directory.
+ if (cmSystemTools::FileExists(this->TestPath, true)) {
this->DebugLibraryFound(name.Raw, dir);
// This is a matching file. Check if it is better than the
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 866e7c0..f7526e8 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -317,7 +317,7 @@ add_RunCMake_test(ctest_upload)
add_RunCMake_test(ctest_fixtures)
add_RunCMake_test(file)
add_RunCMake_test(find_file)
-add_RunCMake_test(find_library)
+add_RunCMake_test(find_library -DCYGWIN=${CYGWIN})
add_RunCMake_test(find_package)
add_RunCMake_test(find_path)
add_RunCMake_test(find_program -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
diff --git a/Tests/RunCMake/find_library/LibSymLink-stderr.txt b/Tests/RunCMake/find_library/LibSymLink-stderr.txt
new file mode 100644
index 0000000..8a2f088
--- /dev/null
+++ b/Tests/RunCMake/find_library/LibSymLink-stderr.txt
@@ -0,0 +1,2 @@
+^SYMLINK_LIBRARY='SYMLINK_LIBRARY-NOTFOUND'
+SYMLINK_LIBRARY='[^']*/Tests/RunCMake/find_library/LibSymLink-build/lib/libsymlink.a'$
diff --git a/Tests/RunCMake/find_library/LibSymLink.cmake b/Tests/RunCMake/find_library/LibSymLink.cmake
new file mode 100644
index 0000000..8ee4b75
--- /dev/null
+++ b/Tests/RunCMake/find_library/LibSymLink.cmake
@@ -0,0 +1,17 @@
+list(APPEND CMAKE_FIND_LIBRARY_PREFIXES lib)
+list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .a)
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
+file(CREATE_LINK "libsymlinked.a" "${CMAKE_CURRENT_BINARY_DIR}/lib/libsymlink.a" SYMBOLIC)
+find_library(SYMLINK_LIBRARY
+ NAMES symlink
+ PATHS ${CMAKE_CURRENT_BINARY_DIR}/lib
+ NO_DEFAULT_PATH
+ )
+message("SYMLINK_LIBRARY='${SYMLINK_LIBRARY}'")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lib/libsymlinked.a" "symlinked")
+find_library(SYMLINK_LIBRARY
+ NAMES symlink
+ PATHS ${CMAKE_CURRENT_BINARY_DIR}/lib
+ NO_DEFAULT_PATH
+ )
+message("SYMLINK_LIBRARY='${SYMLINK_LIBRARY}'")
diff --git a/Tests/RunCMake/find_library/RunCMakeTest.cmake b/Tests/RunCMake/find_library/RunCMakeTest.cmake
index b6aadce..c7d69e4 100644
--- a/Tests/RunCMake/find_library/RunCMakeTest.cmake
+++ b/Tests/RunCMake/find_library/RunCMakeTest.cmake
@@ -3,8 +3,9 @@ include(RunCMake)
run_cmake(Created)
run_cmake(FromPrefixPath)
run_cmake(FromPATHEnv)
-if(CMAKE_HOST_UNIX)
+if(UNIX AND NOT CYGWIN)
run_cmake(LibArchLink)
+ run_cmake(LibSymLink)
endif()
run_cmake(PrefixInPATH)
run_cmake(Required)