install.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. include(GNUInstallDirs)
  2. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf.pc.cmake
  3. ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY)
  4. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf-lite.pc.cmake
  5. ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc @ONLY)
  6. set(_protobuf_libraries libprotobuf-lite libprotobuf)
  7. if (protobuf_BUILD_PROTOC_BINARIES)
  8. list(APPEND _protobuf_libraries libprotoc)
  9. endif (protobuf_BUILD_PROTOC_BINARIES)
  10. foreach(_library ${_protobuf_libraries})
  11. set_property(TARGET ${_library}
  12. PROPERTY INTERFACE_INCLUDE_DIRECTORIES
  13. $<BUILD_INTERFACE:${protobuf_source_dir}/src>
  14. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
  15. install(TARGETS ${_library} EXPORT protobuf-targets
  16. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
  17. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
  18. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
  19. endforeach()
  20. if (protobuf_BUILD_PROTOC_BINARIES)
  21. install(TARGETS protoc EXPORT protobuf-targets
  22. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
  23. endif (protobuf_BUILD_PROTOC_BINARIES)
  24. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  25. file(STRINGS extract_includes.bat.in _extract_strings
  26. REGEX "^copy")
  27. foreach(_extract_string ${_extract_strings})
  28. string(REGEX REPLACE "^.* .+ include\\\\(.+)$" "\\1"
  29. _header ${_extract_string})
  30. string(REPLACE "\\" "/" _header ${_header})
  31. get_filename_component(_extract_from "${protobuf_SOURCE_DIR}/../src/${_header}" ABSOLUTE)
  32. get_filename_component(_extract_name ${_header} NAME)
  33. get_filename_component(_extract_to "${CMAKE_INSTALL_INCLUDEDIR}/${_header}" PATH)
  34. if(EXISTS "${_extract_from}")
  35. install(FILES "${_extract_from}"
  36. DESTINATION "${_extract_to}"
  37. COMPONENT protobuf-headers
  38. RENAME "${_extract_name}")
  39. else()
  40. message(AUTHOR_WARNING "The file \"${_extract_from}\" is listed in "
  41. "\"${protobuf_SOURCE_DIR}/cmake/extract_includes.bat.in\" "
  42. "but there not exists. The file will not be installed.")
  43. endif()
  44. endforeach()
  45. # Internal function for parsing auto tools scripts
  46. function(_protobuf_auto_list FILE_NAME VARIABLE)
  47. file(STRINGS ${FILE_NAME} _strings)
  48. set(_list)
  49. foreach(_string ${_strings})
  50. set(_found)
  51. string(REGEX MATCH "^[ \t]*${VARIABLE}[ \t]*=[ \t]*" _found "${_string}")
  52. if(_found)
  53. string(LENGTH "${_found}" _length)
  54. string(SUBSTRING "${_string}" ${_length} -1 _draft_list)
  55. foreach(_item ${_draft_list})
  56. string(STRIP "${_item}" _item)
  57. list(APPEND _list "${_item}")
  58. endforeach()
  59. endif()
  60. endforeach()
  61. set(${VARIABLE} ${_list} PARENT_SCOPE)
  62. endfunction()
  63. # Install well-known type proto files
  64. _protobuf_auto_list("../src/Makefile.am" nobase_dist_proto_DATA)
  65. foreach(_file ${nobase_dist_proto_DATA})
  66. get_filename_component(_file_from "../src/${_file}" ABSOLUTE)
  67. get_filename_component(_file_name ${_file} NAME)
  68. get_filename_component(_file_path ${_file} PATH)
  69. if(EXISTS "${_file_from}")
  70. install(FILES "${_file_from}"
  71. DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_file_path}"
  72. COMPONENT protobuf-protos
  73. RENAME "${_file_name}")
  74. else()
  75. message(AUTHOR_WARNING "The file \"${_file_from}\" is listed in "
  76. "\"${protobuf_SOURCE_DIR}/../src/Makefile.am\" as nobase_dist_proto_DATA "
  77. "but there not exists. The file will not be installed.")
  78. endif()
  79. endforeach()
  80. # Install configuration
  81. set(_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files")
  82. if(NOT MSVC)
  83. set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/protobuf" CACHE STRING "${_cmakedir_desc}")
  84. else()
  85. set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}")
  86. endif()
  87. mark_as_advanced(CMAKE_INSTALL_CMAKEDIR)
  88. configure_file(protobuf-config.cmake.in
  89. ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config.cmake @ONLY)
  90. configure_file(protobuf-config-version.cmake.in
  91. ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config-version.cmake @ONLY)
  92. configure_file(protobuf-module.cmake.in
  93. ${CMAKE_INSTALL_CMAKEDIR}/protobuf-module.cmake @ONLY)
  94. configure_file(protobuf-options.cmake
  95. ${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)
  96. # Allows the build directory to be used as a find directory.
  97. if (protobuf_BUILD_PROTOC_BINARIES)
  98. export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
  99. NAMESPACE protobuf::
  100. FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
  101. )
  102. else (protobuf_BUILD_PROTOC_BINARIES)
  103. export(TARGETS libprotobuf-lite libprotobuf
  104. NAMESPACE protobuf::
  105. FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
  106. )
  107. endif (protobuf_BUILD_PROTOC_BINARIES)
  108. install(EXPORT protobuf-targets
  109. DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
  110. NAMESPACE protobuf::
  111. COMPONENT protobuf-export)
  112. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/
  113. DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
  114. COMPONENT protobuf-export
  115. PATTERN protobuf-targets.cmake EXCLUDE
  116. )
  117. option(protobuf_INSTALL_EXAMPLES "Install the examples folder" OFF)
  118. if(protobuf_INSTALL_EXAMPLES)
  119. install(DIRECTORY ../examples/ DESTINATION examples
  120. COMPONENT protobuf-examples)
  121. endif()