@@ -134,32 +134,21 @@ else ()
134134endif ()
135135
136136# ----------------------------------------------------------------------------
137- # Force-deactivate optional dependencies
137+ # Force-(de)activate optional dependencies
138138# ----------------------------------------------------------------------------
139139
140- # Cereal is auto-detected by default, i.e. used if found, not used if not found.
141- # You can optionally set a hard requirement so a build fails without cereal,
142- # or you can force-disable cereal even if present on the system.
143- option (SEQAN3_CEREAL "Require cereal and fail if not present." OFF )
144- option (SEQAN3_NO_CEREAL "Don't use cereal, even if present." OFF )
140+ # https://cmake.org/cmake/help/latest/variable/CMAKE_DISABLE_FIND_PACKAGE_PackageName.html
141+ # https://cmake.org/cmake/help/latest/variable/CMAKE_REQUIRE_FIND_PACKAGE_PackageName.html
145142
146- if (SEQAN3_CEREAL AND SEQAN3_NO_CEREAL)
147- # this is always a user error, therefore we always error-out, even if SeqAn is not required
148- message (FATAL_ERROR "You may not specify SEQAN3_CEREAL and SEQAN3_NO_CEREAL at the same time.\n\
149- You can specify neither (use auto-detection), or specify either to force on/off." )
150- return ()
151- endif ()
152-
153- if (SEQAN3_CEREAL)
154- set (SEQAN3_DEFINITIONS ${SEQAN3_DEFINITIONS} "-DSEQAN3_WITH_CEREAL=1" )
155- elseif (SEQAN3_NO_CEREAL)
156- set (SEQAN3_DEFINITIONS ${SEQAN3_DEFINITIONS} "-DSEQAN3_WITH_CEREAL=0" )
157- endif ()
143+ ## Example for deactivating
144+ # cmake <path> -DCMAKE_DISABLE_FIND_PACKAGE_ZLIB=TRUE
145+ # -DCMAKE_DISABLE_FIND_PACKAGE_BZip2=TRUE
146+ # -DCMAKE_DISABLE_FIND_PACKAGE_cereal=TRUE
158147
159- # These two are "opt-in", because detected by CMake
160- # If you want to force-require these, just do find_package (zlib REQUIRED) before find_package (seqan3)
161- option (SEQAN3_NO_ZLIB "Don't use ZLIB, even if present." OFF )
162- option (SEQAN3_NO_BZIP2 "Don't use BZip2, even if present." OFF )
148+ ## Example for requiring
149+ # cmake <path> -DCMAKE_REQUIRE_FIND_PACKAGE_ZLIB=TRUE
150+ # -DCMAKE_REQUIRE_FIND_PACKAGE_BZip2=TRUE
151+ # -DCMAKE_REQUIRE_FIND_PACKAGE_cereal=TRUE
163152
164153# ----------------------------------------------------------------------------
165154# Check supported compilers
@@ -180,8 +169,8 @@ endif ()
180169set (THREADS_PREFER_PTHREAD_FLAG TRUE )
181170find_package (Threads QUIET )
182171
183- if (Threads_FOUND )
184- set (SEQAN3_LIBRARIES ${ SEQAN3_LIBRARIES} Threads::Threads)
172+ if (TARGET Threads::Threads )
173+ list ( APPEND SEQAN3_LIBRARIES Threads::Threads)
185174 if ("${CMAKE_THREAD_LIBS_INIT} " STREQUAL "" )
186175 seqan3_config_print ("Thread support: builtin." )
187176 else ()
@@ -192,114 +181,70 @@ else ()
192181endif ()
193182
194183# ----------------------------------------------------------------------------
195- # Cereal dependency is optional, but may set as required
184+ # Cereal dependency
196185# ----------------------------------------------------------------------------
197186
198- if (NOT SEQAN3_NO_CEREAL)
199- find_path (SEQAN3_CEREAL_INCLUDE_DIR
200- NAMES cereal/version .hpp
201- HINTS "${SEQAN3_INCLUDE_DIR} /seqan3/vendor" )
187+ if (SEQAN3_HAS_CPM AND NOT CMAKE_DISABLE_FIND_PACKAGE_cereal )
188+ CPMGetPackage (cereal)
189+ else ()
190+ find_package (cereal CONFIG QUIET )
191+ endif ()
202192
203- # 1) Check the vendor directory of SeqAn3. This directory exists for source packages and installed packages.
204- if (SEQAN3_CEREAL_INCLUDE_DIR)
205- if (SEQAN3_CEREAL)
206- seqan3_config_print ("Required dependency: Cereal found." )
207- else ()
208- seqan3_config_print ("Optional dependency: Cereal found." )
209- endif ()
210- set (SEQAN3_DEPENDENCY_INCLUDE_DIRS ${SEQAN3_CEREAL_INCLUDE_DIR} ${SEQAN3_DEPENDENCY_INCLUDE_DIRS} )
211- # 2) Get package via CPM.
212- elseif (SEQAN3_HAS_CPM)
213- CPMGetPackage (cereal)
214-
215- find_path (SEQAN3_CEREAL_INCLUDE_DIR
216- NAMES cereal/version .hpp
217- HINTS "${cereal_SOURCE_DIR} /include" )
218-
219- if (SEQAN3_CEREAL_INCLUDE_DIR)
220- if (SEQAN3_CEREAL)
221- seqan3_config_print ("Required dependency: Cereal found." )
222- else ()
223- seqan3_config_print ("Optional dependency: Cereal found." )
224- endif ()
225- set (SEQAN3_DEPENDENCY_INCLUDE_DIRS ${SEQAN3_CEREAL_INCLUDE_DIR} ${SEQAN3_DEPENDENCY_INCLUDE_DIRS} )
226- else ()
227- if (SEQAN3_CEREAL)
228- seqan3_config_error ("The (optional) cereal library was marked as required, but wasn't found." )
229- else ()
230- seqan3_config_print ("Optional dependency: Cereal not found." )
231- endif ()
232- endif ()
233- else ()
234- if (SEQAN3_CEREAL)
235- seqan3_config_error ("The (optional) cereal library was marked as required, but wasn't found." )
236- else ()
237- seqan3_config_print ("Optional dependency: Cereal not found." )
238- endif ()
239- endif ()
193+ if (TARGET cereal::cereal)
194+ list (APPEND SEQAN3_LIBRARIES cereal::cereal)
195+ seqan3_config_print ("Optional dependency: Cereal found." )
196+ else ()
197+ set (SEQAN3_DEFINITIONS ${SEQAN3_DEFINITIONS} "-DSEQAN3_HAS_CEREAL=0" )
198+ seqan3_config_print ("Optional dependency: Cereal not found." )
240199endif ()
241200
242201# ----------------------------------------------------------------------------
243202# ZLIB dependency
244203# ----------------------------------------------------------------------------
245204
246- if (NOT SEQAN3_NO_ZLIB)
247- find_package (ZLIB QUIET )
248- endif ()
205+ find_package (ZLIB QUIET )
249206
250- if (ZLIB_FOUND)
251- set (SEQAN3_LIBRARIES ${SEQAN3_LIBRARIES} ${ZLIB_LIBRARIES} )
252- set (SEQAN3_DEPENDENCY_INCLUDE_DIRS ${SEQAN3_DEPENDENCY_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} )
253- set (SEQAN3_DEFINITIONS ${SEQAN3_DEFINITIONS} "-DSEQAN3_HAS_ZLIB=1" )
207+ if (TARGET ZLIB::ZLIB)
208+ list (APPEND SEQAN3_LIBRARIES ZLIB::ZLIB)
254209 seqan3_config_print ("Optional dependency: ZLIB-${ZLIB_VERSION_STRING} found." )
255210else ()
211+ set (SEQAN3_DEFINITIONS ${SEQAN3_DEFINITIONS} "-DSEQAN3_HAS_ZLIB=0" )
256212 seqan3_config_print ("Optional dependency: ZLIB not found." )
257213endif ()
258214
259215# ----------------------------------------------------------------------------
260216# BZip2 dependency
261217# ----------------------------------------------------------------------------
262218
263- if (NOT SEQAN3_NO_BZIP2)
264- find_package (BZip2 QUIET )
265- endif ()
219+ find_package (BZip2 QUIET )
266220
267- if (NOT ZLIB_FOUND AND BZIP2_FOUND)
268- # NOTE (marehr): iostream_bzip2 uses the type `uInt`, which is defined by
269- # `zlib`. Therefore, `bzip2` will cause a ton of errors without `zlib`.
270- message (AUTHOR_WARNING "Disabling BZip2 [which was successfully found], "
271- "because ZLIB was not found. BZip2 depends on ZLIB." )
272- unset (BZIP2_FOUND)
273- endif ()
274-
275- if (BZIP2_FOUND)
276- set (SEQAN3_LIBRARIES ${SEQAN3_LIBRARIES} ${BZIP2_LIBRARIES} )
277- set (SEQAN3_DEPENDENCY_INCLUDE_DIRS ${SEQAN3_DEPENDENCY_INCLUDE_DIRS} ${BZIP2_INCLUDE_DIRS} )
278- set (SEQAN3_DEFINITIONS ${SEQAN3_DEFINITIONS} "-DSEQAN3_HAS_BZIP2=1" )
221+ if (TARGET ZLIB::ZLIB AND TARGET BZip2::BZip2)
222+ list (APPEND SEQAN3_LIBRARIES BZip2::BZip2)
279223 seqan3_config_print ("Optional dependency: BZip2-${BZIP2_VERSION_STRING} found." )
280224else ()
225+ set (SEQAN3_DEFINITIONS ${SEQAN3_DEFINITIONS} "-DSEQAN3_HAS_BZIP2=0" )
281226 seqan3_config_print ("Optional dependency: BZip2 not found." )
282227endif ()
283228
229+ if (NOT TARGET ZLIB::ZLIB AND TARGET BZip2::BZip2)
230+ message (AUTHOR_WARNING "BZip2 was found but ZLIB was not found. BZip2 requires ZLIB." )
231+ endif ()
232+
284233# ----------------------------------------------------------------------------
285234# System dependencies
286235# ----------------------------------------------------------------------------
287236
288237# librt
289- if ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
290- OR (${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" )
291- OR (${CMAKE_SYSTEM_NAME} STREQUAL "GNU" ))
292- set (SEQAN3_LIBRARIES ${SEQAN3_LIBRARIES} rt)
238+ find_library (SEQAN3_RT_LIB rt)
239+ if (SEQAN3_RT_LIB)
240+ list (APPEND SEQAN3_LIBRARIES ${SEQAN3_RT_LIB} )
293241endif ()
294242
295243# libexecinfo -- implicit
296- check_include_file_cxx (execinfo.h _SEQAN3_HAVE_EXECINFO )
297- mark_as_advanced (_SEQAN3_HAVE_EXECINFO )
298- if (_SEQAN3_HAVE_EXECINFO )
244+ find_package (Backtrace QUIET )
245+ if ( TARGET Backtrace::Backtrace )
246+ list ( APPEND SEQAN3_LIBRARIES Backtrace::Backtrace )
299247 seqan3_config_print ("Optional dependency: libexecinfo found." )
300- if ((${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" ) OR (${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" ))
301- set (SEQAN3_LIBRARIES ${SEQAN3_LIBRARIES} execinfo elf)
302- endif ()
303248else ()
304249 seqan3_config_print ("Optional dependency: libexecinfo not found." )
305250endif ()
@@ -308,19 +253,17 @@ endif ()
308253# Perform compilability test of platform.hpp (tests some requirements)
309254# ----------------------------------------------------------------------------
310255
311- set (CXXSTD_TEST_SOURCE "#include <seqan3/core/platform.hpp>
312- int main() {}" )
313-
314- # using try_compile instead of check_cxx_source_compiles to capture output in case of failure
315- file (WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /CMakeTmp/src.cxx" "${CXXSTD_TEST_SOURCE} \n " )
316-
317256# cmake-format: off
257+ # Note: With CMake >= 3.25, the file WRITE can be removed, the second and third line in try_compile can be replaced by
258+ # SOURCE_FROM_CONTENT "platform_test.cpp" "#include <seqan3/core/platform.hpp>\nint main() {}"
259+ file (WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /CMakeTmp/platform_test.cpp"
260+ "#include <seqan3/core/platform.hpp>\n int main() {}" )
261+
318262try_compile (SEQAN3_PLATFORM_TEST
319263 ${CMAKE_BINARY_DIR}
320- ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /CMakeTmp/src.cxx
321- CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_INCLUDE_PATH} ; ${ SEQAN3_INCLUDE_DIR} ; ${SEQAN3_DEPENDENCY_INCLUDE_DIRS } "
264+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /CMakeTmp/platform_test.cpp
265+ CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${SEQAN3_INCLUDE_DIR} "
322266 COMPILE_DEFINITIONS ${SEQAN3_DEFINITIONS}
323- LINK_LIBRARIES ${SEQAN3_LIBRARIES}
324267 CXX_STANDARD 23
325268 CXX_STANDARD_REQUIRED ON
326269 CXX_EXTENSIONS OFF
@@ -358,7 +301,7 @@ foreach (package_var
358301endforeach ()
359302
360303# propagate SEQAN3_INCLUDE_DIR into SEQAN3_INCLUDE_DIRS
361- set (SEQAN3_INCLUDE_DIRS ${SEQAN3_INCLUDE_DIR} ${SEQAN3_DEPENDENCY_INCLUDE_DIRS} )
304+ set (SEQAN3_INCLUDE_DIRS ${SEQAN3_INCLUDE_DIR} )
362305
363306# ----------------------------------------------------------------------------
364307# Export targets
@@ -371,9 +314,6 @@ if (SEQAN3_FOUND AND NOT TARGET seqan3::seqan3)
371314 target_link_libraries (seqan3_seqan3 INTERFACE "${SEQAN3_LIBRARIES} " )
372315 # include seqan3/include/ as -I, because seqan3 should never produce warnings.
373316 target_include_directories (seqan3_seqan3 INTERFACE "${SEQAN3_INCLUDE_DIR} " )
374- # include everything except seqan3/include/ as -isystem, i.e.
375- # a system header which suppresses warnings of external libraries.
376- target_include_directories (seqan3_seqan3 SYSTEM INTERFACE "${SEQAN3_DEPENDENCY_INCLUDE_DIRS} " )
377317 add_library (seqan3::seqan3 ALIAS seqan3_seqan3)
378318endif ()
379319
0 commit comments