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