Skip to content

Commit 958e9be

Browse files
authored
refactor cmake configuration (#172)
* remove useless option * cmake extract version * add cmake option prefix * add docs target * fetch doxygen-css * fetch doctest * fetch liburing
1 parent 7058a1c commit 958e9be

45 files changed

Lines changed: 198 additions & 154 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci-latest-kernel.yml‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ jobs:
2121
timeout-minutes: 30
2222

2323
steps:
24-
- name: Checkout Repository and Submodules
24+
- name: Checkout Repository
2525
uses: actions/checkout@v4
26-
with:
27-
submodules: true
2826

2927
- name: Update Apt Packages
3028
run: sudo apt-get update
@@ -69,13 +67,13 @@ jobs:
6967
- name: Configure CMake
7068
run: |
7169
cmake -B ${{github.workspace}}/build \
72-
-DBUILD_EXAMPLES=ON \
73-
-DBUILD_BENCHMARKS=ON \
74-
-DBUILD_TESTS=ON \
70+
-DCONDY_BUILD_EXAMPLES=ON \
71+
-DCONDY_BUILD_BENCHMARKS=ON \
72+
-DCONDY_BUILD_TESTS=ON \
7573
-DCMAKE_C_COMPILER=clang \
7674
-DCMAKE_CXX_COMPILER=clang++ \
7775
-DCMAKE_BUILD_TYPE=Release \
78-
-DTESTS_STATIC_LINK=ON
76+
-DCONDY_TESTS_STATIC_LINK=ON
7977
8078
- name: Build
8179
run: cmake --build ${{github.workspace}}/build -j$(nproc)

‎.github/workflows/ci-main.yml‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,8 @@ jobs:
2929
sanitizer: [ tsan, asan ]
3030

3131
steps:
32-
- name: Checkout Repository and Submodules
32+
- name: Checkout Repository
3333
uses: actions/checkout@v4
34-
with:
35-
submodules: true
36-
37-
- name: Checkout Liburing to Specified Version
38-
run: |
39-
cd ./third_party/liburing
40-
git fetch --tags
41-
git checkout liburing-${{ env.LIBURING_VERSION }}
42-
cd ../../
4334

4435
# GCC 15 Regression https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124584
4536
- name: Install GCC 14
@@ -57,14 +48,15 @@ jobs:
5748
echo "Using compiler: $COMPILER"
5849
SANITIZER_FLAG=""
5950
if [ "${{ matrix.sanitizer }}" = "tsan" ]; then
60-
SANITIZER_FLAG="-DTESTS_TSAN=ON"
51+
SANITIZER_FLAG="-DCONDY_TESTS_TSAN=ON"
6152
elif [ "${{ matrix.sanitizer }}" = "asan" ]; then
62-
SANITIZER_FLAG="-DTESTS_ASAN=ON"
53+
SANITIZER_FLAG="-DCONDY_TESTS_ASAN=ON"
6354
fi
6455
cmake -B ${{github.workspace}}/build \
65-
-DBUILD_EXAMPLES=ON \
66-
-DBUILD_BENCHMARKS=ON \
67-
-DBUILD_TESTS=ON \
56+
-DCONDY_BUILD_EXAMPLES=ON \
57+
-DCONDY_BUILD_BENCHMARKS=ON \
58+
-DCONDY_BUILD_TESTS=ON \
59+
-DCONDY_LINK_LIBURING_VERSION=${{ env.LIBURING_VERSION }} \
6860
$SANITIZER_FLAG \
6961
-DCMAKE_C_COMPILER=${{matrix.compiler.cc}} \
7062
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}} \

‎.github/workflows/ci-static-check.yml‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,20 @@ jobs:
3131
steps:
3232
- name: Checkout Repository
3333
uses: actions/checkout@v4
34-
with:
35-
submodules: true
36-
37-
- name: Configure liburing
38-
run: |
39-
cd third_party/liburing
40-
./configure --cc=clang --cxx=clang++
4134

4235
- name: Configure CMake
4336
run: |
4437
cmake -B ${{github.workspace}}/build \
45-
-DBUILD_EXAMPLES=ON \
46-
-DBUILD_BENCHMARKS=ON \
47-
-DBUILD_TESTS=ON \
38+
-DCONDY_BUILD_EXAMPLES=ON \
39+
-DCONDY_BUILD_BENCHMARKS=ON \
40+
-DCONDY_BUILD_TESTS=ON \
4841
-DCMAKE_C_COMPILER=clang \
4942
-DCMAKE_CXX_COMPILER=clang++ \
5043
-DCMAKE_BUILD_TYPE=Debug \
5144
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
5245
46+
- name: Build liburing
47+
run: cmake --build ${{github.workspace}}/build --target liburing_ext
48+
5349
- name: Static Analysis
5450
run: bash ./scripts/check-all.sh

