From 7bb75068b56b629bd8fdc4e0927dc100558d143a Mon Sep 17 00:00:00 2001 From: Zack Galbreath Date: Thu, 3 Oct 2019 11:04:54 -0400 Subject: [PATCH] Create pkg-config files from CMake --- CMakeLists.txt | 71 ++++++++++++++++++++++++++++++- cmake/pkg-config-template.pc.in | 12 ++++++ templates/CMakeLists.txt.template | 71 ++++++++++++++++++++++++++++++- 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 cmake/pkg-config-template.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 8294a2c2e1f..98c3f5e9105 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,10 +25,11 @@ cmake_minimum_required(VERSION 3.5.1) set(PACKAGE_NAME "grpc") set(PACKAGE_VERSION "1.25.0-dev") +set(gRPC_CORE_VERSION "8.0.0") set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}") set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/") -project(${PACKAGE_NAME} C CXX) +project(${PACKAGE_NAME} LANGUAGES C CXX) set(gRPC_INSTALL_BINDIR "bin" CACHE STRING "Installation directory for executables") set(gRPC_INSTALL_LIBDIR "lib" CACHE STRING "Installation directory for libraries") @@ -19431,3 +19432,71 @@ endforeach() install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/etc/roots.pem DESTINATION ${gRPC_INSTALL_SHAREDIR}) + +# Function to generate pkg-config files. +function(generate_pkgconfig name description version requires + libs libs_private output_filename) + set(PC_NAME "${name}") + set(PC_DESCRIPTION "${description}") + set(PC_VERSION "${version}") + set(PC_REQUIRES "${requires}") + set(PC_LIB "${libs}") + set(PC_LIBS_PRIVATE "${libs_private}") + set(output_filepath "${grpc_BINARY_DIR}/libs/opt/pkgconfig/${output_filename}") + configure_file( + "${grpc_SOURCE_DIR}/cmake/pkg-config-template.pc.in" + "${output_filepath}" + @ONLY) + install(FILES "${output_filepath}" + DESTINATION "lib/pkgconfig/") +endfunction() + +# gpr .pc file +generate_pkgconfig( + "gpr" + "gRPC platform support library" + "${gRPC_CORE_VERSION}" + "" + "-lgpr" + "" + "gpr.pc") + +# grpc .pc file +generate_pkgconfig( + "gRPC" + "high performance general RPC framework" + "${gRPC_CORE_VERSION}" + "gpr" + "-lgrpc -laddress_sorting -lcares -lz" + "" + "grpc.pc") + +# grpc_unsecure .pc file +generate_pkgconfig( + "gRPC unsecure" + "high performance general RPC framework without SSL" + "${gRPC_CORE_VERSION}" + "gpr" + "-lgrpc_unsecure" + "" + "grpc_unsecure.pc") + +# grpc++ .pc file +generate_pkgconfig( + "gRPC++" + "C++ wrapper for gRPC" + "${PACKAGE_VERSION}" + "grpc" + "-lgrpc++" + "" + "grpc++.pc") + +# grpc++_unsecure .pc file +generate_pkgconfig( + "gRPC++ unsecure" + "C++ wrapper for gRPC without SSL" + "${PACKAGE_VERSION}" + "grpc_unsecure" + "-lgrpc++_unsecure" + "" + "grpc++_unsecure.pc") diff --git a/cmake/pkg-config-template.pc.in b/cmake/pkg-config-template.pc.in new file mode 100644 index 00000000000..d56154bb3a5 --- /dev/null +++ b/cmake/pkg-config-template.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +includedir=${prefix}/include +libdir=${exec_prefix}/lib + +Name: @PC_NAME@ +Description: @PC_DESCRIPTION@ +Version: @PC_VERSION@ +Cflags: -I${includedir} +Requires: @PC_REQUIRES@ +Libs: -L${libdir} @PC_LIB@ +Libs.private: @PC_LIBS_PRIVATE@ diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 77769cb93bf..e954d404178 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -73,10 +73,11 @@ set(PACKAGE_NAME "grpc") set(PACKAGE_VERSION "${settings.cpp_version}") + set(gRPC_CORE_VERSION "${settings.core_version}") set(PACKAGE_STRING "<%text>${PACKAGE_NAME} ${PACKAGE_VERSION}") set(PACKAGE_TARNAME "<%text>${PACKAGE_NAME}-${PACKAGE_VERSION}") set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/") - project(<%text>${PACKAGE_NAME} C CXX) + project(<%text>${PACKAGE_NAME} LANGUAGES C CXX) set(gRPC_INSTALL_BINDIR "bin" CACHE STRING "Installation directory for executables") set(gRPC_INSTALL_LIBDIR "lib" CACHE STRING "Installation directory for libraries") @@ -569,3 +570,71 @@ install(FILES <%text>${CMAKE_CURRENT_SOURCE_DIR}/etc/roots.pem DESTINATION <%text>${gRPC_INSTALL_SHAREDIR}) + + # Function to generate pkg-config files. + function(generate_pkgconfig name description version requires + libs libs_private output_filename) + set(PC_NAME "<%text>${name}") + set(PC_DESCRIPTION "<%text>${description}") + set(PC_VERSION "<%text>${version}") + set(PC_REQUIRES "<%text>${requires}") + set(PC_LIB "<%text>${libs}") + set(PC_LIBS_PRIVATE "<%text>${libs_private}") + set(output_filepath "<%text>${grpc_BINARY_DIR}/libs/opt/pkgconfig/${output_filename}") + configure_file( + "<%text>${grpc_SOURCE_DIR}/cmake/pkg-config-template.pc.in" + "<%text>${output_filepath}" + @ONLY) + install(FILES "<%text>${output_filepath}" + DESTINATION "lib/pkgconfig/") + endfunction() + + # gpr .pc file + generate_pkgconfig( + "gpr" + "gRPC platform support library" + "<%text>${gRPC_CORE_VERSION}" + "" + "-lgpr" + "" + "gpr.pc") + + # grpc .pc file + generate_pkgconfig( + "gRPC" + "high performance general RPC framework" + "<%text>${gRPC_CORE_VERSION}" + "gpr" + "-lgrpc -laddress_sorting -lcares -lz" + "" + "grpc.pc") + + # grpc_unsecure .pc file + generate_pkgconfig( + "gRPC unsecure" + "high performance general RPC framework without SSL" + "<%text>${gRPC_CORE_VERSION}" + "gpr" + "-lgrpc_unsecure" + "" + "grpc_unsecure.pc") + + # grpc++ .pc file + generate_pkgconfig( + "gRPC++" + "C++ wrapper for gRPC" + "<%text>${PACKAGE_VERSION}" + "grpc" + "-lgrpc++" + "" + "grpc++.pc") + + # grpc++_unsecure .pc file + generate_pkgconfig( + "gRPC++ unsecure" + "C++ wrapper for gRPC without SSL" + "<%text>${PACKAGE_VERSION}" + "grpc_unsecure" + "-lgrpc++_unsecure" + "" + "grpc++_unsecure.pc")