install.cmake 4.5 KB

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