aboutsummaryrefslogtreecommitdiffhomepage
path: root/templates
diff options
context:
space:
mode:
authorGravatar Konstantin Podsvirov <konstantin@podsvirov.pro>2016-07-27 23:43:47 +0300
committerGravatar Konstantin Podsvirov <konstantin@podsvirov.pro>2016-07-28 00:46:11 +0300
commitd2b883022cdb3156b411cdac5e0da7a4e129091c (patch)
treec00b0a65918c1148150881f3c8a726159df470c0 /templates
parent5baf725a9de91b651d10a9917669b24d0f0cfe2f (diff)
CMake: Installation and Export Configuration
Diffstat (limited to 'templates')
-rw-r--r--templates/CMakeLists.txt.template45
1 files changed, 45 insertions, 0 deletions
diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template
index 4c8d155b29..a1c76828e2 100644
--- a/templates/CMakeLists.txt.template
+++ b/templates/CMakeLists.txt.template
@@ -102,6 +102,7 @@
if(TARGET ZLIB::ZLIB)
set(_gRPC_ZLIB_LIBRARIES ZLIB::ZLIB)
endif()
+ set(_gRPC_FIND_ZLIB "if(NOT ZLIB_FOUND) find_package(ZLIB) endif()")
endif()
if("<%text>${gRPC_PROTOBUF_PROVIDER}</%text>" STREQUAL "module")
@@ -134,8 +135,10 @@
if(TARGET protobuf::libprotoc)
set(_gRPC_PROTOBUF_PROTOC_LIBRARIES protobuf::libprotoc)
endif()
+ set(_gRPC_FIND_PROTOBUF "if(NOT protobuf_FOUND) find_package(protobuf CONFIG) endif()")
else()
find_package(Protobuf MODULE)
+ set(_gRPC_FIND_PROTOBUF "if(NOT Protobuf_FOUND) find_package(Protobuf) endif()")
endif()
endif()
@@ -156,6 +159,7 @@
if(TARGET OpenSSL::SSL)
set(_gRPC_SSL_LIBRARIES OpenSSL::SSL)
endif()
+ set(_gRPC_FIND_SSL "if(NOT OpenSSL_FOUND) find_package(OpenSSL) endif()")
endif()
if(NOT MSVC)
@@ -167,15 +171,22 @@
set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32)
endif()
+ include(GNUInstallDirs)
+ if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR)
+ set(CMAKE_INSTALL_CMAKEDIR "<%text>${CMAKE_INSTALL_LIBDIR}</%text>/cmake/gRPC")
+ endif()
+
% for lib in libs:
% if lib.build in ["all", "protoc", "tool"]:
${cc_library(lib)}
+ ${cc_install(lib)}
% endif
% endfor
% for tgt in targets:
% if tgt.build in ["all", "protoc", "tool"]:
${cc_binary(tgt)}
+ ${cc_install(tgt)}
% endif
% endfor
@@ -202,6 +213,20 @@
% endfor
)
% endif
+
+ % if len(lib.get('public_headers', [])) > 0:
+ foreach(_hdr
+ % for hdr in lib.get('public_headers', []):
+ ${hdr}
+ % endfor
+ )
+ string(REPLACE "include/" "" _path <%text>${_hdr}</%text>)
+ get_filename_component(_path <%text>${_path}</%text> PATH)
+ install(FILES <%text>${_hdr}</%text>
+ DESTINATION "<%text>${CMAKE_INSTALL_INCLUDEDIR}/${_path}</%text>"
+ )
+ endforeach()
+ % endif
</%def>
<%def name="cc_binary(tgt)">
@@ -229,3 +254,23 @@
% endif
</%def>
+ <%def name="cc_install(tgt)">
+ install(TARGETS ${tgt.name} EXPORT gRPCTargets
+ RUNTIME DESTINATION <%text>${CMAKE_INSTALL_BINDIR}</%text>
+ LIBRARY DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text>
+ ARCHIVE DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text>
+ )
+ </%def>
+
+ install(EXPORT gRPCTargets
+ DESTINATION <%text>${CMAKE_INSTALL_CMAKEDIR}</%text>
+ NAMESPACE gRPC::
+ )
+
+ foreach(_config gRPCConfig gRPCConfigVersion)
+ configure_file(tools/cmake/<%text>${_config}</%text>.cmake.in
+ <%text>${_config}</%text>.cmake @ONLY)
+ install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/${_config}</%text>.cmake
+ DESTINATION <%text>${CMAKE_INSTALL_CMAKEDIR}</%text>
+ )
+ endforeach()