Linux.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. set(LINUX 1)
  2. set(CMAKE_DL_LIBS "dl")
  3. set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
  4. set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
  5. set(CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN "\$ORIGIN")
  6. set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
  7. set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
  8. set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
  9. # Shared libraries with no builtin soname may not be linked safely by
  10. # specifying the file path.
  11. set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME 1)
  12. # Initialize C link type selection flags. These flags are used when
  13. # building a shared library, shared module, or executable that links
  14. # to other libraries to select whether to use the static or shared
  15. # versions of the libraries.
  16. foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
  17. set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-Bstatic")
  18. set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
  19. endforeach()
  20. # Features for LINK_LIBRARY generator expression
  21. ## check linker capabilities
  22. if(NOT DEFINED _CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
  23. execute_process(COMMAND "${CMAKE_LINKER}" --help
  24. OUTPUT_VARIABLE __linker_help
  25. ERROR_VARIABLE __linker_help)
  26. if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state")
  27. set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED TRUE CACHE INTERNAL "linker supports push/pop state")
  28. else()
  29. set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state")
  30. endif()
  31. unset(__linker_help)
  32. endif()
  33. ## WHOLE_ARCHIVE: Force loading all members of an archive
  34. if(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
  35. set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive"
  36. "<LINK_ITEM>"
  37. "LINKER:--pop-state")
  38. else()
  39. set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive"
  40. "<LINK_ITEM>"
  41. "LINKER:--no-whole-archive")
  42. endif()
  43. set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
  44. # Features for LINK_GROUP generator expression
  45. ## RESCAN: request the linker to rescan static libraries until there is
  46. ## no pending undefined symbols
  47. set(CMAKE_LINK_GROUP_USING_RESCAN "LINKER:--start-group" "LINKER:--end-group")
  48. set(CMAKE_LINK_GROUP_USING_RESCAN_SUPPORTED TRUE)
  49. # Debian policy requires that shared libraries be installed without
  50. # executable permission. Fedora policy requires that shared libraries
  51. # be installed with the executable permission. Since the native tools
  52. # create shared libraries with execute permission in the first place a
  53. # reasonable policy seems to be to install with execute permission by
  54. # default. In order to support debian packages we provide an option
  55. # here. The option default is based on the current distribution, but
  56. # packagers can set it explicitly on the command line.
  57. if(DEFINED CMAKE_INSTALL_SO_NO_EXE)
  58. # Store the decision variable in the cache. This preserves any
  59. # setting the user provides on the command line.
  60. set(CMAKE_INSTALL_SO_NO_EXE "${CMAKE_INSTALL_SO_NO_EXE}" CACHE INTERNAL
  61. "Install .so files without execute permission.")
  62. else()
  63. # Store the decision variable as an internal cache entry to avoid
  64. # checking the platform every time. This option is advanced enough
  65. # that only package maintainers should need to adjust it. They are
  66. # capable of providing a setting on the command line.
  67. if(EXISTS "/etc/debian_version")
  68. set(CMAKE_INSTALL_SO_NO_EXE 1 CACHE INTERNAL
  69. "Install .so files without execute permission.")
  70. else()
  71. set(CMAKE_INSTALL_SO_NO_EXE 0 CACHE INTERNAL
  72. "Install .so files without execute permission.")
  73. endif()
  74. endif()
  75. # Match multiarch library directory names.
  76. set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_]*")
  77. include(Platform/UnixPaths)
  78. # Debian has lib32 and lib64 paths only for compatibility so they should not be
  79. # searched.
  80. if(NOT CMAKE_CROSSCOMPILING AND EXISTS "/etc/debian_version")
  81. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS FALSE)
  82. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
  83. endif()