Linux.cmake 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # GCC is the default compiler on Linux.
  2. SET(CMAKE_DL_LIBS "dl")
  3. SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
  4. SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")
  5. SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-rdynamic")
  6. SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
  7. SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
  8. SET(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
  9. SET(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-Wl,-soname,")
  10. SET(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-Wl,-soname,")
  11. SET(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
  12. SET(CMAKE_EXE_EXPORTS_CXX_FLAG "-Wl,--export-dynamic")
  13. # Initialize C link type selection flags. These flags are used when
  14. # building a shared library, shared module, or executable that links
  15. # to other libraries to select whether to use the static or shared
  16. # versions of the libraries.
  17. FOREACH(type SHARED_LIBRARY SHARED_MODULE EXE)
  18. SET(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Wl,-Bstatic")
  19. SET(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
  20. ENDFOREACH(type)
  21. # Debian policy requires that shared libraries be installed without
  22. # executable permission. Fedora policy requires that shared libraries
  23. # be installed with the executable permission. Since the native tools
  24. # create shared libraries with execute permission in the first place a
  25. # reasonable policy seems to be to install with execute permission by
  26. # default. In order to support debian packages we provide an option
  27. # here. The option default is based on the current distribution, but
  28. # packagers can set it explicitly on the command line.
  29. IF(DEFINED CMAKE_INSTALL_SO_NO_EXE)
  30. # Store the decision variable in the cache. This preserves any
  31. # setting the user provides on the command line.
  32. SET(CMAKE_INSTALL_SO_NO_EXE "${CMAKE_INSTALL_SO_NO_EXE}" CACHE INTERNAL
  33. "Install .so files without execute permission.")
  34. ELSE(DEFINED CMAKE_INSTALL_SO_NO_EXE)
  35. # Detect the linux distribution.
  36. SET(CMAKE_LINUX_DISTRO)
  37. IF(EXISTS "/proc/version")
  38. FILE(READ "/proc/version" CMAKE_LINUX_DISTRO)
  39. ENDIF(EXISTS "/proc/version")
  40. # List the distributions that require shared libraries to not have
  41. # execute permission.
  42. SET(CMAKE_INSTALL_SO_NO_EXE_DISTRO "(Debian|Ubuntu)")
  43. # Store the decision variable as an internal cache entry to avoid
  44. # checking the platform every time. This option is advanced enough
  45. # that only package maintainers should need to adjust it. They are
  46. # capable of providing a setting on the command line.
  47. IF("${CMAKE_LINUX_DISTRO}" MATCHES "${CMAKE_INSTALL_SO_NO_EXE_DISTRO}")
  48. SET(CMAKE_INSTALL_SO_NO_EXE 1 CACHE INTERNAL
  49. "Install .so files without execute permission.")
  50. ELSE("${CMAKE_LINUX_DISTRO}" MATCHES "${CMAKE_INSTALL_SO_NO_EXE_DISTRO}")
  51. SET(CMAKE_INSTALL_SO_NO_EXE 0 CACHE INTERNAL
  52. "Install .so files without execute permission.")
  53. ENDIF("${CMAKE_LINUX_DISTRO}" MATCHES "${CMAKE_INSTALL_SO_NO_EXE_DISTRO}")
  54. ENDIF(DEFINED CMAKE_INSTALL_SO_NO_EXE)
  55. INCLUDE(Platform/UnixPaths)