Inspired by commit 896ad25 for bug #11260, this commit allows to use the variable CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX to be used as find path. Allowing the find path to be more deterministic on custom setups.
A similar idea has already been suggested in #10287 and is required for bug #15994. v2: - Change path variable a string to be specified as suffix directly. - Make path variable non-global - Fix find_library test - strip FindPackage, as testing is ambigous in such scenario --- Help/command/find_library.rst | 6 +++++ Source/cmFindLibraryCommand.cxx | 28 ++++++++++++---------- Tests/CMakeOnly/find_library/CMakeLists.txt | 15 +++++++++++- .../CMakeOnly/find_library/lib/A/libXYZ/libtest2.a | 0 Tests/CMakeOnly/find_library/lib/XYZ/libtest1.a | 0 .../CMakeOnly/find_library/libXYZ/A/lib/libtest4.a | 0 .../find_library/libXYZ/A/libXYZ/libtest5.a | 0 Tests/CMakeOnly/find_library/libXYZ/A/libtest6.a | 0 Tests/CMakeOnly/find_library/libXYZ/libtest7.a | 0 9 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 Tests/CMakeOnly/find_library/lib/A/libXYZ/libtest2.a create mode 100644 Tests/CMakeOnly/find_library/lib/XYZ/libtest1.a create mode 100644 Tests/CMakeOnly/find_library/libXYZ/A/lib/libtest4.a create mode 100644 Tests/CMakeOnly/find_library/libXYZ/A/libXYZ/libtest5.a create mode 100644 Tests/CMakeOnly/find_library/libXYZ/A/libtest6.a create mode 100644 Tests/CMakeOnly/find_library/libXYZ/libtest7.a diff --git a/Help/command/find_library.rst b/Help/command/find_library.rst index 1eb50f7..d6c0e8a 100644 --- a/Help/command/find_library.rst +++ b/Help/command/find_library.rst @@ -49,6 +49,12 @@ path to the framework ``<fullPath>/A.framework``. When a full path to a framework is used as a library, CMake will use a ``-framework A``, and a ``-F<fullPath>`` to link the framework to the target. +If the property `CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX` is set all search +paths will be tested as normal, with the suffix appended, and with all matches +of ``lib/`` replaced with `lib${CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX}/`. +This property overrides both `FIND_LIBRARY_USE_LIB32_PATHS` and +`FIND_LIBRARY_USE_LIB64_PATHS`. + If the :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` global property is set all search paths will be tested as normal, with ``32/`` appended, and with all matches of ``lib/`` replaced with ``lib32/``. This property is diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 082350f..50ee3ae 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -31,20 +31,22 @@ bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn, return true; } - if (this->Makefile->GetState()->GetGlobalPropertyAsBool( - "FIND_LIBRARY_USE_LIB32_PATHS")) { - // add special 32 bit paths if this is a 32 bit compile. - if (this->Makefile->PlatformIs32Bit()) { - this->AddArchitecturePaths("32"); - } + // add custom lib<qual> paths instead of using fixed lib32 or lib64 + if (this->Makefile->GetDefinition("CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX")) { + this->AddArchitecturePaths( + this->Makefile->GetDefinition("CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX")); } - - if (this->Makefile->GetState()->GetGlobalPropertyAsBool( - "FIND_LIBRARY_USE_LIB64_PATHS")) { - // add special 64 bit paths if this is a 64 bit compile. - if (this->Makefile->PlatformIs64Bit()) { - this->AddArchitecturePaths("64"); - } + // add special 32 bit paths if this is a 32 bit compile. + else if (this->Makefile->PlatformIs32Bit() && + this->Makefile->GetState()->GetGlobalPropertyAsBool( + "FIND_LIBRARY_USE_LIB32_PATHS")) { + this->AddArchitecturePaths("32"); + } + // add special 64 bit paths if this is a 64 bit compile. + else if (this->Makefile->PlatformIs64Bit() && + this->Makefile->GetState()->GetGlobalPropertyAsBool( + "FIND_LIBRARY_USE_LIB64_PATHS")) { + this->AddArchitecturePaths("64"); } std::string library = this->FindLibrary(); diff --git a/Tests/CMakeOnly/find_library/CMakeLists.txt b/Tests/CMakeOnly/find_library/CMakeLists.txt index 9958650..9c1aad8 100644 --- a/Tests/CMakeOnly/find_library/CMakeLists.txt +++ b/Tests/CMakeOnly/find_library/CMakeLists.txt @@ -24,7 +24,7 @@ endmacro() macro(test_find_library_subst expected) get_filename_component(dir ${expected} PATH) get_filename_component(name ${expected} NAME) - string(REGEX REPLACE "lib/?64" "lib" dir "${dir}") + string(REGEX REPLACE "lib/?[36X][24Y][Z]*" "lib" dir "${dir}") test_find_library(", searched as ${dir}" "${expected}" NAMES ${name} PATHS ${CMAKE_CURRENT_SOURCE_DIR}/${dir} @@ -79,3 +79,16 @@ test_find_library("" A/libtestA.a NAMES testB testA NAMES_PER_DIR PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A ${CMAKE_CURRENT_SOURCE_DIR}/B ) + +set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX "XYZ") +foreach(libXYZ + lib/XYZ/libtest1.a + lib/A/libXYZ/libtest2.a + lib/libtest3.a + libXYZ/A/lib/libtest4.a + libXYZ/A/libXYZ/libtest5.a + libXYZ/A/libtest6.a + libXYZ/libtest7.a + ) + test_find_library_subst(${libXYZ}) +endforeach() diff --git a/Tests/CMakeOnly/find_library/lib/A/libXYZ/libtest2.a b/Tests/CMakeOnly/find_library/lib/A/libXYZ/libtest2.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/lib/XYZ/libtest1.a b/Tests/CMakeOnly/find_library/lib/XYZ/libtest1.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/libXYZ/A/lib/libtest4.a b/Tests/CMakeOnly/find_library/libXYZ/A/lib/libtest4.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/libXYZ/A/libXYZ/libtest5.a b/Tests/CMakeOnly/find_library/libXYZ/A/libXYZ/libtest5.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/libXYZ/A/libtest6.a b/Tests/CMakeOnly/find_library/libXYZ/A/libtest6.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/libXYZ/libtest7.a b/Tests/CMakeOnly/find_library/libXYZ/libtest7.a new file mode 100644 index 0000000..e69de29 -- 2.10.2 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers