CMakeLists.txt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # CPack Example: User-selectable Installation Components
  2. #
  3. # In this example, we have a simple library (mylib) with an example
  4. # application (mylibapp). We create a binary installer (a CPack Generator)
  5. # which supports CPack components.
  6. cmake_minimum_required(VERSION 2.8.3.20101130 FATAL_ERROR)
  7. project(CPackComponentsDEB)
  8. # Use GNUInstallDirs in order to enforce lib64 if needed
  9. include(GNUInstallDirs)
  10. # Create the mylib library
  11. add_library(mylib mylib.cpp)
  12. # Create the mylibapp application
  13. add_executable(mylibapp mylibapp.cpp)
  14. target_link_libraries(mylibapp mylib)
  15. # Duplicate of mylibapp application
  16. # which won't be put in any component (?mistake?)
  17. add_executable(mylibapp2 mylibapp.cpp)
  18. target_link_libraries(mylibapp2 mylib)
  19. # Create installation targets. Note that we put each kind of file
  20. # into a different component via COMPONENT. These components will
  21. # be used to create the installation components.
  22. install(TARGETS mylib
  23. ARCHIVE
  24. DESTINATION ${CMAKE_INSTALL_LIBDIR}
  25. COMPONENT libraries)
  26. install(TARGETS mylibapp
  27. RUNTIME
  28. DESTINATION bin
  29. COMPONENT applications)
  30. install(FILES mylib.h
  31. DESTINATION include
  32. COMPONENT headers)
  33. # CPack boilerplate for this project
  34. set(CPACK_PACKAGE_NAME "MyLib")
  35. set(CPACK_PACKAGE_CONTACT "None")
  36. set(CPACK_PACKAGE_VENDOR "CMake.org")
  37. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
  38. set(CPACK_PACKAGE_VERSION "1.0.2")
  39. set(CPACK_PACKAGE_VERSION_MAJOR "1")
  40. set(CPACK_PACKAGE_VERSION_MINOR "0")
  41. set(CPACK_PACKAGE_VERSION_PATCH "2")
  42. set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
  43. set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/license.txt)
  44. # Tell CPack all of the components to install. The "ALL"
  45. # refers to the fact that this is the set of components that
  46. # will be included when CPack is instructed to put everything
  47. # into the binary installer (the default behavior).
  48. set(CPACK_COMPONENTS_ALL applications libraries headers)
  49. # Set the displayed names for each of the components to install.
  50. # These will be displayed in the list of components inside the installer.
  51. set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
  52. set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
  53. set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
  54. # Provide descriptions for each of the components to install.
  55. # When the user hovers the mouse over the name of a component,
  56. # the description will be shown in the "Description" box in the
  57. # installer. If no descriptions are provided, the "Description"
  58. # box will be removed.
  59. set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
  60. "An extremely useful application that makes use of MyLib")
  61. set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
  62. "Static libraries used to build programs with MyLib")
  63. set(CPACK_COMPONENT_HEADERS_DESCRIPTION
  64. "C/C++ header files for use with MyLib")
  65. # It doesn't make sense to install the headers without the libraries
  66. # (because you could never use the headers!), so make the headers component
  67. # depend on the libraries component.
  68. set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
  69. # creates preinst/prerm scripts with specific permissions. Those permissions
  70. # (especially executable) should be in the final archive
  71. find_program(CHMOD_PROG chmod)
  72. if(CHMOD_PROG)
  73. file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/preinst "echo default_preinst")
  74. file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/prerm "echo default_prerm")
  75. # Those should have 755 permission normally. We mess it up to see if
  76. # CPACK_DEBIAN_APPLICATIONS_PACKAGE_CONTROL_STRICT_PERMISSION is able to fix
  77. # it.
  78. execute_process(COMMAND ${CHMOD_PROG} 640 ${CMAKE_CURRENT_BINARY_DIR}/preinst)
  79. execute_process(COMMAND ${CHMOD_PROG} 640 ${CMAKE_CURRENT_BINARY_DIR}/prerm)
  80. set(CPACK_DEBIAN_APPLICATIONS_PACKAGE_CONTROL_EXTRA
  81. "${CMAKE_CURRENT_BINARY_DIR}/preinst;${CMAKE_CURRENT_BINARY_DIR}/prerm")
  82. set(CPACK_DEBIAN_APPLICATIONS_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
  83. endif()
  84. # creates a symbolic link and a directory. Those should not be hashed.
  85. # warning: relocation of the symlink is not supported (symlinks with relative
  86. # paths)
  87. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink mylibapp symtest)
  88. install(FILES ${CPackComponentsDEB_BINARY_DIR}/symtest
  89. DESTINATION bin
  90. COMPONENT applications)
  91. if(EXISTS "./dirtest")
  92. execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ./dirtest)
  93. endif()
  94. # NOTE: directory left empty on purpose
  95. execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ./dirtest)
  96. # NOTE: we should not add the trailing "/" to dirtest
  97. install(DIRECTORY ${CPackComponentsDEB_BINARY_DIR}/dirtest
  98. DESTINATION bin/
  99. COMPONENT applications)
  100. # We may use the CPack specific config file in order
  101. # to tailor CPack behavior on a CPack generator specific way
  102. # (Behavior would be different for RPM or TGZ or DEB ...)
  103. if (NOT DEFINED CPackDEBConfiguration)
  104. message(FATAL_ERROR "CPackDEBConfiguration should be defined")
  105. endif()
  106. # Setup project specific CPack-time CPack Config file.
  107. configure_file(${CPackComponentsDEB_SOURCE_DIR}/MyLibCPackConfig-${CPackDEBConfiguration}.cmake.in
  108. ${CPackComponentsDEB_BINARY_DIR}/MyLibCPackConfig-${CPackDEBConfiguration}.cmake
  109. @ONLY)
  110. set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsDEB_BINARY_DIR}/MyLibCPackConfig-${CPackDEBConfiguration}.cmake)
  111. # set CPACK_DEBIAN_FILE_NAME to use default package name format
  112. set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
  113. # Include CPack to introduce the appropriate targets
  114. include(CPack)