Fix cmake export for grpc

This patch fixes two issues with the targets exported by the
grpc cmake build:

- Install directories are now given relative instead of absolute.
  Previously the exported targets would contain absolute paths to
  their created targets when they should be relative. The actual
  installation location stays the same as cmake automatically
  interprets the paths relative to CMAKE_INSTALL_PREFIX

- ZLIB and OpenSSL are now linked using targets instead of the
  legacy library variables if possible. Using the legacy paths
  produces absolute paths to those dependencies in the export.
  With this change cmake inserts the target names instead.

With these changes no more absolute paths are inserted into the
export allowing the install location to be used as an artifact
that can be moved or transfered to another machine and used there.
pull/14019/head
Stefan Hacker 7 years ago committed by Stefan Hacker
parent e1e562eb17
commit 471a5dc18b
  1. 8
      CMakeLists.txt
  2. 8
      cmake/ssl.cmake
  3. 8
      cmake/zlib.cmake
  4. 8
      templates/CMakeLists.txt.template

@ -30,10 +30,10 @@ set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
project(${PACKAGE_NAME} C CXX)
set(gRPC_INSTALL_BINDIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
set(gRPC_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
set(gRPC_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
set(gRPC_INSTALL_CMAKEDIR "${CMAKE_INSTALL_PREFIX}/lib/cmake/${PACKAGE_NAME}" CACHE PATH "Installation directory for cmake config files")
set(gRPC_INSTALL_BINDIR "bin" CACHE STRING "Installation directory for executables")
set(gRPC_INSTALL_LIBDIR "lib" CACHE STRING "Installation directory for libraries")
set(gRPC_INSTALL_INCLUDEDIR "include" CACHE STRING "Installation directory for headers")
set(gRPC_INSTALL_CMAKEDIR "lib/cmake/${PACKAGE_NAME}" CACHE STRING "Installation directory for cmake config files")
# Options
option(gRPC_BUILD_TESTS "Build tests" OFF)

@ -32,7 +32,13 @@ if("${gRPC_SSL_PROVIDER}" STREQUAL "module")
endif()
elseif("${gRPC_SSL_PROVIDER}" STREQUAL "package")
find_package(OpenSSL REQUIRED)
set(_gRPC_SSL_LIBRARIES ${OPENSSL_LIBRARIES})
if(TARGET OpenSSL::SSL)
set(_gRPC_SSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
else()
set(_gRPC_SSL_LIBRARIES ${OPENSSL_LIBRARIES})
endif()
set(_gRPC_SSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
set(_gRPC_FIND_SSL "if(NOT OPENSSL_FOUND)\n find_package(OpenSSL)\nendif()")
endif()

@ -34,6 +34,12 @@ if("${gRPC_ZLIB_PROVIDER}" STREQUAL "module")
endif()
elseif("${gRPC_ZLIB_PROVIDER}" STREQUAL "package")
find_package(ZLIB REQUIRED)
set(_gRPC_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
if(TARGET ZLIB::ZLIB)
set(_gRPC_ZLIB_LIBRARIES ZLIB::ZLIB)
else()
set(_gRPC_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
endif()
set(_gRPC_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()")
endif()

@ -74,10 +74,10 @@
set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
project(<%text>${PACKAGE_NAME}</%text> C CXX)
set(gRPC_INSTALL_BINDIR "<%text>${CMAKE_INSTALL_PREFIX}</%text>/bin" CACHE PATH "Installation directory for executables")
set(gRPC_INSTALL_LIBDIR "<%text>${CMAKE_INSTALL_PREFIX}</%text>/lib" CACHE PATH "Installation directory for libraries")
set(gRPC_INSTALL_INCLUDEDIR "<%text>${CMAKE_INSTALL_PREFIX}</%text>/include" CACHE PATH "Installation directory for headers")
set(gRPC_INSTALL_CMAKEDIR "<%text>${CMAKE_INSTALL_PREFIX}/lib/cmake/${PACKAGE_NAME}</%text>" CACHE PATH "Installation directory for cmake config files")
set(gRPC_INSTALL_BINDIR "bin" CACHE STRING "Installation directory for executables")
set(gRPC_INSTALL_LIBDIR "lib" CACHE STRING "Installation directory for libraries")
set(gRPC_INSTALL_INCLUDEDIR "include" CACHE STRING "Installation directory for headers")
set(gRPC_INSTALL_CMAKEDIR "lib/cmake/<%text>${PACKAGE_NAME}</%text>" CACHE STRING "Installation directory for cmake config files")
# Options
option(gRPC_BUILD_TESTS "Build tests" OFF)

Loading…
Cancel
Save