This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake".
The branch, next has been updated via 0412b809f4d426ad1826c10e7f4b2d172906b0ee (commit) via 6f5aede71642b05a351d5cf92e0c884ed9b4fd3c (commit) via e67963ed7316768bf0ebfbe42137d028c0d1d2a4 (commit) from 29c967ef21bf0248e965cac171cfa2fb51fbaf1c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0412b809f4d426ad1826c10e7f4b2d172906b0ee commit 0412b809f4d426ad1826c10e7f4b2d172906b0ee Merge: 29c967e 6f5aede Author: Brad King <brad.k...@kitware.com> AuthorDate: Tue Feb 28 15:23:21 2017 -0500 Commit: CMake Topic Stage <kwro...@kitware.com> CommitDate: Tue Feb 28 15:23:21 2017 -0500 Merge topic 'find-libarch-not-symlink' into next 6f5aede7 find_library: Skip 'lib => lib<arch>' searches if one symlinks the other e67963ed cmFindLibraryCommand: Refactor AddArchitecturePath logic https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6f5aede71642b05a351d5cf92e0c884ed9b4fd3c commit 6f5aede71642b05a351d5cf92e0c884ed9b4fd3c Author: Brad King <brad.k...@kitware.com> AuthorDate: Tue Feb 28 13:51:35 2017 -0500 Commit: Brad King <brad.k...@kitware.com> CommitDate: Tue Feb 28 14:56:54 2017 -0500 find_library: Skip 'lib => lib<arch>' searches if one symlinks the other The `FIND_LIBRARY_USE_LIB<arch>_PATHS` global properties ask `find_library` to look in `lib<arch>` directories automatically before corresponding `lib` directories. However, if `lib<arch>` is just a symlink to `lib` (or vice-versa) then we should skip adding the `lib<arch>` path. Such symlinks typically only exist to satisfy software that expects the `lib<arch>` path to be available. Fixes: #16687 diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 58d92aa..412d573 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -72,6 +72,18 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix) } } +static bool cmLibDirsLinked(std::string const& l, std::string const& r) +{ + // Compare the real paths of the two directories. + // Since our caller only changed the trailing component of each + // directory, the real paths can be the same only if at least one of + // the trailing components is a symlink. Use this as an optimization + // to avoid excessive realpath calls. + return (cmSystemTools::FileIsSymlink(l) || + cmSystemTools::FileIsSymlink(r)) && + cmSystemTools::GetRealPath(l) == cmSystemTools::GetRealPath(r); +} + void cmFindLibraryCommand::AddArchitecturePath( std::string const& dir, std::string::size_type start_pos, const char* suffix, bool fresh) @@ -87,6 +99,11 @@ void cmFindLibraryCommand::AddArchitecturePath( std::string libX = lib + suffix; bool use_libX = cmSystemTools::FileIsDirectory(libX); + // Avoid copies of the same directory due to symlinks. + if (use_libX && use_lib && cmLibDirsLinked(libX, lib)) { + use_libX = false; + } + if (use_libX) { libX += dir.substr(pos + 3); std::string::size_type libX_pos = pos + 3 + strlen(suffix) + 1; @@ -106,6 +123,11 @@ void cmFindLibraryCommand::AddArchitecturePath( std::string dirX = dir + suffix; bool use_dirX = cmSystemTools::FileIsDirectory(dirX); + // Avoid copies of the same directory due to symlinks. + if (use_dirX && use_dir && cmLibDirsLinked(dirX, dir)) { + use_dirX = false; + } + if (use_dirX) { dirX += "/"; this->SearchPaths.push_back(dirX); diff --git a/Tests/RunCMake/find_library/LibArchLink-stderr.txt b/Tests/RunCMake/find_library/LibArchLink-stderr.txt new file mode 100644 index 0000000..139e077 --- /dev/null +++ b/Tests/RunCMake/find_library/LibArchLink-stderr.txt @@ -0,0 +1,2 @@ +TOP_LIBRARY='[^']*/Tests/RunCMake/find_library/LibArchLink-build/lib/libtop.a' +SUB_LIBRARY='[^']*/Tests/RunCMake/find_library/LibArchLink-build/lib/sub/libsub.a' diff --git a/Tests/RunCMake/find_library/LibArchLink.cmake b/Tests/RunCMake/find_library/LibArchLink.cmake new file mode 100644 index 0000000..c91381d --- /dev/null +++ b/Tests/RunCMake/find_library/LibArchLink.cmake @@ -0,0 +1,24 @@ +set(CMAKE_SIZEOF_VOID_P 4) +set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS ON) +list(APPEND CMAKE_FIND_LIBRARY_PREFIXES lib) +list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .a) + +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink lib ${CMAKE_CURRENT_BINARY_DIR}/lib32) +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lib/libtop.a" "top") +find_library(TOP_LIBRARY + NAMES top + PATHS ${CMAKE_CURRENT_BINARY_DIR}/lib + NO_DEFAULT_PATH + ) +message("TOP_LIBRARY='${TOP_LIBRARY}'") + +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib/sub) +execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink . ${CMAKE_CURRENT_BINARY_DIR}/lib/sub/32) +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lib/sub/libsub.a" "sub") +find_library(SUB_LIBRARY + NAMES sub + PATHS ${CMAKE_CURRENT_BINARY_DIR}/lib/sub + NO_DEFAULT_PATH + ) +message("SUB_LIBRARY='${SUB_LIBRARY}'") diff --git a/Tests/RunCMake/find_library/RunCMakeTest.cmake b/Tests/RunCMake/find_library/RunCMakeTest.cmake index 5733965..e7e8db3 100644 --- a/Tests/RunCMake/find_library/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_library/RunCMakeTest.cmake @@ -1,6 +1,9 @@ include(RunCMake) run_cmake(Created) +if(CMAKE_HOST_UNIX) + run_cmake(LibArchLink) +endif() if(WIN32 OR CYGWIN) run_cmake(PrefixInPATH) endif() https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e67963ed7316768bf0ebfbe42137d028c0d1d2a4 commit e67963ed7316768bf0ebfbe42137d028c0d1d2a4 Author: Brad King <brad.k...@kitware.com> AuthorDate: Tue Feb 28 11:30:14 2017 -0500 Commit: Brad King <brad.k...@kitware.com> CommitDate: Tue Feb 28 14:56:13 2017 -0500 cmFindLibraryCommand: Refactor AddArchitecturePath logic Use boolean variables to save results and rename variables to more closely represent their roles. diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 082350f..58d92aa 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -77,31 +77,41 @@ void cmFindLibraryCommand::AddArchitecturePath( bool fresh) { std::string::size_type pos = dir.find("lib/", start_pos); + if (pos != std::string::npos) { - std::string cur_dir = dir.substr(0, pos + 3); - - // Follow "lib<suffix>". - std::string next_dir = cur_dir + suffix; - if (cmSystemTools::FileIsDirectory(next_dir)) { - next_dir += dir.substr(pos + 3); - std::string::size_type next_pos = pos + 3 + strlen(suffix) + 1; - this->AddArchitecturePath(next_dir, next_pos, suffix); + // Check for "lib". + std::string lib = dir.substr(0, pos + 3); + bool use_lib = cmSystemTools::FileIsDirectory(lib); + + // Check for "lib<suffix>" and use it first. + std::string libX = lib + suffix; + bool use_libX = cmSystemTools::FileIsDirectory(libX); + + if (use_libX) { + libX += dir.substr(pos + 3); + std::string::size_type libX_pos = pos + 3 + strlen(suffix) + 1; + this->AddArchitecturePath(libX, libX_pos, suffix); } - // Follow "lib". - if (cmSystemTools::FileIsDirectory(cur_dir)) { + if (use_lib) { this->AddArchitecturePath(dir, pos + 3 + 1, suffix, false); } } + if (fresh) { - // Check for <dir><suffix>/. - std::string cur_dir = dir + suffix + "/"; - if (cmSystemTools::FileIsDirectory(cur_dir)) { - this->SearchPaths.push_back(cur_dir); + // Check for the original unchanged path. + bool use_dir = cmSystemTools::FileIsDirectory(dir); + + // Check for <dir><suffix>/ and use it first. + std::string dirX = dir + suffix; + bool use_dirX = cmSystemTools::FileIsDirectory(dirX); + + if (use_dirX) { + dirX += "/"; + this->SearchPaths.push_back(dirX); } - // Now add the original unchanged path - if (cmSystemTools::FileIsDirectory(dir)) { + if (use_dir) { this->SearchPaths.push_back(dir); } } ----------------------------------------------------------------------- Summary of changes: Source/cmFindLibraryCommand.cxx | 64 +++++++++++++++----- Tests/RunCMake/find_library/LibArchLink-stderr.txt | 2 + Tests/RunCMake/find_library/LibArchLink.cmake | 24 ++++++++ Tests/RunCMake/find_library/RunCMakeTest.cmake | 3 + 4 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 Tests/RunCMake/find_library/LibArchLink-stderr.txt create mode 100644 Tests/RunCMake/find_library/LibArchLink.cmake hooks/post-receive -- CMake _______________________________________________ Cmake-commits mailing list Cmake-commits@cmake.org http://public.kitware.com/mailman/listinfo/cmake-commits