From 20b806037bb4f566861070c80890f273aba58a50 Mon Sep 17 00:00:00 2001 From: Alexander Damian Date: Wed, 3 Jul 2019 18:01:28 -0400 Subject: [PATCH] Added options to conditionally disable installation of configuration files --- CMakeLists.txt | 2 ++ README.md | 2 ++ cmake/config.cmake.in | 2 +- src/CMakeLists.txt | 68 +++++++++++++++++++++++-------------------- 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 45077bd..3caed5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,8 @@ option(CPPKAFKA_DISABLE_EXAMPLES "Disable build of cppkafka examples." OFF) option(CPPKAFKA_BOOST_STATIC_LIBS "Link with Boost static libraries." ON) option(CPPKAFKA_BOOST_USE_MULTITHREADED "Use Boost multithreaded libraries." ON) option(CPPKAFKA_RDKAFKA_STATIC_LIB "Link with Rdkafka static library." OFF) +option(CPPKAFKA_EXPORT_PKGCONFIG "Generate 'cppkafka.pc' file" ON) +option(CPPKAFKA_EXPORT_CMAKE_CONFIG "Generate CMake config, target and version files." ON) # Add FindRdKafka.cmake set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") diff --git a/README.md b/README.md index d0243c8..5301930 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ The following cmake options can be specified: * `CPPKAFKA_RDKAFKA_STATIC_LIB` : Link to Rdkafka static library. Default is `OFF`. * `CPPKAFKA_CONFIG_DIR` : Install location of the cmake configuration files. Default is `lib/cmake/cppkafka`. * `CPPKAFKA_PKGCONFIG_DIR` : Install location of the .pc file. Default is `share/pkgconfig`. +* `CPPKAFKA_EXPORT_PKGCONFIG` : Generate `cppkafka.pc` file. Default is `ON`. +* `CPPKAFKA_EXPORT_CMAKE_CONFIG` : Generate CMake config, target and version files. Default is `ON`. Example: ```Shell diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 89a4e4d..32f4398 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -11,7 +11,7 @@ set(RDKAFKA_MIN_VERSION_HEX "@RDKAFKA_MIN_VERSION_HEX@") find_dependency(Boost REQUIRED) # Try to find the RdKafka configuration file if present. -# This will search default system locations as well as RdKafka_ROOT and RdKafka_Dir paths if specified. +# This will search default system locations as well as RdKafka_ROOT and RdKafka_DIR paths if specified. find_package(RdKafka QUIET CONFIG) set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND}) if (NOT RdKafka_FOUND) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c49b600..4c23cfc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,40 +64,44 @@ install( INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) -# Install the exported file -install( - EXPORT "${TARGET_EXPORT_NAME}" - NAMESPACE "${NAMESPACE}" - COMPONENT config - DESTINATION "${CPPKAFKA_CONFIG_DIR}" -) +if (CPPKAFKA_EXPORT_PKGCONFIG) + # Generate and install pkgconfig file + configure_file(${PROJECT_SOURCE_DIR}/cmake/cppkafka.pc.in ${PKG_CONFIG_FILE} @ONLY) -# Generate and install pkgconfig file -configure_file(${PROJECT_SOURCE_DIR}/cmake/cppkafka.pc.in ${PKG_CONFIG_FILE} @ONLY) + install( + FILES ${PKG_CONFIG} + DESTINATION "${CPPKAFKA_PKGCONFIG_DIR}" + COMPONENT pkgconfig + ) +endif() -install( - FILES ${PKG_CONFIG} - DESTINATION "${CPPKAFKA_PKGCONFIG_DIR}" - COMPONENT pkgconfig -) +if (CPPKAFKA_EXPORT_CMAKE_CONFIG) + # Install the exported file + install( + EXPORT "${TARGET_EXPORT_NAME}" + NAMESPACE "${NAMESPACE}" + COMPONENT config + DESTINATION "${CPPKAFKA_CONFIG_DIR}" + ) -# Generate CMAKE configuration file and exported targets -configure_package_config_file( - "${PROJECT_SOURCE_DIR}/cmake/config.cmake.in" - "${CONFIG_FILE}" - INSTALL_DESTINATION "${CPPKAFKA_CONFIG_DIR}" - PATH_VARS RDKAFKA_MIN_VERSION_HEX CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR -) + # Generate CMAKE configuration file and exported targets + configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/config.cmake.in" + "${CONFIG_FILE}" + INSTALL_DESTINATION "${CPPKAFKA_CONFIG_DIR}" + PATH_VARS RDKAFKA_MIN_VERSION_HEX CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR + ) -# Generate version file -write_basic_package_version_file( - "${VERSION_FILE}" - VERSION ${CPPKAFKA_VERSION} - COMPATIBILITY AnyNewerVersion -) + # Generate version file + write_basic_package_version_file( + "${VERSION_FILE}" + VERSION ${CPPKAFKA_VERSION} + COMPATIBILITY AnyNewerVersion + ) -install( - FILES "${CONFIG_FILE}" "${VERSION_FILE}" "${FIND_RDKAFKA_FILE}" - DESTINATION "${CPPKAFKA_CONFIG_DIR}" - COMPONENT config -) + install( + FILES "${CONFIG_FILE}" "${VERSION_FILE}" "${FIND_RDKAFKA_FILE}" + DESTINATION "${CPPKAFKA_CONFIG_DIR}" + COMPONENT config + ) +endif()