install.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. include(GNUInstallDirs)
  2. foreach(_library
  3. libprotobuf-lite
  4. libprotobuf
  5. libprotoc)
  6. set_property(TARGET ${_library}
  7. PROPERTY INTERFACE_INCLUDE_DIRECTORIES
  8. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
  9. install(TARGETS ${_library} EXPORT protobuf-targets
  10. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
  11. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
  12. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
  13. endforeach()
  14. install(TARGETS protoc EXPORT protobuf-targets
  15. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
  16. if(TRUE)
  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. endif()
  44. # Internal function for parsing auto tools scripts
  45. function(_protobuf_auto_list FILE_NAME VARIABLE)
  46. file(STRINGS ${FILE_NAME} _strings)
  47. set(_list)
  48. foreach(_string ${_strings})
  49. set(_found)
  50. string(REGEX MATCH "^[ \t]*${VARIABLE}[ \t]*=[ \t]*" _found "${_string}")
  51. if(_found)
  52. string(LENGTH "${_found}" _length)
  53. string(SUBSTRING "${_string}" ${_length} -1 _draft_list)
  54. foreach(_item ${_draft_list})
  55. string(STRIP "${_item}" _item)
  56. list(APPEND _list "${_item}")
  57. endforeach()
  58. endif()
  59. endforeach()
  60. set(${VARIABLE} ${_list} PARENT_SCOPE)
  61. endfunction()
  62. # Install well-known type proto files
  63. _protobuf_auto_list("../src/Makefile.am" nobase_dist_proto_DATA)
  64. foreach(_file ${nobase_dist_proto_DATA})
  65. get_filename_component(_file_from "../src/${_file}" ABSOLUTE)
  66. get_filename_component(_file_name ${_file} NAME)
  67. get_filename_component(_file_path ${_file} PATH)
  68. if(EXISTS "${_file_from}")
  69. install(FILES "${_file_from}"
  70. DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_file_path}"
  71. COMPONENT protobuf-protos
  72. RENAME "${_file_name}")
  73. else()
  74. message(AUTHOR_WARNING "The file \"${_file_from}\" is listed in "
  75. "\"${protobuf_SOURCE_DIR}/../src/Makefile.am\" as nobase_dist_proto_DATA "
  76. "but there not exists. The file will not be installed.")
  77. endif()
  78. endforeach()
  79. # Export configuration
  80. install(EXPORT protobuf-targets
  81. DESTINATION "lib/cmake/protobuf"
  82. COMPONENT protobuf-export)
  83. configure_file(protobuf-config.cmake.in
  84. protobuf-config.cmake @ONLY)
  85. configure_file(protobuf-config-version.cmake.in
  86. protobuf-config-version.cmake @ONLY)
  87. configure_file(protobuf-module.cmake.in
  88. protobuf-module.cmake @ONLY)
  89. install(FILES
  90. "${protobuf_BINARY_DIR}/protobuf-config.cmake"
  91. "${protobuf_BINARY_DIR}/protobuf-config-version.cmake"
  92. "${protobuf_BINARY_DIR}/protobuf-module.cmake"
  93. DESTINATION "lib/cmake/protobuf"
  94. COMPONENT protobuf-export)