install.cmake 4.3 KB

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