blob: 6d7aa1e0dab5fd3c5e6c8e398aa7e8096b94cfe9 [file] [log] [blame]
Feng Xiaoeee38b02015-08-22 18:25:48 -07001include(GNUInstallDirs)
2
3foreach(_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})
14endforeach()
15
16install(TARGETS protoc EXPORT protobuf-targets
17 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
18
Walter Gray04265e42016-05-26 18:04:32 -070019file(STRINGS extract_includes.bat.in _extract_strings
20 REGEX "^copy")
21foreach(_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()
44endforeach()
Feng Xiaoeee38b02015-08-22 18:25:48 -070045
46# Internal function for parsing auto tools scripts
47function(_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)
63endfunction()
64
65# Install well-known type proto files
66_protobuf_auto_list("../src/Makefile.am" nobase_dist_proto_DATA)
67foreach(_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()
81endforeach()
82
83# Export configuration
Walter Gray7d794582016-05-19 14:52:04 -070084set(_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files")
85if(NOT MSVC)
Jeff Merver733ef982016-05-21 16:01:32 -070086 set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/protobuf" CACHE STRING "${_cmakedir_desc}")
Walter Gray7d794582016-05-19 14:52:04 -070087else()
88 set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}")
89endif()
Konstantin Podsvirov71556292016-06-01 17:00:08 +030090mark_as_advanced(CMAKE_INSTALL_CMAKEDIR)
Feng Xiaoeee38b02015-08-22 18:25:48 -070091
Konstantin Podsvirov71556292016-06-01 17:00:08 +030092# Import configuration
Feng Xiaoeee38b02015-08-22 18:25:48 -070093install(EXPORT protobuf-targets
Walter Gray7d794582016-05-19 14:52:04 -070094 DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
Walter Gray28f35b42016-05-19 15:55:12 -070095 NAMESPACE protobuf::
Feng Xiaoeee38b02015-08-22 18:25:48 -070096 COMPONENT protobuf-export)
97
98configure_file(protobuf-config.cmake.in
Konstantin Podsvirov71556292016-06-01 17:00:08 +030099 ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config.cmake @ONLY)
Feng Xiaoeee38b02015-08-22 18:25:48 -0700100configure_file(protobuf-config-version.cmake.in
Konstantin Podsvirov71556292016-06-01 17:00:08 +0300101 ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config-version.cmake @ONLY)
Feng Xiaoeee38b02015-08-22 18:25:48 -0700102configure_file(protobuf-module.cmake.in
Konstantin Podsvirov71556292016-06-01 17:00:08 +0300103 ${CMAKE_INSTALL_CMAKEDIR}/protobuf-module.cmake @ONLY)
104
105# Build tree import configuration (for import from subprojects)
106if(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}")
113endif()
Feng Xiaoeee38b02015-08-22 18:25:48 -0700114
115install(FILES
Konstantin Podsvirov71556292016-06-01 17:00:08 +0300116 "${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 Gray7d794582016-05-19 14:52:04 -0700120 DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
Feng Xiaoeee38b02015-08-22 18:25:48 -0700121 COMPONENT protobuf-export)