-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
139 lines (121 loc) · 5.39 KB
/
CMakeLists.txt
File metadata and controls
139 lines (121 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# This file replaces CMakeLists.txt with the refactored version
cmake_minimum_required(VERSION 3.20)
project(engine-sim-cli VERSION 1.0.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Find required packages
find_package(Threads REQUIRED)
# Platform-specific audio libraries
if(APPLE)
# macOS/iOS: Use CoreAudio AudioQueue (built-in framework)
set(AUDIO_LIBRARY "-framework AudioToolbox -framework CoreAudio -framework CoreFoundation")
else()
message(FATAL_ERROR "engine-sim-cli only supports macOS with AudioQueue. Linux/Windows support has been removed.")
endif()
# Add engine-sim-bridge submodule
# The bridge now handles engine-sim as its own nested submodule
add_subdirectory(engine-sim-bridge ${CMAKE_BINARY_DIR}/engine-sim-bridge )
# CLI executable - refactored into separate source files for SOLID compliance
# NEW: Includes audio/modes and audio/renderers for one-class-per-file structure
add_executable(engine-sim-cli
src/CLIConfig.cpp
src/AudioPlayer.cpp
src/KeyboardInput.cpp
src/RPMController.cpp
src/AudioSource.cpp
src/ConsoleColors.cpp
src/audio/modes/ThreadedAudioMode.cpp
src/audio/modes/SyncPullAudioMode.cpp
src/audio/modes/AudioModeFactory.cpp
src/audio/renderers/SyncPullRenderer.cpp # NEW: Extracted SyncPullRenderer
src/audio/renderers/CircularBufferRenderer.cpp # NEW: Extracted CircularBufferRenderer
src/audio/renderers/SilentRenderer.cpp # NEW: Extracted SilentRenderer
src/SimulationLoop.cpp
src/CLIMain.cpp
src/CircularBuffer.cpp # NEW: Pure ring buffer handling
src/SyncPullAudio.cpp # NEW: Sync-pull audio rendering
src/EngineConfig.cpp # Engine config and script loading
src/ILogging.cpp # NEW: Logging interface implementation
src/interfaces/KeyboardInputProvider.cpp # NEW: Input provider interface
src/interfaces/ConsolePresentation.cpp # NEW: Presentation interface
)
target_link_libraries(engine-sim-cli
PRIVATE
engine-sim-bridge
${AUDIO_LIBRARY}
Threads::Threads
)
target_include_directories(engine-sim-cli
PRIVATE
engine-sim-bridge/include
src
)
target_compile_options(engine-sim-cli PRIVATE -g)
# Set rpath for CLI executable to find dylibs in build directory
if(APPLE)
set_target_properties(engine-sim-cli PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "@executable_path"
BUILD_RPATH "@executable_path"
)
endif()
# Post-build: Copy engine-sim libraries from bridge build directory
# Bridge builds both engine-sim-bridge (self-contained dependency)
# Parent just copies what it needs - no intrinsic knowledge of bridge internals
add_custom_command(TARGET engine-sim-cli POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/engine-sim-bridge/libenginesim.dylib
${CMAKE_BINARY_DIR}/libenginesim.dylib
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/engine-sim-bridge/libenginesim.1.dylib
${CMAKE_BINARY_DIR}/libenginesim.1.dylib
# Copy engine-sim assets so bridge can find them when running from build dir
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/engine-sim-bridge/engine-sim
${CMAKE_BINARY_DIR}/engine-sim-bridge/engine-sim
COMMENT "Copying engine-sim libraries from bridge build directory"
)
# Ensure engine-sim-bridge and dependencies are built before engine-sim-cli
add_dependencies(engine-sim-cli engine-sim-bridge)
# Installation
install(TARGETS engine-sim-cli
RUNTIME DESTINATION bin
)
# -----------------------------------------------------------------------------
# Tests
# Bridge owns its own tests (BridgeUnitTests); CLI owns its own tests (smoke_tests)
# `make test` from CLI runs both; `make run_tests` shows real-time output
# -----------------------------------------------------------------------------
option(BUILD_TESTS "Build engine-sim-cli unit tests" ON)
if(BUILD_TESTS)
# Download GoogleTest if not found
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
)
# For Windows: Prevent overriding parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# Enable testing
enable_testing()
# Add CLI smoke tests
add_subdirectory(test)
# Custom 'run_tests' target: runs all tests with real-time output
# Bridge tests its own code; CLI tests its own code
add_custom_target(run_tests
DEPENDS engine-sim-cli smoke_tests bridge_unit_tests
COMMAND ${CMAKE_COMMAND} -E echo "=== Bridge Unit Tests ==========================================="
COMMAND ${CMAKE_BINARY_DIR}/engine-sim-bridge/bridge_unit_tests --gtest_color=yes
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "=== CLI Smoke Tests ============================================="
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test/smoke_tests --gtest_color=yes
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "=== All tests complete ==========================================="
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running all tests with real-time output"
)
endif()