Linux.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. # Debian policy requires that shared libraries be installed without
  20. # executable permission. Fedora policy requires that shared libraries
  21. # be installed with the executable permission. Since the native tools
  22. # create shared libraries with execute permission in the first place a
  23. # reasonable policy seems to be to install with execute permission by
  24. # default. In order to support debian packages we provide an option
  25. # here. The option default is based on the current distribution, but
  26. # packagers can set it explicitly on the command line.
  27. if(DEFINED CMAKE_INSTALL_SO_NO_EXE)
  28. # Store the decision variable in the cache. This preserves any
  29. # setting the user provides on the command line.
  30. set(CMAKE_INSTALL_SO_NO_EXE "${CMAKE_INSTALL_SO_NO_EXE}" CACHE INTERNAL
  31. "Install .so files without execute permission.")
  32. else()
  33. # Store the decision variable as an internal cache entry to avoid
  34. # checking the platform every time. This option is advanced enough
  35. # that only package maintainers should need to adjust it. They are
  36. # capable of providing a setting on the command line.
  37. if(EXISTS "/etc/debian_version")
  38. set(CMAKE_INSTALL_SO_NO_EXE 1 CACHE INTERNAL
  39. "Install .so files without execute permission.")
  40. else()
  41. set(CMAKE_INSTALL_SO_NO_EXE 0 CACHE INTERNAL
  42. "Install .so files without execute permission.")
  43. endif()
  44. endif()
  45. # Match multiarch library directory names.
  46. set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_]*")
  47. include(Platform/UnixPaths)
  48. # Debian has lib32 and lib64 paths only for compatibility so they should not be
  49. # searched.
  50. if(NOT CMAKE_CROSSCOMPILING AND EXISTS "/etc/debian_version")
  51. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS FALSE)
  52. set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
  53. endif()