CMakeLists.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. # Create the mylib library
  13. add_library(mylib mylib.cpp)
  14. # Create the mylibapp application
  15. add_executable(mylibapp mylibapp.cpp)
  16. target_link_libraries(mylibapp mylib)
  17. # Duplicate of mylibapp application
  18. # which won't be put in any component (?mistake?)
  19. add_executable(mylibapp2 mylibapp.cpp)
  20. target_link_libraries(mylibapp2 mylib)
  21. # Create installation targets. Note that we put each kind of file
  22. # into a different component via COMPONENT. These components will
  23. # be used to create the installation components.
  24. install(TARGETS mylib
  25. ARCHIVE
  26. DESTINATION lib
  27. COMPONENT libraries)
  28. install(TARGETS mylibapp
  29. RUNTIME
  30. DESTINATION bin
  31. COMPONENT applications)
  32. # This application does not belong to any component
  33. # thus (as of cmake 2.8.2) it will be left "uninstalled"
  34. # by a component-aware installer unless a
  35. # CPACK_MONOLITHIC_INSTALL=1 is set (at cmake time).
  36. install(TARGETS mylibapp2
  37. RUNTIME
  38. DESTINATION bin)
  39. install(FILES mylib.h
  40. DESTINATION include
  41. COMPONENT headers)
  42. # CPack boilerplate for this project
  43. set(CPACK_PACKAGE_NAME "MyLib")
  44. set(CPACK_PACKAGE_CONTACT "None")
  45. set(CPACK_PACKAGE_VENDOR "CMake.org")
  46. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
  47. set(CPACK_PACKAGE_VERSION "1.0.2")
  48. set(CPACK_PACKAGE_VERSION_MAJOR "1")
  49. set(CPACK_PACKAGE_VERSION_MINOR "0")
  50. set(CPACK_PACKAGE_VERSION_PATCH "2")
  51. set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
  52. # Tell CPack all of the components to install. The "ALL"
  53. # refers to the fact that this is the set of components that
  54. # will be included when CPack is instructed to put everything
  55. # into the binary installer (the default behavior).
  56. set(CPACK_COMPONENTS_ALL applications libraries headers Unspecified)
  57. # Set the displayed names for each of the components to install.
  58. # These will be displayed in the list of components inside the installer.
  59. set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
  60. set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
  61. set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
  62. # Provide descriptions for each of the components to install.
  63. # When the user hovers the mouse over the name of a component,
  64. # the description will be shown in the "Description" box in the
  65. # installer. If no descriptions are provided, the "Description"
  66. # box will be removed.
  67. set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
  68. "An extremely useful application that makes use of MyLib")
  69. set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
  70. "Static libraries used to build programs with MyLib")
  71. set(CPACK_COMPONENT_HEADERS_DESCRIPTION
  72. "C/C++ header files for use with MyLib")
  73. # Put the components into two different groups: "Runtime" and "Development"
  74. set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
  75. set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
  76. set(CPACK_COMPONENT_HEADERS_GROUP "Development")
  77. # Expand the "Development" group by default, since we have so few components.
  78. # Also, provide this group with a description.
  79. set(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON)
  80. set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
  81. "All of the tools you'll ever need to develop software")
  82. # It doesn't make sense to install the headers without the libraries
  83. # (because you could never use the headers!), so make the headers component
  84. # depend on the libraries component.
  85. set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
  86. # Create two installation types with pre-selected components.
  87. # The "Developer" installation has just the library and headers,
  88. # while the "Full" installation has everything.
  89. set(CPACK_ALL_INSTALL_TYPES Full Developer)
  90. set(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything")
  91. set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full)
  92. set(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
  93. set(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full)
  94. # We may use the CPack specific config file in order
  95. # to tailor CPack behavio on a CPack generator specific way
  96. # (Behavior would be different for RPM or TGZ or DEB ...)
  97. if (USE_CPACK_PROJECT_CONFIG)
  98. # Setup project specific CPack-time CPack Config file.
  99. configure_file(${MyLib_SOURCE_DIR}/MyLibCPackConfig.cmake.in
  100. ${MyLib_BINARY_DIR}/MyLibCPackConfig.cmake
  101. @ONLY)
  102. set(CPACK_PROJECT_CONFIG_FILE ${MyLib_BINARY_DIR}/MyLibCPackConfig.cmake)
  103. endif (USE_CPACK_PROJECT_CONFIG)
  104. # Include CPack to introduce the appropriate targets
  105. include(CPack)