11cmake_minimum_required (VERSION 3.13 )
22
3- project (condy LANGUAGES CXX )
4-
5- option (BUILD_EXAMPLES "Build examples" OFF )
6- option (BUILD_BENCHMARKS "Build benchmarks" OFF )
7- option (BUILD_TESTS "Build tests" OFF )
8- option (BUILD_MODULE "Build C++ module interface" OFF )
9- option (ENABLE_CLANG_TIDY "Enable clang-tidy static analysis" OFF )
10- option (TESTS_STATIC_LINK "Use static linking for tests" OFF )
11- option (TESTS_TSAN "Enable thread sanitizer for tests" OFF )
12- option (TESTS_ASAN "Enable address and undefined behavior sanitizers for tests" OFF )
13- option (LINK_LIBURING "Use liburing from third_party and link it to condy" ON )
14-
15- if (ENABLE_CLANG_TIDY)
16- find_program (CLANG_TIDY_EXE NAMES "clang-tidy" )
17- if (CLANG_TIDY_EXE)
18- message (STATUS "Found clang-tidy: ${CLANG_TIDY_EXE} " )
19- set (CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE} " )
20- else ()
21- message (WARNING "clang-tidy not found, static analysis will be disabled" )
22- endif ()
3+ # Version is defined once in the version header.
4+ set (CONDY_VERSION_HEADER include/condy/version.hpp)
5+ file (READ ${CONDY_VERSION_HEADER} _condy_version_h )
6+ string (REGEX MATCH "#define CONDY_VERSION_MAJOR ([0-9]+)" _condy_ver_m "${_condy_version_h} " )
7+ set (CONDY_VERSION_MAJOR ${CMAKE_MATCH_1} )
8+ string (REGEX MATCH "#define CONDY_VERSION_MINOR ([0-9]+)" _condy_ver_m "${_condy_version_h} " )
9+ set (CONDY_VERSION_MINOR ${CMAKE_MATCH_1} )
10+ if (NOT CONDY_VERSION_MAJOR OR NOT CONDY_VERSION_MINOR)
11+ message (FATAL_ERROR "Failed to parse version from ${CONDY_VERSION_HEADER} " )
2312endif ()
13+ set (CONDY_VERSION_STRING "v${CONDY_VERSION_MAJOR} .${CONDY_VERSION_MINOR} " )
14+
15+ project (condy VERSION ${CONDY_VERSION_MAJOR} .${CONDY_VERSION_MINOR} LANGUAGES CXX )
16+ message (STATUS "Configuring condy ${CONDY_VERSION_STRING} " )
17+
18+ option (CONDY_BUILD_EXAMPLES "Build examples" OFF )
19+ option (CONDY_BUILD_BENCHMARKS "Build benchmarks" OFF )
20+ option (CONDY_BUILD_TESTS "Build tests" OFF )
21+ option (CONDY_BUILD_MODULE "Build C++ module interface" OFF )
22+ option (CONDY_BUILD_DOCS "Build Doxygen documentation" OFF )
23+ option (CONDY_TESTS_STATIC_LINK "Use static linking for tests" OFF )
24+ option (CONDY_TESTS_TSAN "Enable thread sanitizer for tests" OFF )
25+ option (CONDY_TESTS_ASAN "Enable address and undefined behavior sanitizers for tests" OFF )
26+ option (CONDY_LINK_LIBURING "Use liburing and link it to condy" ON )
27+ set (CONDY_LINK_LIBURING_VERSION "2.15" CACHE STRING "liburing version to fetch and link" )
28+
29+ # Backward compatibility for the unprefixed option names.
30+ macro (condy_legacy_option legacy new )
31+ if (DEFINED ${legacy} )
32+ message (DEPRECATION "The ${legacy} option is deprecated, use ${new} instead" )
33+ get_property (_condy_${new} _desc CACHE ${new} PROPERTY HELPSTRING)
34+ set (${new} ${${legacy} } CACHE BOOL "${_condy_${new} _desc}" FORCE )
35+ endif ()
36+ endmacro ()
37+ condy_legacy_option (BUILD_EXAMPLES CONDY_BUILD_EXAMPLES )
38+ condy_legacy_option (BUILD_BENCHMARKS CONDY_BUILD_BENCHMARKS )
39+ condy_legacy_option (BUILD_TESTS CONDY_BUILD_TESTS )
40+ condy_legacy_option (BUILD_MODULE CONDY_BUILD_MODULE )
41+ condy_legacy_option (TESTS_STATIC_LINK CONDY_TESTS_STATIC_LINK )
42+ condy_legacy_option (TESTS_TSAN CONDY_TESTS_TSAN )
43+ condy_legacy_option (TESTS_ASAN CONDY_TESTS_ASAN )
44+ condy_legacy_option (LINK_LIBURING CONDY_LINK_LIBURING )
45+
46+ include (FetchContent )
47+
48+ set (DOXYGEN_AWESOME_CSS_VERSION v2.4.1)
49+ set (DOCTEST_VERSION v2.5.0)
50+ set (LIBURING_VERSION liburing-${CONDY_LINK_LIBURING_VERSION} )
51+
52+ FetchContent_Declare (
53+ doxygen-awesome-css
54+ URL https://raw.githubusercontent.com/jothepro/doxygen-awesome-css/${DOXYGEN_AWESOME_CSS_VERSION} /doxygen-awesome.css
55+ DOWNLOAD_NO_EXTRACT TRUE
56+ )
57+ FetchContent_Declare (
58+ doctest
59+ URL https://raw.githubusercontent.com/doctest/doctest/${DOCTEST_VERSION} /doctest/doctest.h
60+ DOWNLOAD_NO_EXTRACT TRUE
61+ )
62+ FetchContent_Declare (
63+ liburing
64+ URL https://github.com/axboe/liburing/archive/refs/tags/${LIBURING_VERSION} .tar.gz
65+ DOWNLOAD_EXTRACT_TIMESTAMP TRUE
66+ )
2467
2568add_library (condy INTERFACE )
2669target_include_directories (condy INTERFACE include )
2770target_compile_features (condy INTERFACE cxx_std_20 )
2871
29- if (BUILD_EXAMPLES OR BUILD_BENCHMARKS OR BUILD_TESTS OR LINK_LIBURING OR BUILD_MODULE )
72+ if (CONDY_BUILD_EXAMPLES OR CONDY_BUILD_BENCHMARKS OR CONDY_BUILD_TESTS OR CONDY_LINK_LIBURING )
3073 enable_language (C )
3174 include (ExternalProject )
3275
@@ -38,30 +81,30 @@ if(BUILD_EXAMPLES OR BUILD_BENCHMARKS OR BUILD_TESTS OR LINK_LIBURING OR BUILD_M
3881 endif ()
3982
4083 # liburing
41- set ( LIBURING_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } /third_party/liburing )
42- message ( STATUS "Configuring liburing in ${ LIBURING_SOURCE_DIR } " )
84+ message ( STATUS "Fetching liburing ${LIBURING_VERSION} " )
85+ FetchContent_MakeAvailable ( liburing)
4386
4487 ExternalProject_Add (
4588 liburing_ext
46- SOURCE_DIR ${LIBURING_SOURCE_DIR }
89+ SOURCE_DIR ${liburing_SOURCE_DIR }
4790 CONFIGURE_COMMAND ./configure --cc=${CMAKE_C_COMPILER } --cxx=${CMAKE_CXX_COMPILER }
4891 BUILD_COMMAND ${MAKE_EXECUTABLE} -C src
4992 BUILD_IN_SOURCE 1
5093 INSTALL_COMMAND ""
51- BUILD_BYPRODUCTS ${LIBURING_SOURCE_DIR } /src/liburing.a
94+ BUILD_BYPRODUCTS ${liburing_SOURCE_DIR } /src/liburing.a
5295 )
5396
5497 add_library (uring STATIC IMPORTED GLOBAL )
55- set_target_properties (uring PROPERTIES IMPORTED_LOCATION ${LIBURING_SOURCE_DIR } /src/liburing.a)
56- target_include_directories (uring INTERFACE ${LIBURING_SOURCE_DIR } /src/include )
98+ set_target_properties (uring PROPERTIES IMPORTED_LOCATION ${liburing_SOURCE_DIR } /src/liburing.a)
99+ target_include_directories (uring INTERFACE ${liburing_SOURCE_DIR } /src/include )
57100 add_dependencies (uring liburing_ext )
58101endif ()
59102
60- if (LINK_LIBURING )
103+ if (CONDY_LINK_LIBURING )
61104 target_link_libraries (condy INTERFACE uring )
62105endif ()
63106
64- if (BUILD_MODULE )
107+ if (CONDY_BUILD_MODULE )
65108 set (CMAKE_CXX_SCAN_FOR_MODULES ON )
66109 message (STATUS "Configuring C++ module interface in ${CMAKE_CURRENT_SOURCE_DIR } /module" )
67110 add_subdirectory (module )
@@ -78,20 +121,22 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
78121 add_compile_options (-Wno-maybe-uninitialized )
79122endif ()
80123
81- if (BUILD_EXAMPLES )
124+ if (CONDY_BUILD_EXAMPLES )
82125 message (STATUS "Configuring examples in ${CMAKE_CURRENT_SOURCE_DIR } /examples" )
83126 add_subdirectory (examples )
84127endif ()
85128
86- if (BUILD_BENCHMARKS )
129+ if (CONDY_BUILD_BENCHMARKS )
87130 message (STATUS "Configuring benchmarks in ${CMAKE_CURRENT_SOURCE_DIR } /benchmarks" )
88131 add_subdirectory (benchmarks )
89132endif ()
90133
91- if (BUILD_TESTS)
92- # doctest
93- add_subdirectory (third_party/doctest )
134+ if (CONDY_BUILD_TESTS)
94135 message (STATUS "Configuring tests in ${CMAKE_CURRENT_SOURCE_DIR } /tests" )
95136 enable_testing ()
96137 add_subdirectory (tests )
138+ endif ()
139+
140+ if (CONDY_BUILD_DOCS)
141+ add_subdirectory (docs )
97142endif ()
0 commit comments