CMakeLists.txt 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. #
  7. # Depending on the CPack generator and on some CPACK_xxx var values
  8. # the generator may produce a single (NSIS, PackageMaker)
  9. # or several package files (Archive Generators, RPM, DEB)
  10. cmake_minimum_required(VERSION 2.8.3.20101130 FATAL_ERROR)
  11. project(CPackComponentsForAll)
  12. # Use GNUInstallDirs in order to enforce lib64 if needed
  13. include(GNUInstallDirs)
  14. # Create the mylib library
  15. add_library(mylib mylib.cpp)
  16. # Create the mylibapp application
  17. add_executable(mylibapp mylibapp.cpp)
  18. target_link_libraries(mylibapp mylib)
  19. # Duplicate of mylibapp application
  20. # which won't be put in any component (?mistake?)
  21. add_executable(mylibapp2 mylibapp.cpp)
  22. target_link_libraries(mylibapp2 mylib)
  23. # Create installation targets. Note that we put each kind of file
  24. # into a different component via COMPONENT. These components will
  25. # be used to create the installation components.
  26. install(TARGETS mylib
  27. ARCHIVE
  28. DESTINATION ${CMAKE_INSTALL_LIBDIR}
  29. COMPONENT libraries)
  30. install(TARGETS mylibapp
  31. RUNTIME
  32. DESTINATION bin
  33. COMPONENT applications)
  34. # This application does not belong to any component
  35. # thus (as of cmake 2.8.2) it will be left "uninstalled"
  36. # by a component-aware installer unless a
  37. # CPACK_MONOLITHIC_INSTALL=1 is set (at cmake time).
  38. install(TARGETS mylibapp2
  39. RUNTIME
  40. DESTINATION bin/@in@_@path@@with\\@and\\@/\@in_path\@) # test @ char in path
  41. install(FILES mylib.h
  42. DESTINATION include
  43. COMPONENT headers)
  44. if("${CPACK_GENERATOR}" MATCHES "RPM")
  45. ############## test man pages
  46. install(FILES mylib
  47. DESTINATION share/man/mylib/man3/mylib.1)
  48. install(FILES mylib
  49. DESTINATION share/man/mylib/man3/mylib.1 RENAME mylib2)
  50. ############## test symlinks
  51. # Package symbolic links
  52. install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three COMPONENT libraries)
  53. install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable/bar COMPONENT libraries)
  54. install(DIRECTORY DESTINATION other_relocatable/depth_two COMPONENT libraries)
  55. install(DIRECTORY DESTINATION non_relocatable/depth_two COMPONENT libraries)
  56. # test symbolic links to same dir
  57. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink depth_three symlink_samedir_path)
  58. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
  59. # test symbolic links to same dir with current dir ./ prefix
  60. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ./depth_three symlink_samedir_path_current_dir)
  61. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path_current_dir DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
  62. # test symbolic links to same dir with longer relative path
  63. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../../${CMAKE_INSTALL_LIBDIR}/.././${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/./depth_two/depth_three symlink_samedir_path_longer)
  64. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_samedir_path_longer DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
  65. # test symbolic links to sub dir
  66. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three symlink_subdir_path)
  67. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_subdir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one COMPONENT libraries)
  68. # test symbolic links to parent dir
  69. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../../../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/./depth_two symlink_parentdir_path)
  70. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_parentdir_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two/depth_three COMPONENT libraries)
  71. # test symbolic link to another relocatable path
  72. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././.././../other_relocatable/./depth_two symlink_other_relocatable_path)
  73. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_other_relocatable_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two COMPONENT libraries)
  74. # test symbolic link to non relocatable path
  75. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../../non_relocatable/./depth_two symlink_to_non_relocatable_path)
  76. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_to_non_relocatable_path DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two COMPONENT libraries)
  77. # test symbolic link from non relocatable path
  78. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink .././../${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two symlink_from_non_relocatable_path)
  79. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_from_non_relocatable_path DESTINATION non_relocatable/depth_two COMPONENT libraries)
  80. # test symbolic link relocatable path to its relocatable subpath
  81. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../inside_relocatable_two/depth_two/different_relocatable/bar symlink_relocatable_subpath)
  82. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_relocatable_subpath DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
  83. # test symbolic link to location outside package
  84. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ./outside_package symlink_outside_package)
  85. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_outside_package DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
  86. # test symbolic link to location outside wdr (packaging directory)
  87. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink /outside_package_wdr symlink_outside_wdr)
  88. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/symlink_outside_wdr DESTINATION ${CMAKE_INSTALL_LIBDIR}/inside_relocatable_one/depth_two COMPONENT libraries)
  89. endif()
  90. # CPack boilerplate for this project
  91. set(CPACK_PACKAGE_NAME "MyLib")
  92. set(CPACK_PACKAGE_CONTACT "None")
  93. set(CPACK_PACKAGE_VENDOR "CMake.org")
  94. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
  95. set(CPACK_PACKAGE_VERSION "1.0.2")
  96. set(CPACK_PACKAGE_VERSION_MAJOR "1")
  97. set(CPACK_PACKAGE_VERSION_MINOR "0")
  98. set(CPACK_PACKAGE_VERSION_PATCH "2")
  99. set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
  100. set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/license.txt)
  101. # Tell CPack all of the components to install. The "ALL"
  102. # refers to the fact that this is the set of components that
  103. # will be included when CPack is instructed to put everything
  104. # into the binary installer (the default behavior).
  105. set(CPACK_COMPONENTS_ALL applications libraries headers Unspecified)
  106. # Set the displayed names for each of the components to install.
  107. # These will be displayed in the list of components inside the installer.
  108. set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
  109. set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
  110. set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
  111. # Provide descriptions for each of the components to install.
  112. # When the user hovers the mouse over the name of a component,
  113. # the description will be shown in the "Description" box in the
  114. # installer. If no descriptions are provided, the "Description"
  115. # box will be removed.
  116. set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
  117. "An extremely useful application that makes use of MyLib")
  118. set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
  119. "Static libraries used to build programs with MyLib")
  120. set(CPACK_COMPONENT_HEADERS_DESCRIPTION
  121. "C/C++ header files for use with MyLib")
  122. # Put the components into two different groups: "Runtime" and "Development"
  123. set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
  124. set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
  125. set(CPACK_COMPONENT_HEADERS_GROUP "Development")
  126. # Expand the "Development" group by default, since we have so few components.
  127. # Also, provide this group with a description.
  128. set(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON)
  129. set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
  130. "All of the tools you'll ever need to develop software")
  131. # It doesn't make sense to install the headers without the libraries
  132. # (because you could never use the headers!), so make the headers component
  133. # depend on the libraries component.
  134. set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
  135. # Create two installation types with pre-selected components.
  136. # The "Developer" installation has just the library and headers,
  137. # while the "Full" installation has everything.
  138. set(CPACK_ALL_INSTALL_TYPES Full Developer)
  139. set(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything")
  140. set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full)
  141. set(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
  142. set(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full)
  143. # set CPACK_RPM_RELOCATION_PATHS here as GNUInstallDirs script
  144. # can not be used in CPack scripts due to CMAKE_SIZEOF_VOID_P
  145. # variable not being set
  146. set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"
  147. "${CMAKE_INSTALL_LIBDIR}" "${CMAKE_INSTALL_BINDIR}" "other_relocatable"
  148. "${CMAKE_INSTALL_LIBDIR}/inside_relocatable_two/depth_two/different_relocatable")
  149. # set CPACK_DEBIAN_FILE_NAME to use default package name format
  150. set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
  151. # We may use the CPack specific config file in order
  152. # to tailor CPack behavior on a CPack generator specific way
  153. # (Behavior would be different for RPM or TGZ or DEB ...)
  154. if (NOT ("${CPackComponentWay}" STREQUAL "default"))
  155. # Setup project specific CPack-time CPack Config file.
  156. configure_file(${CPackComponentsForAll_SOURCE_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake.in
  157. ${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake
  158. @ONLY)
  159. set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake)
  160. endif ()
  161. # Include CPack to introduce the appropriate targets
  162. include(CPack)