Linux.cmake 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. set(CMAKE_DL_LIBS "dl")
  2. set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
  3. set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
  4. set(CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN "\$ORIGIN")
  5. set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
  6. set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
  7. set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
  8. # Shared libraries with no builtin soname may not be linked safely by
  9. # specifying the file path.
  10. set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME 1)
  11. # Initialize C link type selection flags. These flags are used when
  12. # building a shared library, shared module, or executable that links
  13. # to other libraries to select whether to use the static or shared
  14. # versions of the libraries.
  15. foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
  16. set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-Bstatic")
  17. set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
  18. endforeach()
  19. # Features for LINK_LIBRARY generator expression
  20. ## check linker capabilities
  21. if(NOT DEFINED _CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
  22. execute_process(COMMAND "${CMAKE_LINKER}" --help
  23. OUTPUT_VARIABLE __linker_help
  24. ERROR_VARIABLE __linker_help)
  25. if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state")
  26. set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED TRUE CACHE INTERNAL "linker supports push/pop state")
  27. else()
  28. set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state")
  29. endif()
  30. unset(__linker_help)
  31. endif()
  32. ## WHOLE_ARCHIVE: Force loading all members of an archive
  33. if(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
  34. set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive"
  35. "<LINK_ITEM>"
  36. "LINKER:--pop-state")
  37. else()
  38. set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive"
  39. "<LINK_ITEM>"
  40. "LINKER:--no-whole-archive")
  41. endif()
  42. set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
  43. set(CMAKE_LINK_LIBRARY_WHOLE_ARCHIVE_PROPERTIES LIBRARY_TYPE=STATIC UNICITY=YES OVERRIDE=DEFAULT)
  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. include(Platform/UnixPaths)
  76. # Debian has lib32 and lib64 paths only for compatibility so they should not be
  77. # searched.
  78. if(NOT CMAKE_CROSSCOMPILING)
  79. if (EXISTS "/etc/debian_version")
  80. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS FALSE)
  81. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
  82. endif()
  83. if (EXISTS "/etc/arch-release")
  84. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
  85. endif()
  86. endif()