install.cmake 4.6 KB

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