@@ -16,6 +16,8 @@ set(CPPKAFKA_VERSION "${CPPKAFKA_VERSION_MAJOR}.${CPPKAFKA_VERSION_MINOR}.${CPPK
1616set (RDKAFKA_MIN_VERSION "0.9.4" )
1717set (RDKAFKA_MIN_VERSION_HEX 0x00090400)
1818
19+ option (USE_CPP17 "Use C++17 features instead of Boost (still, if you don't have boost you can't build examples"  OFF )
20+ 1921if  (NOT  CMAKE_CXX_FLAGS )
2022 # Set default compile flags for the project 
2123 if (MSVC )
@@ -31,8 +33,13 @@ if (NOT CMAKE_CXX_FLAGS)
3133 set (CMAKE_CXX_FLAGS  "-Wall" )
3234 endif ()
3335endif ()
34- # Use C++17 
35- set (CMAKE_CXX_STANDARD 17)
36+ 37+ if (USE_CPP17)
38+  set (CMAKE_CXX_STANDARD 17)
39+  add_definitions ("-D_USE_CPP17" )
40+ else ()
41+  set (CMAKE_CXX_STANDARD 11)
42+ endif ()
3643
3744# Set output directories 
3845set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY  ${CMAKE_CURRENT_BINARY_DIR} /lib)
@@ -104,32 +111,11 @@ if (NOT CPPKAFKA_PKGCONFIG_DIR)
104111 set (CPPKAFKA_PKGCONFIG_DIR share/pkgconfig)
105112endif ()
106113
107- # Try to find the RdKafka configuration file if present. 
108- # This will search default system locations as well as RdKafka_ROOT and RdKafka_Dir paths if specified. 
109- find_package (RdKafka ${FIND_PACKAGE_QUIET}  CONFIG)
110- set (RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND} )
111- if  (NOT  RdKafka_FOUND)
112-  message (STATUS  "RdKafkaConfig.cmake not found. Attempting to find module instead..." )
113-  find_package (RdKafka REQUIRED ${FIND_PACKAGE_QUIET}  MODULE)
114-  if  (NOT  RdKafka_FOUND)
115-  message (FATAL_ERROR "RdKafka module not found. Please set RDKAFKA_ROOT to the install path or RDKAFKA_DIR pointing to the RdKafka configuration file location." )
116-  else ()
117-  message (STATUS  "RdKafka module found." )
118-  endif ()
119- else ()
120-  message (STATUS  "RdKafka configuration file found: ${RdKafka_CONFIG} " )
121- endif ()
122- 123- add_subdirectory (src)
124- add_subdirectory (include /cppkafka)
125- 126- # Examples target 
127- if  (NOT  CPPKAFKA_DISABLE_EXAMPLES)
114+ if (NOT  USE_CPP17 OR  NOT  CPPKAFKA_DISABLE_EXAMPLES OR  NOT  CPPKAFKA_DISABLE_TESTS)
128115 # Look for Boost (just need boost.optional headers here) 
129-  find_package (Boost ${FIND_PACKAGE_QUIET}  CONFIG)
116+  find_package (Boost REQUIRED ${FIND_PACKAGE_QUIET} )
117+ 130118 if  (Boost_FOUND)
131-  option (CPPKAFKA_BOOST_STATIC_LIBS "Link with Boost static libraries."  ON )
132-  option (CPPKAFKA_BOOST_USE_MULTITHREADED "Use Boost multithreaded libraries."  ON )
133119 find_package (Boost COMPONENTS program_options ${FIND_PACKAGE_QUIET} )
134120 set (Boost_USE_STATIC_LIBS ${CPPKAFKA_BOOST_STATIC_LIBS} )
135121 set (Boost_USE_MULTITHREADED ${CPPKAFKA_BOOST_USE_MULTITHREADED} )
@@ -142,12 +128,37 @@ if (NOT CPPKAFKA_DISABLE_EXAMPLES)
142128 message (STATUS  "Boost is multi-threaded: ${CPPKAFKA_BOOST_USE_MULTITHREADED} " )
143129 message (STATUS  "Boost libraries: ${Boost_LIBRARIES} " )
144130 endif ()
131+  endif ()
132+ 133+  # Examples target 
134+  if  (Boost_PROGRAM_OPTIONS_FOUND)
145135 add_subdirectory (examples)
146136 else ()
147137 message (STATUS  "Disabling examples" )
148138 endif ()
149139endif ()
150140
141+ # Try to find the RdKafka configuration file if present. 
142+ # This will search default system locations as well as RdKafka_ROOT and RdKafka_Dir paths if specified. 
143+ find_package (RdKafka ${FIND_PACKAGE_QUIET}  CONFIG)
144+ set (RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND} )
145+ if  (NOT  RdKafka_FOUND)
146+  message (STATUS  "RdKafkaConfig.cmake not found. Attempting to find module instead..." )
147+  find_package (RdKafka REQUIRED ${FIND_PACKAGE_QUIET}  MODULE)
148+  if  (NOT  RdKafka_FOUND)
149+  message (FATAL_ERROR "RdKafka module not found. Please set RDKAFKA_ROOT to the install path or RDKAFKA_DIR pointing to the RdKafka configuration file location." )
150+  else ()
151+  message (STATUS  "RdKafka module found." )
152+  endif ()
153+ else ()
154+  message (STATUS  "RdKafka configuration file found: ${RdKafka_CONFIG} " )
155+ endif ()
156+ 157+ add_subdirectory (src)
158+ add_subdirectory (include /cppkafka)
159+ 160+ 161+ 151162# Add a target to generate API documentation using Doxygen 
152163find_package (Doxygen ${FIND_PACKAGE_QUIET} )
153164if (DOXYGEN_FOUND)
@@ -188,4 +199,4 @@ if(NOT TARGET uninstall)
188199 # Add uninstall target 
189200 add_custom_target (uninstall
190201 COMMAND  ${CMAKE_COMMAND}  -P ${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake)
191- endif ()
202+ endif ()
0 commit comments