‎.github/workflows/ci-toolchain.yml‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,17 @@ jobs:
2727
generator: [ "Ninja", "Unix Makefiles" ]
2828

2929
steps:
30-
- name: Checkout Repository and Submodules
30+
- name: Checkout Repository
3131
uses: actions/checkout@v4
32-
with:
33-
submodules: true
34-
35-
- name: Checkout Liburing Version
36-
run: |
37-
cd ./third_party/liburing
38-
git fetch --tags
39-
git checkout liburing-${{ matrix.liburing-version }}
40-
cd ../../
4132

4233
- name: Configure CMake
4334
run: |
4435
cmake -B ${{github.workspace}}/build \
4536
-G "${{ matrix.generator }}" \
46-
-DBUILD_EXAMPLES=ON \
47-
-DBUILD_BENCHMARKS=ON \
48-
-DBUILD_TESTS=ON \
37+
-DCONDY_BUILD_EXAMPLES=ON \
38+
-DCONDY_BUILD_BENCHMARKS=ON \
39+
-DCONDY_BUILD_TESTS=ON \
40+
-DCONDY_LINK_LIBURING_VERSION=${{ matrix.liburing-version }} \
4941
-DCMAKE_C_COMPILER=${{ matrix.compiler.cc }} \
5042
-DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} \
5143
-DCMAKE_BUILD_TYPE=Debug
@@ -66,8 +58,9 @@ jobs:
6658
&& !(matrix.compiler.cc == 'gcc' && matrix.liburing-version == '2.3')
6759
run: |
6860
cmake -B ${{github.workspace}}/build_module -G Ninja \
69-
-DBUILD_MODULE=ON \
70-
-DBUILD_EXAMPLES=ON \
61+
-DCONDY_BUILD_MODULE=ON \
62+
-DCONDY_BUILD_EXAMPLES=ON \
63+
-DCONDY_LINK_LIBURING_VERSION=${{ matrix.liburing-version }} \
7164
-DCMAKE_C_COMPILER=${{ matrix.compiler.cc }} \
7265
-DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }}
7366
ninja -C ${{github.workspace}}/build_module module-hello

‎.github/workflows/deploy-docs.yml‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ jobs:
2323
- name: Checkout Repository
2424
uses: actions/checkout@v4
2525

26-
- name: Checkout Doxygen Style
27-
run: |
28-
git submodule update --init --depth 1 ./third_party/doxygen-awesome-css
29-
3026
- name: Install Doxygen
3127
run: |
3228
sudo apt-get update
@@ -36,14 +32,16 @@ jobs:
3632
id: pages
3733
uses: actions/configure-pages@v5
3834

39-
- name: Build with Doxygen
40-
run: |
41-
doxygen Doxyfile
35+
- name: Configure CMake
36+
run: cmake -B build -DCONDY_BUILD_DOCS=ON
37+
38+
- name: Build Documentation
39+
run: cmake --build build --target docs
4240

4341
- name: Upload artifact
4442
uses: actions/upload-pages-artifact@v3
4543
with:
46-
path: ./docs/html
44+
path: ./build/docs/html
4745

4846
deploy:
4947
needs: build

‎.gitmodules‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎CMakeLists.txt‎

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,75 @@
11
cmake_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}")
2312
endif()
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

2568
add_library(condy INTERFACE)
2669
target_include_directories(condy INTERFACE include)
2770
target_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)
58101
endif()
59102

60-
if(LINK_LIBURING)
103+
if(CONDY_LINK_LIBURING)
61104
target_link_libraries(condy INTERFACE uring)
62105
endif()
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)
79122
endif()
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)
84127
endif()
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)
89132
endif()
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)
97142
endif()

‎docs/CMakeLists.txt‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
find_program(DOXYGEN_EXECUTABLE NAMES doxygen REQUIRED)
2+
3+
message(STATUS "Fetching doxygen-awesome-css")
4+
FetchContent_MakeAvailable(doxygen-awesome-css)
5+
FetchContent_GetProperties(doxygen-awesome-css SOURCE_DIR AWESOME_CSS_DIR)
6+
7+
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
8+
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
9+
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
10+
11+
add_custom_target(docs
12+
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
13+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
14+
COMMENT "Generate Doxygen documentation into ${CMAKE_CURRENT_BINARY_DIR}/html"
15+
VERBATIM)

0 commit comments

Comments
 (0)