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