CMakeLists.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 that allows
  5. # users to select which pieces will be installed: the example
  6. # application, the library binaries, and/or the header file.
  7. cmake_minimum_required(VERSION 2.6)
  8. project(CPackComponents)
  9. # Create the mylib library
  10. add_library(mylib mylib.cpp)
  11. # Create the mylibapp application
  12. add_executable(mylibapp mylibapp.cpp)
  13. target_link_libraries(mylibapp mylib)
  14. # On Linux, enable using an absolute install path to verify that
  15. # CMAKE_INSTALL_PREFIX and CPACK_SET_DESTDIR interact properly.
  16. #
  17. # But only use absolute paths if not targeting an NSIS installer
  18. # as indicated by CPACK_BINARY_NSIS. (If we allow this, the test
  19. # fails on Linux machines with makensis installed when we are not
  20. # cross-compiling...)
  21. #
  22. if(UNIX AND NOT APPLE)
  23. if(NOT CPACK_BINARY_NSIS)
  24. set(mylib_install_to_absolute_path ON)
  25. endif()
  26. endif()
  27. if(mylib_install_to_absolute_path)
  28. set(CMAKE_INSTALL_PREFIX "/opt/mylib")
  29. set(CPACK_SET_DESTDIR ON)
  30. endif()
  31. # Create installation targets. Note that we put each kind of file
  32. # into a different component via COMPONENT. These components will
  33. # be used to create the installation components.
  34. install(TARGETS mylib
  35. ARCHIVE
  36. DESTINATION lib
  37. COMPONENT libraries)
  38. install(TARGETS mylibapp
  39. RUNTIME
  40. DESTINATION bin
  41. COMPONENT applications)
  42. install(FILES mylib.h
  43. DESTINATION include
  44. COMPONENT headers)
  45. install(FILES "Issue 7470.html"
  46. DESTINATION docs
  47. COMPONENT documentation)
  48. if(mylib_install_to_absolute_path)
  49. install(FILES mylib.cpp
  50. DESTINATION /opt/mylib-source
  51. COMPONENT source)
  52. endif()
  53. # CPack boilerplate for this project
  54. set(CPACK_PACKAGE_NAME "MyLib")
  55. set(CPACK_PACKAGE_VENDOR "CMake.org")
  56. set(CPACK_PACKAGE_CONTACT "somebody@cmake.org")
  57. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
  58. set(CPACK_PACKAGE_VERSION "1.0.0")
  59. set(CPACK_PACKAGE_VERSION_MAJOR "1")
  60. set(CPACK_PACKAGE_VERSION_MINOR "0")
  61. set(CPACK_PACKAGE_VERSION_PATCH "0")
  62. set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
  63. # Settings used when building NSIS installers
  64. set(CPACK_NSIS_MENU_LINKS
  65. "ftp://ftpserver" "Test Ftp Link"
  66. "ftps://ftpsserver" "Test Ftps Link"
  67. "https://cmake.org" "CMake Web Site"
  68. "https://github.com/" "Test Https Link"
  69. "mailto:kitware@kitware.com" "Test MailTo Link"
  70. "news://newsserver" "Test News Link"
  71. )
  72. # Suggested default root for end users of the installer:
  73. set(CPACK_NSIS_INSTALL_ROOT "C:/Program Files/CMake Tests Install Root")
  74. # Include CPack to introduce the appropriate targets
  75. include(CPack)
  76. # Installation types
  77. cpack_add_install_type(Full
  78. DISPLAY_NAME "Everything")
  79. cpack_add_install_type(Developer)
  80. # Component groups
  81. cpack_add_component_group(Runtime)
  82. cpack_add_component_group(Development
  83. EXPANDED
  84. DESCRIPTION "All of the tools you'll ever need to develop software")
  85. # Components
  86. cpack_add_component(applications
  87. DISPLAY_NAME "MyLib Application"
  88. DESCRIPTION "An extremely useful application that makes use of MyLib"
  89. GROUP Runtime
  90. INSTALL_TYPES Full)
  91. cpack_add_component(documentation
  92. DISPLAY_NAME "MyLib Documentation"
  93. DESCRIPTION "The extensive suite of MyLib Application documentation files"
  94. GROUP Runtime
  95. INSTALL_TYPES Full)
  96. cpack_add_component(libraries
  97. DISPLAY_NAME "Libraries"
  98. DESCRIPTION "Static libraries used to build programs with MyLib"
  99. GROUP Development
  100. INSTALL_TYPES Developer Full)
  101. cpack_add_component(headers
  102. DISPLAY_NAME "C++ Headers"
  103. DESCRIPTION "C/C++ header files for use with MyLib"
  104. GROUP Development
  105. DEPENDS libraries
  106. INSTALL_TYPES Developer Full)
  107. if(mylib_install_to_absolute_path)
  108. cpack_add_component(source
  109. DISPLAY_NAME "C++ Source Files"
  110. DESCRIPTION "C/C++ source files to build MyLib"
  111. GROUP Development
  112. DEPENDS libraries
  113. INSTALL_TYPES Developer Full)
  114. endif()