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