CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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)
  41. install(FILES mylib.h
  42. DESTINATION include
  43. COMPONENT headers)
  44. # CPack boilerplate for this project
  45. set(CPACK_PACKAGE_NAME "MyLib")
  46. set(CPACK_PACKAGE_CONTACT "None")
  47. set(CPACK_PACKAGE_VENDOR "CMake.org")
  48. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
  49. set(CPACK_PACKAGE_VERSION "1.0.2")
  50. set(CPACK_PACKAGE_VERSION_MAJOR "1")
  51. set(CPACK_PACKAGE_VERSION_MINOR "0")
  52. set(CPACK_PACKAGE_VERSION_PATCH "2")
  53. set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
  54. # Tell CPack all of the components to install. The "ALL"
  55. # refers to the fact that this is the set of components that
  56. # will be included when CPack is instructed to put everything
  57. # into the binary installer (the default behavior).
  58. set(CPACK_COMPONENTS_ALL applications libraries headers Unspecified)
  59. # Set the displayed names for each of the components to install.
  60. # These will be displayed in the list of components inside the installer.
  61. set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
  62. set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
  63. set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
  64. # Provide descriptions for each of the components to install.
  65. # When the user hovers the mouse over the name of a component,
  66. # the description will be shown in the "Description" box in the
  67. # installer. If no descriptions are provided, the "Description"
  68. # box will be removed.
  69. set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
  70. "An extremely useful application that makes use of MyLib")
  71. set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
  72. "Static libraries used to build programs with MyLib")
  73. set(CPACK_COMPONENT_HEADERS_DESCRIPTION
  74. "C/C++ header files for use with MyLib")
  75. # Put the components into two different groups: "Runtime" and "Development"
  76. set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
  77. set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
  78. set(CPACK_COMPONENT_HEADERS_GROUP "Development")
  79. # Expand the "Development" group by default, since we have so few components.
  80. # Also, provide this group with a description.
  81. set(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON)
  82. set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
  83. "All of the tools you'll ever need to develop software")
  84. # It doesn't make sense to install the headers without the libraries
  85. # (because you could never use the headers!), so make the headers component
  86. # depend on the libraries component.
  87. set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
  88. # Create two installation types with pre-selected components.
  89. # The "Developer" installation has just the library and headers,
  90. # while the "Full" installation has everything.
  91. set(CPACK_ALL_INSTALL_TYPES Full Developer)
  92. set(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything")
  93. set(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full)
  94. set(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
  95. set(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full)
  96. # We may use the CPack specific config file in order
  97. # to tailor CPack behavior on a CPack generator specific way
  98. # (Behavior would be different for RPM or TGZ or DEB ...)
  99. if (NOT ("${CPackComponentWay}" STREQUAL "default"))
  100. # Setup project specific CPack-time CPack Config file.
  101. configure_file(${CPackComponentsForAll_SOURCE_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake.in
  102. ${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake
  103. @ONLY)
  104. set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsForAll_BINARY_DIR}/MyLibCPackConfig-${CPackComponentWay}.cmake)
  105. endif ()
  106. # Include CPack to introduce the appropriate targets
  107. include(CPack)