Inspired by commit 896ad25 for bug #11260, this commit allows to use the variable LIB_SUFFIX to be used as find path as well. 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 #15594. --- Help/command/find_library.rst | 5 ++++ Help/manual/cmake-properties.7.rst | 1 + Modules/FindPkgConfig.cmake | 5 +++- Source/cmFindLibraryCommand.cxx | 27 ++++++++++-------- Source/cmFindPackageCommand.cxx | 32 +++++++++++++++------- Source/cmFindPackageCommand.h | 1 + Tests/CMakeOnly/find_library/CMakeLists.txt | 14 ++++++++++ .../CMakeOnly/find_library/lib/A/libXYZ/libtest3.a | 0 Tests/CMakeOnly/find_library/lib/XYZ/libtest2.a | 0 .../CMakeOnly/find_library/libXYZ/A/lib/libtest2.a | 0 .../find_library/libXYZ/A/libXYZ/libtest1.a | 0 Tests/CMakeOnly/find_library/libXYZ/A/libtest1.a | 0 Tests/CMakeOnly/find_library/libXYZ/libtest1.a | 0 13 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 Tests/CMakeOnly/find_library/lib/A/libXYZ/libtest3.a create mode 100644 Tests/CMakeOnly/find_library/lib/XYZ/libtest2.a create mode 100644 Tests/CMakeOnly/find_library/libXYZ/A/lib/libtest2.a create mode 100644 Tests/CMakeOnly/find_library/libXYZ/A/libXYZ/libtest1.a create mode 100644 Tests/CMakeOnly/find_library/libXYZ/A/libtest1.a create mode 100644 Tests/CMakeOnly/find_library/libXYZ/libtest1.a diff --git a/Help/command/find_library.rst b/Help/command/find_library.rst index 1eb50f7..66eb401 100644 --- a/Help/command/find_library.rst +++ b/Help/command/find_library.rst @@ -49,6 +49,11 @@ 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 :prop_gbl:`FIND_LIBRARY_USE_CUSTOM_SUFFIX` global property is set +all search paths will be tested as normal, with `LIB_SUFFIX` appended, and +with all matches of ``lib/`` replaced with `lib${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/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index d16f231..128f180 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -24,6 +24,7 @@ Properties of Global Scope /prop_gbl/DISABLED_FEATURES /prop_gbl/ENABLED_FEATURES /prop_gbl/ENABLED_LANGUAGES + /prop_gbl/FIND_LIBRARY_USE_CUSTOM_SUFFIX /prop_gbl/FIND_LIBRARY_USE_LIB32_PATHS /prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS /prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 33290c4..75fbef8 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -311,7 +311,10 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma if(NOT DEFINED CMAKE_SYSTEM_NAME OR (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$" AND NOT CMAKE_CROSSCOMPILING)) - if(EXISTS "/etc/debian_version") # is this a debian system ? + get_property(uselibcustom GLOBAL PROPERTY FIND_LIBRARY_USE_CUSTOM_SUFFIX) + if(uselibcustom) + list(APPEND _lib_dirs "lib${LIB_SUFFIX}/pkgconfig") + elseif(EXISTS "/etc/debian_version") # is this a debian system ? if(CMAKE_LIBRARY_ARCHITECTURE) list(APPEND _lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig") endif() diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 3094fcf..d86137a 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -40,20 +40,23 @@ bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn, return true; } + // add custom lib${LIB_SUFFIX} paths instead of defaults 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"); - } + "FIND_LIBRARY_USE_CUSTOM_SUFFIX") && + this->Makefile->GetDefinition("LIB_SUFFIX")) { + this->AddArchitecturePaths(this->Makefile->GetDefinition("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/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 1a44d73..5dfedb4 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -43,6 +43,7 @@ cmFindPackageCommand::cmFindPackageCommand() this->UseConfigFiles = true; this->UseFindModules = true; this->DebugMode = false; + this->UseLibCustomSuffix = false; this->UseLib32Paths = false; this->UseLib64Paths = false; this->PolicyScope = true; @@ -111,17 +112,22 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, this->LibraryArchitecture = arch; } + // Lookup whether lib${LIB_SUFFIX} paths should be used + if (this->Makefile->GetState()->GetGlobalPropertyAsBool( + "FIND_LIBRARY_USE_CUSTOM_SUFFIX")) { + this->UseLibCustomSuffix = true; + std::cout << "FIND_LIBRARY_USE_CUSTOM_SUFFIX" << std::endl; + } // Lookup whether lib32 paths should be used. - if (this->Makefile->PlatformIs32Bit() && - this->Makefile->GetState()->GetGlobalPropertyAsBool( - "FIND_LIBRARY_USE_LIB32_PATHS")) { + else if (this->Makefile->PlatformIs32Bit() && + this->Makefile->GetState()->GetGlobalPropertyAsBool( + "FIND_LIBRARY_USE_LIB32_PATHS")) { this->UseLib32Paths = true; } - // Lookup whether lib64 paths should be used. - if (this->Makefile->PlatformIs64Bit() && - this->Makefile->GetState()->GetGlobalPropertyAsBool( - "FIND_LIBRARY_USE_LIB64_PATHS")) { + else if (this->Makefile->PlatformIs64Bit() && + this->Makefile->GetState()->GetGlobalPropertyAsBool( + "FIND_LIBRARY_USE_LIB64_PATHS")) { this->UseLib64Paths = true; } @@ -1915,10 +1921,16 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) if (!this->LibraryArchitecture.empty()) { common.push_back("lib/" + this->LibraryArchitecture); } - if (this->UseLib32Paths) { + + if (this->UseLibCustomSuffix && + this->Makefile->GetDefinition("LIB_SUFFIX")) { + std::string custom_lib = "lib"; + custom_lib += this->Makefile->GetDefinition("LIB_SUFFIX"); + common.push_back(custom_lib.c_str()); + std::cout << "UseLibCustomSuffix() - " << custom_lib << std::endl; + } else if (this->UseLib32Paths) { common.push_back("lib32"); - } - if (this->UseLib64Paths) { + } else if (this->UseLib64Paths) { common.push_back("lib64"); } common.push_back("lib"); diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 9019f1b..2cbeedc 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -148,6 +148,7 @@ private: bool NoUserRegistry; bool NoSystemRegistry; bool DebugMode; + bool UseLibCustomSuffix; bool UseLib32Paths; bool UseLib64Paths; bool PolicyScope; diff --git a/Tests/CMakeOnly/find_library/CMakeLists.txt b/Tests/CMakeOnly/find_library/CMakeLists.txt index 9958650..3500887 100644 --- a/Tests/CMakeOnly/find_library/CMakeLists.txt +++ b/Tests/CMakeOnly/find_library/CMakeLists.txt @@ -79,3 +79,17 @@ test_find_library("" A/libtestA.a NAMES testB testA NAMES_PER_DIR PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A ${CMAKE_CURRENT_SOURCE_DIR}/B ) + +set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_CUSTOM_SUFFIX TRUE) +set(LIB_SUFFIX "XYZ") +foreach(libXYZ + lib/XYZ/libtest2.a + lib/A/libXYZ/libtest3.a + lib/libtest3.a + libXYZ/A/lib/libtest2.a + libXYZ/A/libXYZ/libtest1.a + libXYZ/A/libtest1.a + libXYZ/libtest1.a + ) + test_find_library_subst(${libXYZ}) +endforeach() diff --git a/Tests/CMakeOnly/find_library/lib/A/libXYZ/libtest3.a b/Tests/CMakeOnly/find_library/lib/A/libXYZ/libtest3.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/lib/XYZ/libtest2.a b/Tests/CMakeOnly/find_library/lib/XYZ/libtest2.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/libXYZ/A/lib/libtest2.a b/Tests/CMakeOnly/find_library/libXYZ/A/lib/libtest2.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/libXYZ/A/libXYZ/libtest1.a b/Tests/CMakeOnly/find_library/libXYZ/A/libXYZ/libtest1.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/libXYZ/A/libtest1.a b/Tests/CMakeOnly/find_library/libXYZ/A/libtest1.a new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CMakeOnly/find_library/libXYZ/libtest1.a b/Tests/CMakeOnly/find_library/libXYZ/libtest1.a new file mode 100644 index 0000000..e69de29 -- 2.7.3 -- 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