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