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