Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 1 | include(GNUInstallDirs) |
| 2 | |
Arfrever Frehtes Taifersar Arahesis | 14cab5b | 2022-03-08 00:00:00 +0000 | [diff] [blame] | 3 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf.pc.cmake |
Axel Huebl | 668712c | 2017-07-21 18:57:07 +0200 | [diff] [blame] | 4 | ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY) |
Arfrever Frehtes Taifersar Arahesis | 14cab5b | 2022-03-08 00:00:00 +0000 | [diff] [blame] | 5 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf-lite.pc.cmake |
Axel Huebl | 668712c | 2017-07-21 18:57:07 +0200 | [diff] [blame] | 6 | ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc @ONLY) |
| 7 | |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 8 | set(_protobuf_libraries libprotobuf-lite libprotobuf) |
Daniel Joos | c8f7633 | 2020-10-10 00:54:39 +0200 | [diff] [blame] | 9 | if (protobuf_BUILD_LIBPROTOC) |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 10 | list(APPEND _protobuf_libraries libprotoc) |
Daniel Joos | c8f7633 | 2020-10-10 00:54:39 +0200 | [diff] [blame] | 11 | endif (protobuf_BUILD_LIBPROTOC) |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 12 | |
| 13 | foreach(_library ${_protobuf_libraries}) |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 14 | set_property(TARGET ${_library} |
| 15 | PROPERTY INTERFACE_INCLUDE_DIRECTORIES |
Arfrever Frehtes Taifersar Arahesis | 4268662 | 2022-03-08 00:00:00 +0000 | [diff] [blame] | 16 | $<BUILD_INTERFACE:${protobuf_SOURCE_DIR}/src> |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 17 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
Mizux | 7306f54 | 2018-05-22 21:52:07 +0200 | [diff] [blame] | 18 | if (UNIX AND NOT APPLE) |
| 19 | set_property(TARGET ${_library} |
| 20 | PROPERTY INSTALL_RPATH "$ORIGIN") |
| 21 | elseif (APPLE) |
| 22 | set_property(TARGET ${_library} |
| 23 | PROPERTY INSTALL_RPATH "@loader_path") |
| 24 | endif() |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 25 | install(TARGETS ${_library} EXPORT protobuf-targets |
| 26 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library} |
| 27 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library} |
| 28 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}) |
| 29 | endforeach() |
| 30 | |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 31 | if (protobuf_BUILD_PROTOC_BINARIES) |
| 32 | install(TARGETS protoc EXPORT protobuf-targets |
johanmoe | 06c8cbe | 2021-09-22 23:25:29 +0200 | [diff] [blame] | 33 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc |
| 34 | BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc) |
Mizux | 7306f54 | 2018-05-22 21:52:07 +0200 | [diff] [blame] | 35 | if (UNIX AND NOT APPLE) |
| 36 | set_property(TARGET protoc |
Carlos O'Ryan | b10d490 | 2019-06-02 21:39:23 -0400 | [diff] [blame] | 37 | PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}") |
Mizux | 7306f54 | 2018-05-22 21:52:07 +0200 | [diff] [blame] | 38 | elseif (APPLE) |
| 39 | set_property(TARGET protoc |
| 40 | PROPERTY INSTALL_RPATH "@loader_path/../lib") |
| 41 | endif() |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 42 | endif (protobuf_BUILD_PROTOC_BINARIES) |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 43 | |
Axel Huebl | 668712c | 2017-07-21 18:57:07 +0200 | [diff] [blame] | 44 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 45 | |
Mike Kruskal | 3edec1f | 2022-07-25 20:36:47 -0700 | [diff] [blame] | 46 | include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) |
| 47 | set(protobuf_HEADERS |
| 48 | ${libprotobuf_hdrs} |
| 49 | ${libprotoc_hdrs} |
| 50 | ${wkt_protos_files} |
| 51 | ${descriptor_proto_proto_srcs} |
| 52 | ${plugin_proto_proto_srcs} |
| 53 | ) |
| 54 | foreach(_header ${protobuf_HEADERS}) |
| 55 | string(REPLACE "${protobuf_SOURCE_DIR}/src" "" _header ${_header}) |
Arfrever Frehtes Taifersar Arahesis | 14cab5b | 2022-03-08 00:00:00 +0000 | [diff] [blame] | 56 | get_filename_component(_extract_from "${protobuf_SOURCE_DIR}/src/${_header}" ABSOLUTE) |
Feng Xiao | c94555f | 2017-03-10 16:32:19 -0800 | [diff] [blame] | 57 | get_filename_component(_extract_name ${_header} NAME) |
Arfrever Frehtes Taifersar Arahesis | bd935e1 | 2022-03-10 21:05:27 +0100 | [diff] [blame] | 58 | get_filename_component(_extract_to "${CMAKE_INSTALL_INCLUDEDIR}/${_header}" DIRECTORY) |
Mike Kruskal | 3edec1f | 2022-07-25 20:36:47 -0700 | [diff] [blame] | 59 | install(FILES "${_extract_from}" |
| 60 | DESTINATION "${_extract_to}" |
| 61 | COMPONENT protobuf-headers |
| 62 | RENAME "${_extract_name}") |
Walter Gray | 04265e4 | 2016-05-26 18:04:32 -0700 | [diff] [blame] | 63 | endforeach() |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 64 | |
Walter Gray | 23fef56 | 2016-06-06 10:59:58 -0700 | [diff] [blame] | 65 | # Install configuration |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 66 | set(_install_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files") |
| 67 | set(_build_cmakedir_desc "Directory relative to CMAKE_CURRENT_BINARY_DIR for cmake configuration files") |
Tongliang Liao | 5a7a4a5 | 2020-11-21 16:41:51 +0800 | [diff] [blame] | 68 | set(_exampledir_desc "Directory relative to CMAKE_INSTALL_DATA to install examples") |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 69 | set(_protobuf_subdir_desc "Subdirectory in which to install cmake configuration files") |
Walter Gray | 7d79458 | 2016-05-19 14:52:04 -0700 | [diff] [blame] | 70 | if(NOT MSVC) |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 71 | set(protobuf_CMAKE_SUBDIR "cmake/protobuf" CACHE STRING "${_protobuf_subdir_desc}") |
| 72 | set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_install_cmakedir_desc}") |
Tongliang Liao | 5a7a4a5 | 2020-11-21 16:41:51 +0800 | [diff] [blame] | 73 | set(CMAKE_INSTALL_EXAMPLEDIR "${CMAKE_INSTALL_DATADIR}/protobuf/examples" CACHE STRING "${_exampledir_desc}") |
Walter Gray | 7d79458 | 2016-05-19 14:52:04 -0700 | [diff] [blame] | 74 | else() |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 75 | set(protobuf_CMAKE_SUBDIR "cmake" CACHE STRING "${_protobuf_subdir_desc}") |
Walter Gray | 7d79458 | 2016-05-19 14:52:04 -0700 | [diff] [blame] | 76 | set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}") |
Tongliang Liao | 5a7a4a5 | 2020-11-21 16:41:51 +0800 | [diff] [blame] | 77 | set(CMAKE_INSTALL_EXAMPLEDIR "examples" CACHE STRING "${_exampledir_desc}") |
Walter Gray | 7d79458 | 2016-05-19 14:52:04 -0700 | [diff] [blame] | 78 | endif() |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 79 | set(CMAKE_BUILD_CMAKEDIR "${CMAKE_CURRENT_BINARY_DIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_build_cmakedir_desc}") |
| 80 | mark_as_advanced(protobuf_CMAKE_SUBDIR) |
| 81 | mark_as_advanced(CMAKE_BUILD_CMAKEDIR) |
Konstantin Podsvirov | 7155629 | 2016-06-01 17:00:08 +0300 | [diff] [blame] | 82 | mark_as_advanced(CMAKE_INSTALL_CMAKEDIR) |
Tongliang Liao | 5a7a4a5 | 2020-11-21 16:41:51 +0800 | [diff] [blame] | 83 | mark_as_advanced(CMAKE_INSTALL_EXAMPLEDIR) |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 84 | |
Arfrever Frehtes Taifersar Arahesis | 14cab5b | 2022-03-08 00:00:00 +0000 | [diff] [blame] | 85 | configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-config.cmake.in |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 86 | ${CMAKE_BUILD_CMAKEDIR}/protobuf-config.cmake @ONLY) |
Arfrever Frehtes Taifersar Arahesis | 14cab5b | 2022-03-08 00:00:00 +0000 | [diff] [blame] | 87 | configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-config-version.cmake.in |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 88 | ${CMAKE_BUILD_CMAKEDIR}/protobuf-config-version.cmake @ONLY) |
Arfrever Frehtes Taifersar Arahesis | 14cab5b | 2022-03-08 00:00:00 +0000 | [diff] [blame] | 89 | configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-module.cmake.in |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 90 | ${CMAKE_BUILD_CMAKEDIR}/protobuf-module.cmake @ONLY) |
Arfrever Frehtes Taifersar Arahesis | 14cab5b | 2022-03-08 00:00:00 +0000 | [diff] [blame] | 91 | configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-options.cmake |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 92 | ${CMAKE_BUILD_CMAKEDIR}/protobuf-options.cmake @ONLY) |
Harald Fernengel | ad55f52 | 2022-08-23 20:32:36 +0200 | [diff] [blame] | 93 | configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-generate.cmake |
| 94 | ${CMAKE_BUILD_CMAKEDIR}/protobuf-generate.cmake @ONLY) |
Konstantin Podsvirov | 7155629 | 2016-06-01 17:00:08 +0300 | [diff] [blame] | 95 | |
Walter Gray | 23fef56 | 2016-06-06 10:59:58 -0700 | [diff] [blame] | 96 | # Allows the build directory to be used as a find directory. |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 97 | |
Walter Gray | 23fef56 | 2016-06-06 10:59:58 -0700 | [diff] [blame] | 98 | install(EXPORT protobuf-targets |
Walter Gray | 7d79458 | 2016-05-19 14:52:04 -0700 | [diff] [blame] | 99 | DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" |
Walter Gray | 23fef56 | 2016-06-06 10:59:58 -0700 | [diff] [blame] | 100 | NAMESPACE protobuf:: |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 101 | COMPONENT protobuf-export |
| 102 | ) |
Adam Cozzette | 3b029b1 | 2022-05-26 14:11:37 -0700 | [diff] [blame] | 103 | |
Jonathan Ringer | 046bde0 | 2022-06-22 10:43:13 -0700 | [diff] [blame] | 104 | install(DIRECTORY ${CMAKE_BUILD_CMAKEDIR}/ |
Adam Cozzette | 3b029b1 | 2022-05-26 14:11:37 -0700 | [diff] [blame] | 105 | DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" |
Walter Gray | 23fef56 | 2016-06-06 10:59:58 -0700 | [diff] [blame] | 106 | COMPONENT protobuf-export |
Adam Cozzette | 3b029b1 | 2022-05-26 14:11:37 -0700 | [diff] [blame] | 107 | PATTERN protobuf-targets.cmake EXCLUDE |
Walter Gray | 23fef56 | 2016-06-06 10:59:58 -0700 | [diff] [blame] | 108 | ) |
| 109 | |
| 110 | option(protobuf_INSTALL_EXAMPLES "Install the examples folder" OFF) |
| 111 | if(protobuf_INSTALL_EXAMPLES) |
Arfrever Frehtes Taifersar Arahesis | 14cab5b | 2022-03-08 00:00:00 +0000 | [diff] [blame] | 112 | install(DIRECTORY examples/ |
Tongliang Liao | 5a7a4a5 | 2020-11-21 16:41:51 +0800 | [diff] [blame] | 113 | DESTINATION "${CMAKE_INSTALL_EXAMPLEDIR}" |
Walter Gray | 23fef56 | 2016-06-06 10:59:58 -0700 | [diff] [blame] | 114 | COMPONENT protobuf-examples) |
| 115 | endif() |