2015-08-23 01:25:48 +00:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2017-07-21 16:57:07 +00:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf.pc.cmake
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY)
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protobuf-lite.pc.cmake
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc @ONLY)
|
|
|
|
|
2017-11-13 23:15:39 +00:00
|
|
|
set(_protobuf_libraries libprotobuf-lite libprotobuf)
|
2020-10-09 22:54:39 +00:00
|
|
|
if (protobuf_BUILD_LIBPROTOC)
|
2017-11-13 23:15:39 +00:00
|
|
|
list(APPEND _protobuf_libraries libprotoc)
|
2020-10-09 22:54:39 +00:00
|
|
|
endif (protobuf_BUILD_LIBPROTOC)
|
2017-11-13 23:15:39 +00:00
|
|
|
|
|
|
|
foreach(_library ${_protobuf_libraries})
|
2015-08-23 01:25:48 +00:00
|
|
|
set_property(TARGET ${_library}
|
|
|
|
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
|
2016-06-06 17:59:58 +00:00
|
|
|
$<BUILD_INTERFACE:${protobuf_source_dir}/src>
|
2015-08-23 01:25:48 +00:00
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
2018-05-22 19:52:07 +00:00
|
|
|
if (UNIX AND NOT APPLE)
|
|
|
|
set_property(TARGET ${_library}
|
|
|
|
PROPERTY INSTALL_RPATH "$ORIGIN")
|
|
|
|
elseif (APPLE)
|
|
|
|
set_property(TARGET ${_library}
|
|
|
|
PROPERTY INSTALL_RPATH "@loader_path")
|
|
|
|
endif()
|
2015-08-23 01:25:48 +00:00
|
|
|
install(TARGETS ${_library} EXPORT protobuf-targets
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
|
|
|
|
endforeach()
|
|
|
|
|
2017-11-13 23:15:39 +00:00
|
|
|
if (protobuf_BUILD_PROTOC_BINARIES)
|
|
|
|
install(TARGETS protoc EXPORT protobuf-targets
|
2021-02-16 19:59:54 +00:00
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
COMPONENT protoc)
|
2018-05-22 19:52:07 +00:00
|
|
|
if (UNIX AND NOT APPLE)
|
|
|
|
set_property(TARGET protoc
|
2019-06-03 01:39:23 +00:00
|
|
|
PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
|
2018-05-22 19:52:07 +00:00
|
|
|
elseif (APPLE)
|
|
|
|
set_property(TARGET protoc
|
|
|
|
PROPERTY INSTALL_RPATH "@loader_path/../lib")
|
|
|
|
endif()
|
2017-11-13 23:15:39 +00:00
|
|
|
endif (protobuf_BUILD_PROTOC_BINARIES)
|
2015-08-23 01:25:48 +00:00
|
|
|
|
2017-07-21 16:57:07 +00:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
|
|
|
|
2016-05-27 01:04:32 +00:00
|
|
|
file(STRINGS extract_includes.bat.in _extract_strings
|
|
|
|
REGEX "^copy")
|
|
|
|
foreach(_extract_string ${_extract_strings})
|
2017-03-11 00:32:19 +00:00
|
|
|
string(REGEX REPLACE "^.* .+ include\\\\(.+)$" "\\1"
|
|
|
|
_header ${_extract_string})
|
|
|
|
string(REPLACE "\\" "/" _header ${_header})
|
|
|
|
get_filename_component(_extract_from "${protobuf_SOURCE_DIR}/../src/${_header}" ABSOLUTE)
|
|
|
|
get_filename_component(_extract_name ${_header} NAME)
|
|
|
|
get_filename_component(_extract_to "${CMAKE_INSTALL_INCLUDEDIR}/${_header}" PATH)
|
2016-05-27 01:04:32 +00:00
|
|
|
if(EXISTS "${_extract_from}")
|
|
|
|
install(FILES "${_extract_from}"
|
|
|
|
DESTINATION "${_extract_to}"
|
|
|
|
COMPONENT protobuf-headers
|
|
|
|
RENAME "${_extract_name}")
|
|
|
|
else()
|
|
|
|
message(AUTHOR_WARNING "The file \"${_extract_from}\" is listed in "
|
|
|
|
"\"${protobuf_SOURCE_DIR}/cmake/extract_includes.bat.in\" "
|
|
|
|
"but there not exists. The file will not be installed.")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2015-08-23 01:25:48 +00:00
|
|
|
|
|
|
|
# Internal function for parsing auto tools scripts
|
|
|
|
function(_protobuf_auto_list FILE_NAME VARIABLE)
|
|
|
|
file(STRINGS ${FILE_NAME} _strings)
|
|
|
|
set(_list)
|
|
|
|
foreach(_string ${_strings})
|
|
|
|
set(_found)
|
|
|
|
string(REGEX MATCH "^[ \t]*${VARIABLE}[ \t]*=[ \t]*" _found "${_string}")
|
|
|
|
if(_found)
|
|
|
|
string(LENGTH "${_found}" _length)
|
|
|
|
string(SUBSTRING "${_string}" ${_length} -1 _draft_list)
|
|
|
|
foreach(_item ${_draft_list})
|
|
|
|
string(STRIP "${_item}" _item)
|
|
|
|
list(APPEND _list "${_item}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${VARIABLE} ${_list} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Install well-known type proto files
|
|
|
|
_protobuf_auto_list("../src/Makefile.am" nobase_dist_proto_DATA)
|
|
|
|
foreach(_file ${nobase_dist_proto_DATA})
|
|
|
|
get_filename_component(_file_from "../src/${_file}" ABSOLUTE)
|
|
|
|
get_filename_component(_file_name ${_file} NAME)
|
|
|
|
get_filename_component(_file_path ${_file} PATH)
|
|
|
|
if(EXISTS "${_file_from}")
|
|
|
|
install(FILES "${_file_from}"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_file_path}"
|
|
|
|
COMPONENT protobuf-protos
|
|
|
|
RENAME "${_file_name}")
|
|
|
|
else()
|
|
|
|
message(AUTHOR_WARNING "The file \"${_file_from}\" is listed in "
|
|
|
|
"\"${protobuf_SOURCE_DIR}/../src/Makefile.am\" as nobase_dist_proto_DATA "
|
|
|
|
"but there not exists. The file will not be installed.")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2016-06-06 17:59:58 +00:00
|
|
|
# Install configuration
|
2016-05-19 21:52:04 +00:00
|
|
|
set(_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files")
|
2020-11-21 08:41:51 +00:00
|
|
|
set(_exampledir_desc "Directory relative to CMAKE_INSTALL_DATA to install examples")
|
2016-05-19 21:52:04 +00:00
|
|
|
if(NOT MSVC)
|
2016-05-21 23:01:32 +00:00
|
|
|
set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/protobuf" CACHE STRING "${_cmakedir_desc}")
|
2020-11-21 08:41:51 +00:00
|
|
|
set(CMAKE_INSTALL_EXAMPLEDIR "${CMAKE_INSTALL_DATADIR}/protobuf/examples" CACHE STRING "${_exampledir_desc}")
|
2016-05-19 21:52:04 +00:00
|
|
|
else()
|
|
|
|
set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}")
|
2020-11-21 08:41:51 +00:00
|
|
|
set(CMAKE_INSTALL_EXAMPLEDIR "examples" CACHE STRING "${_exampledir_desc}")
|
2016-05-19 21:52:04 +00:00
|
|
|
endif()
|
2016-06-01 14:00:08 +00:00
|
|
|
mark_as_advanced(CMAKE_INSTALL_CMAKEDIR)
|
2020-11-21 08:41:51 +00:00
|
|
|
mark_as_advanced(CMAKE_INSTALL_EXAMPLEDIR)
|
2015-08-23 01:25:48 +00:00
|
|
|
|
|
|
|
configure_file(protobuf-config.cmake.in
|
2016-06-01 14:00:08 +00:00
|
|
|
${CMAKE_INSTALL_CMAKEDIR}/protobuf-config.cmake @ONLY)
|
2015-08-23 01:25:48 +00:00
|
|
|
configure_file(protobuf-config-version.cmake.in
|
2016-06-01 14:00:08 +00:00
|
|
|
${CMAKE_INSTALL_CMAKEDIR}/protobuf-config-version.cmake @ONLY)
|
2015-08-23 01:25:48 +00:00
|
|
|
configure_file(protobuf-module.cmake.in
|
2016-06-01 14:00:08 +00:00
|
|
|
${CMAKE_INSTALL_CMAKEDIR}/protobuf-module.cmake @ONLY)
|
2016-06-06 17:59:58 +00:00
|
|
|
configure_file(protobuf-options.cmake
|
|
|
|
${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)
|
2016-06-01 14:00:08 +00:00
|
|
|
|
2016-06-06 17:59:58 +00:00
|
|
|
# Allows the build directory to be used as a find directory.
|
2017-11-13 23:15:39 +00:00
|
|
|
|
|
|
|
if (protobuf_BUILD_PROTOC_BINARIES)
|
|
|
|
export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
|
|
|
|
NAMESPACE protobuf::
|
|
|
|
FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
|
|
|
|
)
|
|
|
|
else (protobuf_BUILD_PROTOC_BINARIES)
|
|
|
|
export(TARGETS libprotobuf-lite libprotobuf
|
|
|
|
NAMESPACE protobuf::
|
|
|
|
FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
|
|
|
|
)
|
|
|
|
endif (protobuf_BUILD_PROTOC_BINARIES)
|
2015-08-23 01:25:48 +00:00
|
|
|
|
2016-06-06 17:59:58 +00:00
|
|
|
install(EXPORT protobuf-targets
|
2016-05-19 21:52:04 +00:00
|
|
|
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
|
2016-06-06 17:59:58 +00:00
|
|
|
NAMESPACE protobuf::
|
2015-08-23 01:25:48 +00:00
|
|
|
COMPONENT protobuf-export)
|
2016-06-06 17:59:58 +00:00
|
|
|
|
2016-07-25 19:13:53 +00:00
|
|
|
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/
|
2016-06-06 17:59:58 +00:00
|
|
|
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
|
|
|
|
COMPONENT protobuf-export
|
|
|
|
PATTERN protobuf-targets.cmake EXCLUDE
|
|
|
|
)
|
|
|
|
|
|
|
|
option(protobuf_INSTALL_EXAMPLES "Install the examples folder" OFF)
|
|
|
|
if(protobuf_INSTALL_EXAMPLES)
|
2020-11-21 08:41:51 +00:00
|
|
|
install(DIRECTORY ../examples/
|
|
|
|
DESTINATION "${CMAKE_INSTALL_EXAMPLEDIR}"
|
2016-06-06 17:59:58 +00:00
|
|
|
COMPONENT protobuf-examples)
|
|
|
|
endif()
|