@@ -, +, @@ - CMAKE_PLATFORM_DEBIAN_PATH ("/etc/debian_version") - CMAKE_PLATFORM_ARCHLINUX_PATH ("/etc/arch-release") --- Modules/Platform/Platform.cmake | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Modules/Platform/Platform.cmake --- a/Modules/Platform/Platform.cmake +++ a/Modules/Platform/Platform.cmake @@ -0,0 +1,48 @@ +set(CMAKE_PLATFORM_DEBIAN_PATH "/etc/debian_version") +set(CMAKE_PLATFORM_ARCHLINUX_PATH "/etc/arch-release") + +option (CMAKE_PLATFORM_DISABLE_DETECTION "Do not check for platform." OFF) + +if(CMAKE_PLATFORM_DISABLE_DETECTION) + set(CMAKE_PLATFORM_DEBIAN_FOUND 0 CACHE INTERNAL + "Debian platform detected via ${CMAKE_PLATFORM_DEBIAN_PATH}") + set(CMAKE_PLATFORM_ARCHLINUX_FOUND 0 CACHE INTERNAL + "Arch Linux platform detected via ${CMAKE_PLATFORM_ARCHLINUX_PATH}") +else() + if(EXISTS "${CMAKE_PLATFORM_DEBIAN_PATH}") + set(CMAKE_PLATFORM_DEBIAN_FOUND 1 CACHE INTERNAL + "Debian platform detected via ${CMAKE_PLATFORM_DEBIAN_PATH}") + endif() + + if(EXISTS "${CMAKE_PLATFORM_ARCHLINUX_PATH}") + set(CMAKE_PLATFORM_ARCHLINUX_FOUND 1 CACHE INTERNAL + "Arch Linux platform detected via ${CMAKE_PLATFORM_ARCHLINUX_PATH}") + endif() +endif() + +# Debian policy requires that shared libraries be installed without +# executable permission. Fedora policy requires that shared libraries +# be installed with the executable permission. Since the native tools +# create shared libraries with execute permission in the first place a +# reasonable policy seems to be to install with execute permission by +# default. In order to support debian packages we provide an option +# here. The option default is based on the current distribution, but +# packagers can set it explicitly on the command line. +if(DEFINED CMAKE_INSTALL_SO_NO_EXE) + # Store the decision variable in the cache. This preserves any + # setting the user provides on the command line. + set(CMAKE_INSTALL_SO_NO_EXE "${CMAKE_INSTALL_SO_NO_EXE}" CACHE INTERNAL + "Install .so files without execute permission.") +else() + # Store the decision variable as an internal cache entry to avoid + # checking the platform every time. This option is advanced enough + # that only package maintainers should need to adjust it. They are + # capable of providing a setting on the command line. + if(CMAKE_PLATFORM_DEBIAN_FOUND) + set(CMAKE_INSTALL_SO_NO_EXE 1 CACHE INTERNAL + "Install .so files without execute permission.") + else() + set(CMAKE_INSTALL_SO_NO_EXE 0 CACHE INTERNAL + "Install .so files without execute permission.") + endif() +endif() -- Platform.cmake --- Modules/Platform/GNU.cmake | 28 +--------------------------- Modules/Platform/Linux.cmake | 28 +--------------------------- 2 files changed, 2 insertions(+), 54 deletions(-) --- a/Modules/Platform/GNU.cmake +++ a/Modules/Platform/GNU.cmake @@ -8,33 +8,7 @@ set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,") set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,") set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic") -# Debian policy requires that shared libraries be installed without -# executable permission. Fedora policy requires that shared libraries -# be installed with the executable permission. Since the native tools -# create shared libraries with execute permission in the first place a -# reasonable policy seems to be to install with execute permission by -# default. In order to support debian packages we provide an option -# here. The option default is based on the current distribution, but -# packagers can set it explicitly on the command line. -if(DEFINED CMAKE_INSTALL_SO_NO_EXE) - # Store the decision variable in the cache. This preserves any - # setting the user provides on the command line. - set(CMAKE_INSTALL_SO_NO_EXE "${CMAKE_INSTALL_SO_NO_EXE}" CACHE INTERNAL - "Install .so files without execute permission.") -else() - # Store the decision variable as an internal cache entry to avoid - # checking the platform every time. This option is advanced enough - # that only package maintainers should need to adjust it. They are - # capable of providing a setting on the command line. - if(EXISTS "/etc/debian_version") - set(CMAKE_INSTALL_SO_NO_EXE 1 CACHE INTERNAL - "Install .so files without execute permission.") - else() - set(CMAKE_INSTALL_SO_NO_EXE 0 CACHE INTERNAL - "Install .so files without execute permission.") - endif() -endif() - set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-gnu[a-z0-9_]*") +include(Platform/Platform) include(Platform/UnixPaths) --- a/Modules/Platform/Linux.cmake +++ a/Modules/Platform/Linux.cmake @@ -19,36 +19,10 @@ foreach(type SHARED_LIBRARY SHARED_MODULE EXE) set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic") endforeach() -# Debian policy requires that shared libraries be installed without -# executable permission. Fedora policy requires that shared libraries -# be installed with the executable permission. Since the native tools -# create shared libraries with execute permission in the first place a -# reasonable policy seems to be to install with execute permission by -# default. In order to support debian packages we provide an option -# here. The option default is based on the current distribution, but -# packagers can set it explicitly on the command line. -if(DEFINED CMAKE_INSTALL_SO_NO_EXE) - # Store the decision variable in the cache. This preserves any - # setting the user provides on the command line. - set(CMAKE_INSTALL_SO_NO_EXE "${CMAKE_INSTALL_SO_NO_EXE}" CACHE INTERNAL - "Install .so files without execute permission.") -else() - # Store the decision variable as an internal cache entry to avoid - # checking the platform every time. This option is advanced enough - # that only package maintainers should need to adjust it. They are - # capable of providing a setting on the command line. - if(EXISTS "/etc/debian_version") - set(CMAKE_INSTALL_SO_NO_EXE 1 CACHE INTERNAL - "Install .so files without execute permission.") - else() - set(CMAKE_INSTALL_SO_NO_EXE 0 CACHE INTERNAL - "Install .so files without execute permission.") - endif() -endif() - # Match multiarch library directory names. set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_]*") +include(Platform/Platform) include(Platform/UnixPaths) # Debian has lib32 and lib64 paths only for compatibility so they should not be -- Platform.cmake --- Modules/CMakeFindPackageMode.cmake | 3 ++- Modules/FindPkgConfig.cmake | 4 +++- Modules/GNUInstallDirs.cmake | 6 ++++-- Modules/Platform/Linux.cmake | 2 +- .../FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake | 2 +- ...PkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake | 2 +- .../FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) --- a/Modules/CMakeFindPackageMode.cmake +++ a/Modules/CMakeFindPackageMode.cmake @@ -73,6 +73,7 @@ include(CMakeSystemSpecificInitialize) include(CMakeSystemSpecificInformation) if(UNIX) + include(Platform/Platform) # try to guess whether we have a 64bit system, if it has not been set # from the outside @@ -94,7 +95,7 @@ if(UNIX) endif() # guess Debian multiarch if it has not been set: - if(EXISTS /etc/debian_version) + if(CMAKE_PLATFORM_DEBIAN_FOUND) if(NOT CMAKE_${LANGUAGE}_LIBRARY_ARCHITECTURE ) file(GLOB filesInLib RELATIVE /lib /lib/*-linux-gnu* ) foreach(file ${filesInLib}) --- a/Modules/FindPkgConfig.cmake +++ a/Modules/FindPkgConfig.cmake @@ -55,6 +55,8 @@ if (PKG_CONFIG_EXECUTABLE) unset(_PKG_CONFIG_VERSION_RESULT) endif () +include(Platform/Platform) + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(PkgConfig REQUIRED_VARS PKG_CONFIG_EXECUTABLE @@ -323,7 +325,7 @@ macro(_pkg_set_path_internal) 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 ? + if(CMAKE_PLATFORM_DEBIAN_FOUND) # is this a debian system ? if(CMAKE_LIBRARY_ARCHITECTURE) list(APPEND _lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig") endif() --- a/Modules/GNUInstallDirs.cmake +++ a/Modules/GNUInstallDirs.cmake @@ -127,6 +127,8 @@ Macros cmake_policy(PUSH) cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced +include(Platform/Platform) + # Convert a cache variable to PATH type macro(_GNUInstallDirs_cache_convert_to_path var description) @@ -228,8 +230,8 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set endif() if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$" AND NOT CMAKE_CROSSCOMPILING - AND NOT EXISTS "/etc/arch-release") - if (EXISTS "/etc/debian_version") # is this a debian system ? + AND NOT CMAKE_PLATFORM_ARCHLINUX_FOUND) + if (CMAKE_PLATFORM_DEBIAN_FOUND) # is this a debian system ? if(CMAKE_LIBRARY_ARCHITECTURE) if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$") set(_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}") --- a/Modules/Platform/Linux.cmake +++ a/Modules/Platform/Linux.cmake @@ -27,7 +27,7 @@ include(Platform/UnixPaths) # Debian has lib32 and lib64 paths only for compatibility so they should not be # searched. -if(NOT CMAKE_CROSSCOMPILING AND EXISTS "/etc/debian_version") +if(NOT CMAKE_CROSSCOMPILING AND CMAKE_PLATFORM_DEBIAN_FOUND) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS FALSE) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE) endif() --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake +++ a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake @@ -21,7 +21,7 @@ find_package(PkgConfig) 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 ? + if(CMAKE_PLATFORM_DEBIAN_FOUND) # is this a debian system ? if(CMAKE_LIBRARY_ARCHITECTURE MATCHES "^(i386-linux-gnu|x86_64-linux-gnu)$") # Cannot create directories for all the existing architectures... set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake +++ a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_ENVIRONMENT_PATH.cmake @@ -21,7 +21,7 @@ find_package(PkgConfig) 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 ? + if(CMAKE_PLATFORM_DEBIAN_FOUND) # is this a debian system ? if(CMAKE_LIBRARY_ARCHITECTURE MATCHES "^(i386-linux-gnu|x86_64-linux-gnu)$") # Cannot create directories for all the existing architectures... set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig") --- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake +++ a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH_NO_CMAKE_PATH.cmake @@ -21,7 +21,7 @@ find_package(PkgConfig) 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 ? + if(CMAKE_PLATFORM_DEBIAN_FOUND) # is this a debian system ? if(CMAKE_LIBRARY_ARCHITECTURE MATCHES "^(i386-linux-gnu|x86_64-linux-gnu)$") # Cannot create directories for all the existing architectures... set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig") --