| 1 |
include(GNUInstallDirs) |
| 2 |
|
| 3 |
foreach(_target IN LISTS protobuf_ABSL_USED_TARGETS) |
| 4 |
string(REPLACE :: _ _modified_target ${_target}) |
| 5 |
list(APPEND _pc_targets ${_modified_target}) |
| 6 |
endforeach() |
| 7 |
list(APPEND _pc_targets "utf8_range") |
| 8 |
|
| 9 |
set(_protobuf_PC_REQUIRES "") |
| 10 |
set(_sep "") |
| 11 |
foreach (_target IN LISTS _pc_targets) |
| 12 |
string(CONCAT _protobuf_PC_REQUIRES "${_protobuf_PC_REQUIRES}" "${_sep}" "${_target}") |
| 13 |
set(_sep " ") |
| 14 |
endforeach () |
| 15 |
set(_protobuf_PC_CFLAGS) |
| 16 |
if (protobuf_BUILD_SHARED_LIBS) |
| 17 |
set(_protobuf_PC_CFLAGS -DPROTOBUF_USE_DLLS) |
| 18 |
endif () |
| 19 |
|
| 20 |
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf.pc.cmake |
| 21 |
${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY) |
| 22 |
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf-lite.pc.cmake |
| 23 |
${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc @ONLY) |
| 24 |
|
| 25 |
set(_protobuf_libraries libprotobuf-lite libprotobuf) |
| 26 |
if (protobuf_BUILD_LIBPROTOC) |
| 27 |
list(APPEND _protobuf_libraries libprotoc) |
| 28 |
endif (protobuf_BUILD_LIBPROTOC) |
| 29 |
|
| 30 |
foreach(_library ${_protobuf_libraries}) |
| 31 |
set_property(TARGET ${_library} |
| 32 |
PROPERTY INTERFACE_INCLUDE_DIRECTORIES |
| 33 |
$<BUILD_INTERFACE:${protobuf_SOURCE_DIR}/src> |
| 34 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
| 35 |
if (UNIX AND NOT APPLE) |
| 36 |
set_property(TARGET ${_library} |
| 37 |
PROPERTY INSTALL_RPATH "$ORIGIN") |
| 38 |
elseif (APPLE) |
| 39 |
set_property(TARGET ${_library} |
| 40 |
PROPERTY INSTALL_RPATH "@loader_path") |
| 41 |
endif() |
| 42 |
install(TARGETS ${_library} EXPORT protobuf-targets |
| 43 |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library} |
| 44 |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library} |
| 45 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}) |
| 46 |
endforeach() |
| 47 |
|
| 48 |
if (protobuf_BUILD_PROTOC_BINARIES) |
| 49 |
install(TARGETS protoc EXPORT protobuf-targets |
| 50 |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc |
| 51 |
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc) |
| 52 |
if (UNIX AND NOT APPLE) |
| 53 |
set_property(TARGET protoc |
| 54 |
PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}") |
| 55 |
elseif (APPLE) |
| 56 |
set_property(TARGET protoc |
| 57 |
PROPERTY INSTALL_RPATH "@loader_path/../lib") |
| 58 |
endif() |
| 59 |
endif (protobuf_BUILD_PROTOC_BINARIES) |
| 60 |
|
| 61 |
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 62 |
|
| 63 |
include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) |
| 64 |
set(protobuf_HEADERS |
| 65 |
${libprotobuf_hdrs} |
| 66 |
${libprotoc_hdrs} |
| 67 |
${wkt_protos_files} |
| 68 |
${cpp_features_proto_proto_srcs} |
| 69 |
${descriptor_proto_proto_srcs} |
| 70 |
${plugin_proto_proto_srcs} |
| 71 |
) |
| 72 |
foreach(_header ${protobuf_HEADERS}) |
| 73 |
string(REPLACE "${protobuf_SOURCE_DIR}/src" "" _header ${_header}) |
| 74 |
get_filename_component(_extract_from "${protobuf_SOURCE_DIR}/src/${_header}" ABSOLUTE) |
| 75 |
get_filename_component(_extract_name ${_header} NAME) |
| 76 |
get_filename_component(_extract_to "${CMAKE_INSTALL_INCLUDEDIR}/${_header}" DIRECTORY) |
| 77 |
install(FILES "${_extract_from}" |
| 78 |
DESTINATION "${_extract_to}" |
| 79 |
COMPONENT protobuf-headers |
| 80 |
RENAME "${_extract_name}") |
| 81 |
endforeach() |
| 82 |
|
| 83 |
# Install configuration |
| 84 |
set(_install_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files") |
| 85 |
set(_build_cmakedir_desc "Directory relative to CMAKE_CURRENT_BINARY_DIR for cmake configuration files") |
| 86 |
set(_exampledir_desc "Directory relative to CMAKE_INSTALL_DATA to install examples") |
| 87 |
set(_protobuf_subdir_desc "Subdirectory in which to install cmake configuration files") |
| 88 |
if(NOT MSVC) |
| 89 |
set(protobuf_CMAKE_SUBDIR "cmake/protobuf" CACHE STRING "${_protobuf_subdir_desc}") |
| 90 |
set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_install_cmakedir_desc}") |
| 91 |
set(CMAKE_INSTALL_EXAMPLEDIR "${CMAKE_INSTALL_DATADIR}/protobuf/examples" CACHE STRING "${_exampledir_desc}") |
| 92 |
else() |
| 93 |
set(protobuf_CMAKE_SUBDIR "cmake" CACHE STRING "${_protobuf_subdir_desc}") |
| 94 |
set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}") |
| 95 |
set(CMAKE_INSTALL_EXAMPLEDIR "examples" CACHE STRING "${_exampledir_desc}") |
| 96 |
endif() |
| 97 |
set(CMAKE_BUILD_CMAKEDIR "${CMAKE_CURRENT_BINARY_DIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_build_cmakedir_desc}") |
| 98 |
mark_as_advanced(protobuf_CMAKE_SUBDIR) |
| 99 |
mark_as_advanced(CMAKE_BUILD_CMAKEDIR) |
| 100 |
mark_as_advanced(CMAKE_INSTALL_CMAKEDIR) |
| 101 |
mark_as_advanced(CMAKE_INSTALL_EXAMPLEDIR) |
| 102 |
|
| 103 |
configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-config.cmake.in |
| 104 |
${CMAKE_BUILD_CMAKEDIR}/protobuf-config.cmake @ONLY) |
| 105 |
configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-config-version.cmake.in |
| 106 |
${CMAKE_BUILD_CMAKEDIR}/protobuf-config-version.cmake @ONLY) |
| 107 |
configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-module.cmake.in |
| 108 |
${CMAKE_BUILD_CMAKEDIR}/protobuf-module.cmake @ONLY) |
| 109 |
configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-options.cmake |
| 110 |
${CMAKE_BUILD_CMAKEDIR}/protobuf-options.cmake @ONLY) |
| 111 |
configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-generate.cmake |
| 112 |
${CMAKE_BUILD_CMAKEDIR}/protobuf-generate.cmake @ONLY) |
| 113 |
|
| 114 |
# Allows the build directory to be used as a find directory. |
| 115 |
|
| 116 |
install(EXPORT protobuf-targets |
| 117 |
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" |
| 118 |
NAMESPACE protobuf:: |
| 119 |
COMPONENT protobuf-export |
| 120 |
) |
| 121 |
|
| 122 |
install(DIRECTORY ${CMAKE_BUILD_CMAKEDIR}/ |
| 123 |
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" |
| 124 |
COMPONENT protobuf-export |
| 125 |
PATTERN protobuf-targets.cmake EXCLUDE |
| 126 |
) |
| 127 |
|
| 128 |
option(protobuf_INSTALL_EXAMPLES "Install the examples folder" OFF) |
| 129 |
if(protobuf_INSTALL_EXAMPLES) |
| 130 |
install(DIRECTORY examples/ |
| 131 |
DESTINATION "${CMAKE_INSTALL_EXAMPLEDIR}" |
| 132 |
COMPONENT protobuf-examples) |
| 133 |
endif() |
| 134 |
|
| 135 |
if (protobuf_INSTALL_TESTS) |
| 136 |
install(TARGETS gmock EXPORT protobuf-targets |
| 137 |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 138 |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 139 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 140 |
endif() |