install.cmake 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. function (install_project
  2. PROJECT_NAME i_project_name
  3. TARGET_NAME i_target_name
  4. TARGET_OUTPUT_SUFFIX i_target_output_suffix
  5. EXPORT_HEADER i_export_header
  6. INCLUDE_PREFIX i_include_prefix
  7. HEADER_MATCHING_REGEX i_header_matching_regex
  8. VERSION_HEADER i_version_header
  9. NAMESPACE i_namespace)
  10. install (TARGETS ${i_target_name}
  11. EXPORT ${i_target_name}
  12. RUNTIME DESTINATION bin
  13. INCLUDES DESTINATION include
  14. ARCHIVE DESTINATION lib
  15. LIBRARY DESTINATION lib)
  16. install (DIRECTORY include/
  17. DESTINATION include
  18. FILES_MATCHING
  19. REGEX ${i_header_matching_regex}
  20. REGEX "CMakeLists\.txt" EXCLUDE)
  21. install (FILES ${i_version_header}
  22. DESTINATION include/${i_include_prefix}
  23. COMPONENT Devel)
  24. install (FILES include/${i_export_header}
  25. DESTINATION include/${i_include_prefix}
  26. COMPONENT Devel)
  27. install(
  28. EXPORT ${i_target_name}
  29. DESTINATION lib/cmake/${i_target_name}${i_target_output_suffix}
  30. FILE "${i_target_name}${i_target_output_suffix}.cmake"
  31. COMPONENT Devel)
  32. include(CMakePackageConfigHelpers)
  33. string (TOLOWER ${i_target_name} CMAKE_BASE_FILE_NAME)
  34. string (TOLOWER "${i_target_output_suffix}" CMAKE_FILE_OUTPUT_SUFFIX)
  35. write_basic_package_version_file(
  36. "${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-config-version.cmake"
  37. VERSION ${${i_project_name}_VERSION}
  38. COMPATIBILITY SameMajorVersion
  39. )
  40. export(EXPORT ${i_target_name}
  41. FILE "${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-targets.cmake"
  42. )
  43. configure_file("cmake/${i_project_name}-config.cmake"
  44. "${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-config.cmake"
  45. @ONLY
  46. )
  47. set(ConfigPackageLocation "lib/cmake/${i_target_name}${i_target_output_suffix}")
  48. install(EXPORT ${i_target_name}
  49. FILE
  50. "${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-targets.cmake"
  51. NAMESPACE
  52. "${i_namespace}"
  53. DESTINATION
  54. ${ConfigPackageLocation}
  55. )
  56. install(
  57. FILES
  58. "${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-config.cmake"
  59. "${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-config-version.cmake"
  60. DESTINATION
  61. ${ConfigPackageLocation}
  62. COMPONENT
  63. Devel
  64. )
  65. configure_file(
  66. ${CMAKE_CURRENT_SOURCE_DIR}/${i_project_name}.pc.in
  67. ${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}${i_target_output_suffix}.pc
  68. @ONLY
  69. )
  70. install(FILES
  71. ${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}${i_target_output_suffix}.pc
  72. DESTINATION
  73. lib/pkgconfig
  74. )
  75. endfunction (install_project)