From 471a5dc18b4465b051cddf4e02dbdf44336f80ce Mon Sep 17 00:00:00 2001 From: Stefan Hacker Date: Sun, 14 Jan 2018 13:38:20 +0100 Subject: 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. --- CMakeLists.txt | 8 ++++---- cmake/ssl.cmake | 8 +++++++- cmake/zlib.cmake | 8 +++++++- templates/CMakeLists.txt.template | 8 ++++---- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78ccfb2132..7fc956ec98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/ssl.cmake b/cmake/ssl.cmake index 75ce069fe6..53d8a1597e 100644 --- a/cmake/ssl.cmake +++ b/cmake/ssl.cmake @@ -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() diff --git a/cmake/zlib.cmake b/cmake/zlib.cmake index 16cd9e66d5..e324802f65 100644 --- a/cmake/zlib.cmake +++ b/cmake/zlib.cmake @@ -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() diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 8de0ccde82..8bd62dca43 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -74,10 +74,10 @@ set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/") project(<%text>${PACKAGE_NAME} C CXX) - set(gRPC_INSTALL_BINDIR "<%text>${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") - set(gRPC_INSTALL_LIBDIR "<%text>${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") - set(gRPC_INSTALL_INCLUDEDIR "<%text>${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") - set(gRPC_INSTALL_CMAKEDIR "<%text>${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/<%text>${PACKAGE_NAME}" CACHE STRING "Installation directory for cmake config files") # Options option(gRPC_BUILD_TESTS "Build tests" OFF) -- cgit v1.2.3 From 93f13871d8e86d00bcf5fbb14981071f77836905 Mon Sep 17 00:00:00 2001 From: Stefan Hacker Date: Sun, 28 Jan 2018 03:32:16 +0100 Subject: Fix helloworld zlib include directory confusion in run_distrib_test_cmake.bat We have to give cmake the explicit zlib location as the internal testing environment has C:/msys64/usr/bin in the PATH and zlib-devel installed. cmake has heuristics in find_package which sees this /bin suffix in PATH and adds C:/msys64/usr/ to the find_package search locations. Doing a find_package(zlib) in this environment makes the find module for it (FindZLIB) find the header zlib.h in C:/msys64/usr/include while the library will still be taken from the testinstall location masking the issue in the log. To satisfy the dependency cmake adds C:/msys64/usr/include as an include directory. This makes cl.exe build with mixed C and C++ standard lib headers breaking the build. This issue was previously masked by cmake writing absolute paths for zlib and other dependencies into the grpc cmake exports. --- test/distrib/cpp/run_distrib_test_cmake.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/distrib/cpp/run_distrib_test_cmake.bat b/test/distrib/cpp/run_distrib_test_cmake.bat index f920768ae3..44661566b1 100644 --- a/test/distrib/cpp/run_distrib_test_cmake.bat +++ b/test/distrib/cpp/run_distrib_test_cmake.bat @@ -64,7 +64,7 @@ mkdir cmake cd cmake mkdir build cd build -cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DOPENSSL_INCLUDE_DIR=%OPENSSL_DIR%/include ../.. || goto :error +cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DOPENSSL_INCLUDE_DIR=%OPENSSL_DIR%/include -DZLIB_LIBRARY=%INSTALL_DIR%/lib/zlibstatic.lib -DZLIB_INCLUDE_DIR=%INSTALL_DIR%/include ../.. || goto :error cmake --build . --config Release || goto :error cd ../../../../.. -- cgit v1.2.3 From 5e9cfd9a99df31febf31f4aa1d0da9efa1e83e32 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 6 Feb 2018 16:11:24 +0100 Subject: cleanup the way openssl and zlib are used --- test/distrib/cpp/run_distrib_test_cmake.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/distrib/cpp/run_distrib_test_cmake.bat b/test/distrib/cpp/run_distrib_test_cmake.bat index 44661566b1..8eb3b201b1 100644 --- a/test/distrib/cpp/run_distrib_test_cmake.bat +++ b/test/distrib/cpp/run_distrib_test_cmake.bat @@ -54,7 +54,7 @@ cd ../../../.. cd cmake mkdir build cd build -cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DOPENSSL_INCLUDE_DIR=%OPENSSL_DIR%/include -DZLIB_LIBRARY=%INSTALL_DIR%/lib/zlibstatic.lib -DZLIB_INCLUDE_DIR=%INSTALL_DIR%/include -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DCMAKE_BUILD_TYPE=Release ../.. || goto :error +cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DZLIB_ROOT=%INSTALL_DIR% -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DCMAKE_BUILD_TYPE=Release ../.. || goto :error cmake --build . --config Release --target install || goto :error cd ../.. @@ -64,7 +64,7 @@ mkdir cmake cd cmake mkdir build cd build -cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DOPENSSL_INCLUDE_DIR=%OPENSSL_DIR%/include -DZLIB_LIBRARY=%INSTALL_DIR%/lib/zlibstatic.lib -DZLIB_INCLUDE_DIR=%INSTALL_DIR%/include ../.. || goto :error +cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DZLIB_ROOT=%INSTALL_DIR% ../.. || goto :error cmake --build . --config Release || goto :error cd ../../../../.. -- cgit v1.2.3