CMakeLists.txt 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. cmake_minimum_required(VERSION 2.8.3.20101130 FATAL_ERROR)
  7. project(CPackComponentsDEB)
  8. # Use GNUInstallDirs in order to enforce lib64 if needed
  9. include(GNUInstallDirs)
  10. # Create the mylib library
  11. add_library(mylib mylib.cpp)
  12. # Create the mylibapp application
  13. add_executable(mylibapp mylibapp.cpp)
  14. target_link_libraries(mylibapp mylib)
  15. # Duplicate of mylibapp application
  16. # which won't be put in any component (?mistake?)
  17. add_executable(mylibapp2 mylibapp.cpp)
  18. target_link_libraries(mylibapp2 mylib)
  19. # Create installation targets. Note that we put each kind of file
  20. # into a different component via COMPONENT. These components will
  21. # be used to create the installation components.
  22. install(TARGETS mylib
  23. ARCHIVE
  24. DESTINATION ${CMAKE_INSTALL_LIBDIR}
  25. COMPONENT libraries)
  26. install(TARGETS mylibapp
  27. RUNTIME
  28. DESTINATION bin
  29. COMPONENT applications)
  30. install(FILES mylib.h
  31. DESTINATION include
  32. COMPONENT headers)
  33. # CPack boilerplate for this project
  34. set(CPACK_PACKAGE_NAME "MyLib")
  35. set(CPACK_PACKAGE_CONTACT "None")
  36. set(CPACK_PACKAGE_VENDOR "CMake.org")
  37. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
  38. set(CPACK_PACKAGE_VERSION "1.0.2")
  39. set(CPACK_PACKAGE_VERSION_MAJOR "1")
  40. set(CPACK_PACKAGE_VERSION_MINOR "0")
  41. set(CPACK_PACKAGE_VERSION_PATCH "2")
  42. set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")
  43. set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/license.txt)
  44. # Tell CPack all of the components to install. The "ALL"
  45. # refers to the fact that this is the set of components that
  46. # will be included when CPack is instructed to put everything
  47. # into the binary installer (the default behavior).
  48. set(CPACK_COMPONENTS_ALL applications libraries headers)
  49. # Set the displayed names for each of the components to install.
  50. # These will be displayed in the list of components inside the installer.
  51. set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "MyLib Application")
  52. set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
  53. set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
  54. # Provide descriptions for each of the components to install.
  55. # When the user hovers the mouse over the name of a component,
  56. # the description will be shown in the "Description" box in the
  57. # installer. If no descriptions are provided, the "Description"
  58. # box will be removed.
  59. set(CPACK_COMPONENT_APPLICATIONS_DESCRIPTION
  60. "An extremely useful application that makes use of MyLib")
  61. set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
  62. "Static libraries used to build programs with MyLib")
  63. set(CPACK_COMPONENT_HEADERS_DESCRIPTION
  64. "C/C++ header files for use with MyLib")
  65. # It doesn't make sense to install the headers without the libraries
  66. # (because you could never use the headers!), so make the headers component
  67. # depend on the libraries component.
  68. set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
  69. # We may use the CPack specific config file in order
  70. # to tailor CPack behavior on a CPack generator specific way
  71. # (Behavior would be different for RPM or TGZ or DEB ...)
  72. if (NOT DEFINED CPackDEBConfiguration)
  73. message(FATAL_ERROR "CPackDEBConfiguration should be defined")
  74. endif()
  75. # Setup project specific CPack-time CPack Config file.
  76. configure_file(${CPackComponentsDEB_SOURCE_DIR}/MyLibCPackConfig-${CPackDEBConfiguration}.cmake.in
  77. ${CPackComponentsDEB_BINARY_DIR}/MyLibCPackConfig-${CPackDEBConfiguration}.cmake
  78. @ONLY)
  79. set(CPACK_PROJECT_CONFIG_FILE ${CPackComponentsDEB_BINARY_DIR}/MyLibCPackConfig-${CPackDEBConfiguration}.cmake)
  80. # Include CPack to introduce the appropriate targets
  81. include(CPack)