| include(GNUInstallDirs) |
| |
| configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf.pc.cmake |
| ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY) |
| configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf-lite.pc.cmake |
| ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc @ONLY) |
| |
| set(_protobuf_libraries libprotobuf-lite libprotobuf) |
| if (protobuf_BUILD_LIBPROTOC) |
| list(APPEND _protobuf_libraries libprotoc) |
| endif (protobuf_BUILD_LIBPROTOC) |
| |
| foreach(_library ${_protobuf_libraries}) |
| set_property(TARGET ${_library} |
| PROPERTY INTERFACE_INCLUDE_DIRECTORIES |
| $<BUILD_INTERFACE:${protobuf_SOURCE_DIR}/src> |
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
| if (UNIX AND NOT APPLE) |
| set_property(TARGET ${_library} |
| PROPERTY INSTALL_RPATH "$ORIGIN") |
| elseif (APPLE) |
| set_property(TARGET ${_library} |
| PROPERTY INSTALL_RPATH "@loader_path") |
| endif() |
| install(TARGETS ${_library} EXPORT protobuf-targets |
| RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library} |
| LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library} |
| ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}) |
| endforeach() |
| |
| if (protobuf_BUILD_PROTOC_BINARIES) |
| install(TARGETS protoc EXPORT protobuf-targets |
| RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc |
| BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc) |
| if (UNIX AND NOT APPLE) |
| set_property(TARGET protoc |
| PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}") |
| elseif (APPLE) |
| set_property(TARGET protoc |
| PROPERTY INSTALL_RPATH "@loader_path/../lib") |
| endif() |
| endif (protobuf_BUILD_PROTOC_BINARIES) |
| |
| install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| |
| include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) |
| set(protobuf_HEADERS |
| ${libprotobuf_hdrs} |
| ${libprotoc_hdrs} |
| ${wkt_protos_files} |
| ${descriptor_proto_proto_srcs} |
| ${plugin_proto_proto_srcs} |
| ) |
| foreach(_header ${protobuf_HEADERS}) |
| string(REPLACE "${protobuf_SOURCE_DIR}/src" "" _header ${_header}) |
| get_filename_component(_extract_from "${protobuf_SOURCE_DIR}/src/${_header}" ABSOLUTE) |
| get_filename_component(_extract_name ${_header} NAME) |
| get_filename_component(_extract_to "${CMAKE_INSTALL_INCLUDEDIR}/${_header}" DIRECTORY) |
| install(FILES "${_extract_from}" |
| DESTINATION "${_extract_to}" |
| COMPONENT protobuf-headers |
| RENAME "${_extract_name}") |
| endforeach() |
| |
| # Install configuration |
| set(_install_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files") |
| set(_build_cmakedir_desc "Directory relative to CMAKE_CURRENT_BINARY_DIR for cmake configuration files") |
| set(_exampledir_desc "Directory relative to CMAKE_INSTALL_DATA to install examples") |
| set(_protobuf_subdir_desc "Subdirectory in which to install cmake configuration files") |
| if(NOT MSVC) |
| set(protobuf_CMAKE_SUBDIR "cmake/protobuf" CACHE STRING "${_protobuf_subdir_desc}") |
| set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_install_cmakedir_desc}") |
| set(CMAKE_INSTALL_EXAMPLEDIR "${CMAKE_INSTALL_DATADIR}/protobuf/examples" CACHE STRING "${_exampledir_desc}") |
| else() |
| set(protobuf_CMAKE_SUBDIR "cmake" CACHE STRING "${_protobuf_subdir_desc}") |
| set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}") |
| set(CMAKE_INSTALL_EXAMPLEDIR "examples" CACHE STRING "${_exampledir_desc}") |
| endif() |
| set(CMAKE_BUILD_CMAKEDIR "${CMAKE_CURRENT_BINARY_DIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_build_cmakedir_desc}") |
| mark_as_advanced(protobuf_CMAKE_SUBDIR) |
| mark_as_advanced(CMAKE_BUILD_CMAKEDIR) |
| mark_as_advanced(CMAKE_INSTALL_CMAKEDIR) |
| mark_as_advanced(CMAKE_INSTALL_EXAMPLEDIR) |
| |
| configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-config.cmake.in |
| ${CMAKE_BUILD_CMAKEDIR}/protobuf-config.cmake @ONLY) |
| configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-config-version.cmake.in |
| ${CMAKE_BUILD_CMAKEDIR}/protobuf-config-version.cmake @ONLY) |
| configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-module.cmake.in |
| ${CMAKE_BUILD_CMAKEDIR}/protobuf-module.cmake @ONLY) |
| configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-options.cmake |
| ${CMAKE_BUILD_CMAKEDIR}/protobuf-options.cmake @ONLY) |
| configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-generate.cmake |
| ${CMAKE_BUILD_CMAKEDIR}/protobuf-generate.cmake @ONLY) |
| |
| # Allows the build directory to be used as a find directory. |
| |
| install(EXPORT protobuf-targets |
| DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" |
| NAMESPACE protobuf:: |
| COMPONENT protobuf-export |
| ) |
| |
| install(DIRECTORY ${CMAKE_BUILD_CMAKEDIR}/ |
| DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" |
| COMPONENT protobuf-export |
| PATTERN protobuf-targets.cmake EXCLUDE |
| ) |
| |
| option(protobuf_INSTALL_EXAMPLES "Install the examples folder" OFF) |
| if(protobuf_INSTALL_EXAMPLES) |
| install(DIRECTORY examples/ |
| DESTINATION "${CMAKE_INSTALL_EXAMPLEDIR}" |
| COMPONENT protobuf-examples) |
| endif() |