Skip to content

Commit 20b8060

Browse files
author
Alexander Damian
committed
Added options to conditionally disable installation of configuration files
1 parent ad800a5 commit 20b8060

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ option(CPPKAFKA_DISABLE_EXAMPLES "Disable build of cppkafka examples." OFF)
4444
option(CPPKAFKA_BOOST_STATIC_LIBS "Link with Boost static libraries." ON)
4545
option(CPPKAFKA_BOOST_USE_MULTITHREADED "Use Boost multithreaded libraries." ON)
4646
option(CPPKAFKA_RDKAFKA_STATIC_LIB "Link with Rdkafka static library." OFF)
47+
option(CPPKAFKA_EXPORT_PKGCONFIG "Generate 'cppkafka.pc' file" ON)
48+
option(CPPKAFKA_EXPORT_CMAKE_CONFIG "Generate CMake config, target and version files." ON)
4749

4850
# Add FindRdKafka.cmake
4951
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ The following cmake options can be specified:
8383
* `CPPKAFKA_RDKAFKA_STATIC_LIB` : Link to Rdkafka static library. Default is `OFF`.
8484
* `CPPKAFKA_CONFIG_DIR` : Install location of the cmake configuration files. Default is `lib/cmake/cppkafka`.
8585
* `CPPKAFKA_PKGCONFIG_DIR` : Install location of the .pc file. Default is `share/pkgconfig`.
86+
* `CPPKAFKA_EXPORT_PKGCONFIG` : Generate `cppkafka.pc` file. Default is `ON`.
87+
* `CPPKAFKA_EXPORT_CMAKE_CONFIG` : Generate CMake config, target and version files. Default is `ON`.
8688

8789
Example:
8890
```Shell

cmake/config.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(RDKAFKA_MIN_VERSION_HEX "@RDKAFKA_MIN_VERSION_HEX@")
1111
find_dependency(Boost REQUIRED)
1212

1313
# Try to find the RdKafka configuration file if present.
14-
# This will search default system locations as well as RdKafka_ROOT and RdKafka_Dir paths if specified.
14+
# This will search default system locations as well as RdKafka_ROOT and RdKafka_DIR paths if specified.
1515
find_package(RdKafka QUIET CONFIG)
1616
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
1717
if (NOT RdKafka_FOUND)

src/CMakeLists.txt

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,40 +64,44 @@ install(
6464
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
6565
)
6666

67-
# Install the exported file
68-
install(
69-
EXPORT "${TARGET_EXPORT_NAME}"
70-
NAMESPACE "${NAMESPACE}"
71-
COMPONENT config
72-
DESTINATION "${CPPKAFKA_CONFIG_DIR}"
73-
)
67+
if (CPPKAFKA_EXPORT_PKGCONFIG)
68+
# Generate and install pkgconfig file
69+
configure_file(${PROJECT_SOURCE_DIR}/cmake/cppkafka.pc.in ${PKG_CONFIG_FILE} @ONLY)
7470

75-
# Generate and install pkgconfig file
76-
configure_file(${PROJECT_SOURCE_DIR}/cmake/cppkafka.pc.in ${PKG_CONFIG_FILE} @ONLY)
71+
install(
72+
FILES ${PKG_CONFIG}
73+
DESTINATION "${CPPKAFKA_PKGCONFIG_DIR}"
74+
COMPONENT pkgconfig
75+
)
76+
endif()
7777

78-
install(
79-
FILES ${PKG_CONFIG}
80-
DESTINATION "${CPPKAFKA_PKGCONFIG_DIR}"
81-
COMPONENT pkgconfig
82-
)
78+
if (CPPKAFKA_EXPORT_CMAKE_CONFIG)
79+
# Install the exported file
80+
install(
81+
EXPORT "${TARGET_EXPORT_NAME}"
82+
NAMESPACE "${NAMESPACE}"
83+
COMPONENT config
84+
DESTINATION "${CPPKAFKA_CONFIG_DIR}"
85+
)
8386

84-
# Generate CMAKE configuration file and exported targets
85-
configure_package_config_file(
86-
"${PROJECT_SOURCE_DIR}/cmake/config.cmake.in"
87-
"${CONFIG_FILE}"
88-
INSTALL_DESTINATION "${CPPKAFKA_CONFIG_DIR}"
89-
PATH_VARS RDKAFKA_MIN_VERSION_HEX CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
90-
)
87+
# Generate CMAKE configuration file and exported targets
88+
configure_package_config_file(
89+
"${PROJECT_SOURCE_DIR}/cmake/config.cmake.in"
90+
"${CONFIG_FILE}"
91+
INSTALL_DESTINATION "${CPPKAFKA_CONFIG_DIR}"
92+
PATH_VARS RDKAFKA_MIN_VERSION_HEX CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
93+
)
9194

92-
# Generate version file
93-
write_basic_package_version_file(
94-
"${VERSION_FILE}"
95-
VERSION ${CPPKAFKA_VERSION}
96-
COMPATIBILITY AnyNewerVersion
97-
)
95+
# Generate version file
96+
write_basic_package_version_file(
97+
"${VERSION_FILE}"
98+
VERSION ${CPPKAFKA_VERSION}
99+
COMPATIBILITY AnyNewerVersion
100+
)
98101

99-
install(
100-
FILES "${CONFIG_FILE}" "${VERSION_FILE}" "${FIND_RDKAFKA_FILE}"
101-
DESTINATION "${CPPKAFKA_CONFIG_DIR}"
102-
COMPONENT config
103-
)
102+
install(
103+
FILES "${CONFIG_FILE}" "${VERSION_FILE}" "${FIND_RDKAFKA_FILE}"
104+
DESTINATION "${CPPKAFKA_CONFIG_DIR}"
105+
COMPONENT config
106+
)
107+
endif()

0 commit comments

Comments
 (0)