Merge topic 'find-lib32'

896ad251 Teach find_library and find_package to search lib32 paths (#11260)
This commit is contained in:
Brad King 2016-06-13 09:54:17 -04:00 committed by CMake Topic Stage
commit 941fbe31f5
28 changed files with 110 additions and 27 deletions

View File

@ -49,6 +49,13 @@ 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_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
automatically set for the platforms that are known to need it if at
least one of the languages supported by the :command:`project` command
is enabled.
If the :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` global property is set
all search paths will be tested as normal, with ``64/`` appended, and
with all matches of ``lib/`` replaced with ``lib64/``. This property is

View File

@ -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_LIB32_PATHS
/prop_gbl/FIND_LIBRARY_USE_LIB64_PATHS
/prop_gbl/FIND_LIBRARY_USE_OPENBSD_VERSIONING
/prop_gbl/GLOBAL_DEPENDS_DEBUG_MODE

View File

@ -0,0 +1,10 @@
FIND_LIBRARY_USE_LIB32_PATHS
----------------------------
Whether the :command:`find_library` command should automatically search
``lib32`` directories.
``FIND_LIBRARY_USE_LIB32_PATHS`` is a boolean specifying whether the
:command:`find_library` command should automatically search the ``lib32``
variant of directories called ``lib`` in the search path when building 32-bit
binaries.

View File

@ -0,0 +1,7 @@
find-lib32
----------
* The :command:`find_library` and :command:`find_package` commands learned
to search in ``lib32/`` directories when the build targets a 32-bit
architecture. See the :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` global
property.

View File

@ -316,9 +316,13 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
list(APPEND _lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig")
endif()
else()
# not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
# not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties
get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
list(APPEND _lib_dirs "lib32/pkgconfig")
endif()
get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if(uselib64)
if(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND _lib_dirs "lib64/pkgconfig")
endif()
endif()

View File

@ -50,8 +50,9 @@ set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_
include(Platform/UnixPaths)
# Debian has lib64 paths only for compatibility so they should not be
# Debian has lib32 and lib64 paths only for compatibility so they should not be
# searched.
if(NOT CMAKE_CROSSCOMPILING AND EXISTS "/etc/debian_version")
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS FALSE)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
endif()

View File

@ -18,6 +18,7 @@ endif()
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_OPENBSD_VERSIONING 1)
# OpenBSD has no multilib
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS FALSE)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
# OpenBSD policy requires that shared libraries be installed without

View File

@ -93,5 +93,6 @@ list(APPEND CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
/usr/include
)
# Enable use of lib64 search path variants by default.
# Enable use of lib32 and lib64 search path variants by default.
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)

View File

@ -40,11 +40,10 @@ bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn,
return true;
}
if (const char* abi_name =
this->Makefile->GetDefinition("CMAKE_INTERNAL_PLATFORM_ABI")) {
std::string abi = abi_name;
if (abi.find("ELF N32") != abi.npos) {
// Convert lib to lib32.
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");
}
}

View File

@ -43,6 +43,7 @@ cmFindPackageCommand::cmFindPackageCommand()
this->UseConfigFiles = true;
this->UseFindModules = true;
this->DebugMode = false;
this->UseLib32Paths = false;
this->UseLib64Paths = false;
this->PolicyScope = true;
this->VersionMajor = 0;
@ -110,6 +111,13 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
this->LibraryArchitecture = arch;
}
// Lookup whether lib32 paths should be used.
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(
@ -1907,6 +1915,9 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
if (!this->LibraryArchitecture.empty()) {
common.push_back("lib/" + this->LibraryArchitecture);
}
if (this->UseLib32Paths) {
common.push_back("lib32");
}
if (this->UseLib64Paths) {
common.push_back("lib64");
}

View File

@ -148,6 +148,7 @@ private:
bool NoUserRegistry;
bool NoSystemRegistry;
bool DebugMode;
bool UseLib32Paths;
bool UseLib64Paths;
bool PolicyScope;
std::string LibraryArchitecture;

View File

@ -2076,6 +2076,14 @@ bool cmMakefile::IsSet(const std::string& name) const
return true;
}
bool cmMakefile::PlatformIs32Bit() const
{
if (const char* sizeof_dptr = this->GetDefinition("CMAKE_SIZEOF_VOID_P")) {
return atoi(sizeof_dptr) == 4;
}
return false;
}
bool cmMakefile::PlatformIs64Bit() const
{
if (const char* sizeof_dptr = this->GetDefinition("CMAKE_SIZEOF_VOID_P")) {

View File

@ -437,6 +437,9 @@ public:
bool IsOn(const std::string& name) const;
bool IsSet(const std::string& name) const;
/** Return whether the target platform is 32-bit. */
bool PlatformIs32Bit() const;
/** Return whether the target platform is 64-bit. */
bool PlatformIs64Bit() const;

View File

@ -33,16 +33,23 @@ endmacro()
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
set(CMAKE_SIZEOF_VOID_P 4)
foreach(lib
lib/32/libtest5.a
lib/A/lib/libtest1.a
lib/A/lib32/libtest3.a
lib/A/libtest1.a
lib/libtest1.a
lib/libtest2.a
lib/libtest3.a
lib/libtest3.a
lib32/A/lib/libtest2.a
lib32/A/lib32/libtest4.a
lib32/A/libtest4.a
lib32/libtest4.a
)
test_find_library_subst(${lib})
endforeach()

View File

@ -1,4 +1,4 @@
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS
enable_language(C)
# Prepare environment and variables
@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
endif()
else()
# not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
# not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties
get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if(uselib64)
if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
else()
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
endif()
endif()
else()

View File

@ -1,4 +1,4 @@
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS
enable_language(C)
# Prepare environment and variables
@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
endif()
else()
# not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
# not debian, check the FIND_LIBRARY_USE_LIB64_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties
get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if(uselib64)
if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
else()
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
endif()
endif()
else()

View File

@ -1,6 +1,3 @@
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
enable_language(C)
# Prepare environment and variables
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH FALSE)
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pc-foo")

View File

@ -1,4 +1,4 @@
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS
enable_language(C)
# Prepare environment and variables
@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
endif()
else()
# not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
# not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS propertie
get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if(uselib64)
if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
else()
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
endif()
endif()
else()

View File

@ -1,4 +1,4 @@
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS
enable_language(C)
# Prepare environment and variables
@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig")
endif()
else()
# not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
# not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties
get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if(uselib64)
if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig")
elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig")
else()
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig")
endif()
endif()
else()

View File

@ -1,4 +1,4 @@
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE and FIND_LIBRARY_USE_LIB64_PATHS
# Needed for CMAKE_SYSTEM_NAME, CMAKE_LIBRARY_ARCHITECTURE, FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS
enable_language(C)
# Prepare environment and variables
@ -29,10 +29,15 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
endif()
else()
# not debian, chech the FIND_LIBRARY_USE_LIB64_PATHS property
# not debian, check the FIND_LIBRARY_USE_LIB64_PATHS and FIND_LIBRARY_USE_LIB32_PATHS properties
get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if(uselib64)
if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib32/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
elseif(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib64/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
else()
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
endif()
endif()
else()