-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
211 lines (180 loc) · 6.69 KB
/
Copy pathCMakeLists.txt
File metadata and controls
211 lines (180 loc) · 6.69 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
cmake_minimum_required(VERSION 3.20)
# Build options (set before project() so vcpkg manifest features can be mapped)
option(FLUXGRAPH_BUILD_TESTS "Build unit tests" ON)
option(FLUXGRAPH_BUILD_EXAMPLES "Build examples" ON)
option(FLUXGRAPH_BUILD_SERVER "Build gRPC server" OFF)
option(FLUXGRAPH_BUILD_DIAGRAM_TOOL "Build diagram generation tooling" OFF)
option(FLUXGRAPH_JSON_ENABLED "Enable JSON graph loading (requires nlohmann/json)" OFF)
option(FLUXGRAPH_YAML_ENABLED "Enable YAML graph loading (requires yaml-cpp)" OFF)
# Map CMake options -> vcpkg manifest features for deterministic dependency resolution.
if(FLUXGRAPH_BUILD_TESTS)
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
endif()
if(FLUXGRAPH_BUILD_SERVER)
list(APPEND VCPKG_MANIFEST_FEATURES "server")
endif()
if(FLUXGRAPH_JSON_ENABLED)
list(APPEND VCPKG_MANIFEST_FEATURES "json")
endif()
if(FLUXGRAPH_YAML_ENABLED)
list(APPEND VCPKG_MANIFEST_FEATURES "yaml")
endif()
project(fluxgraph VERSION 1.0.6 LANGUAGES CXX)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# C++20 required (std::format for diagnostics; standard, no third-party dep)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Export compile commands for IDE support
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# ThreadSanitizer (TSAN) — data-race detection for the gRPC server's worker
# threads. Applied to all targets; deps are rebuilt with TSAN via x64-linux-tsan.
option(ENABLE_TSAN "Enable ThreadSanitizer for data race detection" OFF)
if(ENABLE_TSAN)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
if(NOT WIN32)
add_compile_options(-fsanitize=thread -g -fno-omit-frame-pointer)
add_link_options(-fsanitize=thread)
message(STATUS "ThreadSanitizer (TSAN) enabled for data race detection")
else()
message(WARNING "ThreadSanitizer not supported on Windows (Linux/macOS only)")
endif()
else()
message(WARNING "ThreadSanitizer requested but compiler not supported: ${CMAKE_CXX_COMPILER_ID}")
endif()
elseif(DEFINED VCPKG_TARGET_TRIPLET AND VCPKG_TARGET_TRIPLET MATCHES "tsan")
if(NOT WIN32)
message(STATUS "ThreadSanitizer auto-detected via triplet: ${VCPKG_TARGET_TRIPLET}")
add_compile_options(-fsanitize=thread -g -fno-omit-frame-pointer)
add_link_options(-fsanitize=thread)
endif()
endif()
# Fuzzing (libFuzzer, requires clang). Include the helper BEFORE the targets so
# its instrumentation applies to the code-under-test (the loaders), not just the
# harness.
option(ENABLE_FUZZING "Build libFuzzer fuzz targets (requires clang)" OFF)
if(ENABLE_FUZZING)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/AddFuzzTarget.cmake)
endif()
# Core library sources
set(FLUXGRAPH_SOURCES
src/core/signal_store.cpp
src/core/namespace.cpp
src/core/units.cpp
src/model/thermal_integration.cpp
src/model/thermal_mass.cpp
src/model/thermal_rc2.cpp
src/model/first_order_process.cpp
src/model/second_order_process.cpp
src/model/state_space_siso_discrete.cpp
src/model/mass_spring_damper.cpp
src/model/dc_motor.cpp
src/graph/param_utils.cpp
src/graph/compiler.cpp
src/graph/compiler/algorithms.cpp
src/graph/compiler/common.cpp
src/graph/compiler/dimensional.cpp
src/graph/compiler/registry_common.cpp
src/graph/compiler/registry_transforms.cpp
src/graph/compiler/registry_models_thermal.cpp
src/graph/compiler/registry_models_control.cpp
src/graph/compiler/registry_models_state_space.cpp
src/graph/compiler/registry_models_mechanical.cpp
src/graph/compiler/registry_models_electromechanical.cpp
src/graph/compiler/registry.cpp
src/engine.cpp
)
# Conditionally add loader sources and resolve dependencies from vcpkg
if(FLUXGRAPH_JSON_ENABLED)
list(APPEND FLUXGRAPH_SOURCES src/loaders/json_loader.cpp)
find_package(nlohmann_json CONFIG REQUIRED)
endif()
if(FLUXGRAPH_YAML_ENABLED)
list(APPEND FLUXGRAPH_SOURCES src/loaders/yaml_loader.cpp)
find_package(yaml-cpp CONFIG REQUIRED)
endif()
# Create static library
add_library(fluxgraph STATIC ${FLUXGRAPH_SOURCES})
# Public include directory
target_include_directories(fluxgraph PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Compiler warnings
if(MSVC)
target_compile_options(fluxgraph PRIVATE /W4 /WX)
elseif(ENABLE_FUZZING)
# The fuzz lane is the first clang build of this repo; don't fail it on
# clang-only warnings (the gcc lanes keep -Werror).
target_compile_options(fluxgraph PRIVATE -Wall -Wextra -pedantic)
else()
target_compile_options(fluxgraph PRIVATE -Wall -Wextra -Werror -pedantic)
endif()
# Link optional dependencies
if(FLUXGRAPH_JSON_ENABLED)
target_link_libraries(fluxgraph PUBLIC nlohmann_json::nlohmann_json)
target_compile_definitions(fluxgraph PUBLIC FLUXGRAPH_JSON_ENABLED)
endif()
if(FLUXGRAPH_YAML_ENABLED)
target_link_libraries(fluxgraph PUBLIC yaml-cpp::yaml-cpp)
target_compile_definitions(fluxgraph PUBLIC FLUXGRAPH_YAML_ENABLED)
endif()
# Optional diagram tooling
if(FLUXGRAPH_BUILD_DIAGRAM_TOOL)
add_subdirectory(tools)
endif()
# Tests
if(FLUXGRAPH_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# Examples
if(FLUXGRAPH_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# gRPC Server
if(FLUXGRAPH_BUILD_SERVER)
add_subdirectory(server)
endif()
# Fuzz targets (libFuzzer; loaders must be enabled to have something to fuzz)
if(ENABLE_FUZZING)
add_subdirectory(fuzz)
endif()
# Install/export package configuration
install(TARGETS fluxgraph
EXPORT fluxgraphTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(FLUXGRAPH_BUILD_DIAGRAM_TOOL)
install(DIRECTORY include/fluxgraph
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
else()
install(DIRECTORY include/fluxgraph
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN "viz" EXCLUDE
)
endif()
install(EXPORT fluxgraphTargets
FILE fluxgraphTargets.cmake
NAMESPACE fluxgraph::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fluxgraph
)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/fluxgraphConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/fluxgraphConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fluxgraph
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/fluxgraphConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/fluxgraphConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/fluxgraphConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fluxgraph
)