CMakeLists.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "[email protected]")
  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. # Include CPack to introduce the appropriate targets
  64. include(CPack)
  65. # Installation types
  66. cpack_add_install_type(Full
  67. DISPLAY_NAME "Everything")
  68. cpack_add_install_type(Developer)
  69. # Component groups
  70. cpack_add_component_group(Runtime)
  71. cpack_add_component_group(Development
  72. EXPANDED
  73. DESCRIPTION "All of the tools you'll ever need to develop software")
  74. # Components
  75. cpack_add_component(applications
  76. DISPLAY_NAME "MyLib Application"
  77. DESCRIPTION "An extremely useful application that makes use of MyLib"
  78. GROUP Runtime
  79. INSTALL_TYPES Full)
  80. cpack_add_component(documentation
  81. DISPLAY_NAME "MyLib Documentation"
  82. DESCRIPTION "The extensive suite of MyLib Application documentation files"
  83. GROUP Runtime
  84. INSTALL_TYPES Full)
  85. cpack_add_component(libraries
  86. DISPLAY_NAME "Libraries"
  87. DESCRIPTION "Static libraries used to build programs with MyLib"
  88. GROUP Development
  89. INSTALL_TYPES Developer Full)
  90. cpack_add_component(headers
  91. DISPLAY_NAME "C++ Headers"
  92. DESCRIPTION "C/C++ header files for use with MyLib"
  93. GROUP Development
  94. DEPENDS libraries
  95. INSTALL_TYPES Developer Full)
  96. if(mylib_install_to_absolute_path)
  97. cpack_add_component(source
  98. DISPLAY_NAME "C++ Source Files"
  99. DESCRIPTION "C/C++ source files to build MyLib"
  100. GROUP Development
  101. DEPENDS libraries
  102. INSTALL_TYPES Developer Full)
  103. endif()