Skip to content

Commit fc2a10c

Browse files
committed
build(rhi): make SDL3 optional so CI builds without it
SDL3 is only available on dev machines with local installs. When SDL3 is not found, RHI sources and tests are excluded from the build. Defines CF_HAS_SDL3=1 when available.
1 parent 6e3bcb6 commit fc2a10c

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,36 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
1212
add_compile_definitions(CF_DEBUG)
1313
endif()
1414

15-
# ── SDL3 ────────────────────────────────────────────────────────
16-
find_package(SDL3 REQUIRED CONFIG)
15+
# ── SDL3 (optional – RHI is only built when SDL3 is available) ──
16+
find_package(SDL3 CONFIG QUIET)
1717

1818
add_library(Caffeine
1919
src/core/Timer.cpp
2020
src/core/GameLoop.cpp
2121
src/input/InputManager.cpp
2222
src/debug/LogSystem.cpp
2323
src/debug/Profiler.cpp
24-
src/rhi/RenderDevice.cpp
25-
src/rhi/CommandBuffer.cpp
2624
)
2725

26+
if(SDL3_FOUND)
27+
target_sources(Caffeine PRIVATE
28+
src/rhi/RenderDevice.cpp
29+
src/rhi/CommandBuffer.cpp
30+
)
31+
endif()
32+
2833
target_include_directories(Caffeine PUBLIC
2934
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
3035
$<INSTALL_INTERFACE:include>
3136
)
3237

33-
target_link_libraries(Caffeine PUBLIC SDL3::SDL3)
38+
if(SDL3_FOUND)
39+
target_link_libraries(Caffeine PUBLIC SDL3::SDL3)
40+
target_compile_definitions(Caffeine PUBLIC CF_HAS_SDL3=1)
41+
message(STATUS "SDL3 found – RHI module enabled")
42+
else()
43+
message(STATUS "SDL3 not found – RHI module disabled")
44+
endif()
3445

3546
target_compile_features(Caffeine PUBLIC cxx_std_20)
3647

tests/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.20)
22

3-
add_executable(CaffeineTest
3+
set(CAFFEINE_TEST_SOURCES
44
test_allocators.cpp
55
test_containers.cpp
66
test_math.cpp
@@ -9,9 +9,14 @@ add_executable(CaffeineTest
99
test_gameloop.cpp
1010
test_input.cpp
1111
test_debug.cpp
12-
test_rhi.cpp
1312
)
1413

14+
if(SDL3_FOUND)
15+
list(APPEND CAFFEINE_TEST_SOURCES test_rhi.cpp)
16+
endif()
17+
18+
add_executable(CaffeineTest ${CAFFEINE_TEST_SOURCES})
19+
1520
target_link_libraries(CaffeineTest PRIVATE Caffeine)
1621
target_include_directories(CaffeineTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/Catch2)
1722
if(MSVC)
@@ -23,10 +28,10 @@ endif()
2328
enable_testing()
2429
add_test(NAME CaffeineTest COMMAND CaffeineTest)
2530

26-
if(WIN32)
31+
if(SDL3_FOUND AND WIN32)
2732
add_custom_command(TARGET CaffeineTest POST_BUILD
2833
COMMAND ${CMAKE_COMMAND} -E copy_if_different
2934
$<TARGET_FILE:SDL3::SDL3>
3035
$<TARGET_FILE_DIR:CaffeineTest>
3136
)
32-
endif()
37+
endif()

0 commit comments

Comments
 (0)