-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
314 lines (268 loc) · 10.3 KB
/
Copy pathCMakeLists.txt
File metadata and controls
314 lines (268 loc) · 10.3 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
cmake_minimum_required(VERSION 3.25)
# Must run before project(): the vcpkg toolchain file installs manifest
# features as part of the project() call, so CHISELCAD_BUILD_GUI (an
# ordinary option() below, too late for vcpkg to see) needs this mirror to
# actually skip fetching/building vulkan-memory-allocator/glfw3/imgui for a
# core-only configure. One flag controls both:
# cmake -B build -DCHISELCAD_BUILD_GUI=OFF ...
if(NOT DEFINED CHISELCAD_BUILD_GUI OR CHISELCAD_BUILD_GUI)
list(APPEND VCPKG_MANIFEST_FEATURES "gui")
endif()
project(chiselcad
VERSION 0.2.0
DESCRIPTION "A fast, precise, GPU-accelerated CSG modeler"
LANGUAGES CXX
)
# ============================================================
# C++20
# ============================================================
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ============================================================
# Build type default
# ============================================================
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
endif()
# ============================================================
# Build options
# ============================================================
# The Vulkan GUI app (chiselcad) needs the Vulkan SDK, GLFW, ImGui, VMA, and
# glslc. chiselcad_core/chiselcad_cli/chiselcad_tests need none of that —
# just Manifold and a few small libs — so a CI job that only builds those
# (e.g. the OpenSCAD compat/regression suite) can configure with this OFF
# and skip the entire Vulkan toolchain, including at `find_package` time.
option(CHISELCAD_BUILD_GUI "Build the Vulkan GUI application (chiselcad)" ON)
# ============================================================
# Dependencies shared by every target (via vcpkg)
# ============================================================
find_package(glm CONFIG REQUIRED)
find_package(manifold CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(ZLIB REQUIRED) # raw DEFLATE decompression for import()'s .3mf (ZIP) support
# ============================================================
# Platform-specific sources
# ============================================================
if(WIN32)
set(PLATFORM_SOURCES
src/editor/FileWatcherWin32.cpp
)
set(PLATFORM_UTIL_SOURCES
src/util/ResourcePathsWin32.cpp
)
elseif(UNIX)
set(PLATFORM_SOURCES
src/editor/FileWatcherInotify.cpp
)
set(PLATFORM_UTIL_SOURCES
src/util/ResourcePathsPosix.cpp
)
endif()
# ============================================================
# chiselcad_core — language, CSG/mesh evaluation, import/export, headless
# build pipeline. No Vulkan/GLFW/ImGui/VMA dependency: this is the one
# target the compat/regression suite and the CLI actually need.
# ============================================================
set(CHISELCAD_CORE_SOURCES
# Language
src/lang/Lexer.cpp
src/lang/Parser.cpp
src/lang/Interpreter.cpp
src/lang/SourceLoader.cpp
# CSG / meshing
src/csg/CsgEvaluator.cpp
src/csg/PrimitiveGen.cpp
src/csg/MeshEvaluator.cpp
src/csg/MeshCache.cpp
# Headless build pipeline (parse -> CSG evaluate -> mesh) + JSON stats
src/app/HeadlessBuild.cpp
src/app/BuildStats.cpp
# Export / Import
src/export/StlExporter.cpp
src/import/StlLoader.cpp
src/import/OffLoader.cpp
src/import/DxfLoader.cpp
src/import/SvgLoader.cpp
src/import/MiniXml.cpp
src/import/ZipReader.cpp
src/import/ThreeMfLoader.cpp
src/import/AmfLoader.cpp
src/import/SurfaceLoader.cpp
src/import/stb_truetype_impl.cpp
src/import/stb_image_impl.cpp
src/import/StbFontBackend.cpp
src/import/NaiveLtrShaper.cpp
src/import/TextLoader.cpp
# Util
src/util/ResourcePaths.cpp
${PLATFORM_UTIL_SOURCES}
)
add_library(chiselcad_core STATIC ${CHISELCAD_CORE_SOURCES})
target_include_directories(chiselcad_core PUBLIC
src/
third_party/
)
target_link_libraries(chiselcad_core PUBLIC
manifold::manifold
glm::glm
spdlog::spdlog
nlohmann_json::nlohmann_json
ZLIB::ZLIB
)
target_compile_definitions(chiselcad_core PRIVATE
CHISELCAD_RESOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/resources/"
)
if(MSVC)
target_compile_options(chiselcad_core PRIVATE /W4 /WX /permissive-)
else()
target_compile_options(chiselcad_core PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
# stb_truetype's/stb_image's implementation TUs trigger warnings under
# -Wall -Wextra -Wpedantic (vendored code, not ours to fix) — silenced for
# these two files only rather than loosened project-wide.
if(MSVC)
set_source_files_properties(src/import/stb_truetype_impl.cpp src/import/stb_image_impl.cpp PROPERTIES COMPILE_OPTIONS "/W0")
else()
set_source_files_properties(src/import/stb_truetype_impl.cpp src/import/stb_image_impl.cpp PROPERTIES COMPILE_OPTIONS "-w")
endif()
# ============================================================
# chiselcad_cli — headless entry point. No Vulkan/GLFW/ImGui/VMA.
# ============================================================
add_executable(chiselcad_cli src/cli_main.cpp)
target_link_libraries(chiselcad_cli PRIVATE chiselcad_core)
if(MSVC)
target_compile_options(chiselcad_cli PRIVATE /W4 /WX /permissive-)
else()
target_compile_options(chiselcad_cli PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
install(TARGETS chiselcad_cli RUNTIME DESTINATION bin)
install(DIRECTORY resources/ DESTINATION share/chiselcad/resources)
# ============================================================
# chiselcad — Vulkan GUI application
# ============================================================
if(CHISELCAD_BUILD_GUI)
find_package(Vulkan REQUIRED)
find_package(glfw3 REQUIRED)
find_package(imgui CONFIG REQUIRED)
find_package(VulkanMemoryAllocator CONFIG REQUIRED)
find_program(GLSLC glslc HINTS ENV VULKAN_SDK PATH_SUFFIXES bin REQUIRED)
set(SHADER_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/render/shaders")
set(SHADER_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/shaders")
file(MAKE_DIRECTORY ${SHADER_BINARY_DIR})
set(SHADER_SOURCES
${SHADER_SOURCE_DIR}/preview.vert
${SHADER_SOURCE_DIR}/preview.frag
${SHADER_SOURCE_DIR}/mesh.vert
${SHADER_SOURCE_DIR}/mesh.frag
${SHADER_SOURCE_DIR}/grid.vert
${SHADER_SOURCE_DIR}/grid.frag
${SHADER_SOURCE_DIR}/background.vert
${SHADER_SOURCE_DIR}/background.frag
)
set(SHADER_BINARIES "")
foreach(SHADER ${SHADER_SOURCES})
get_filename_component(SHADER_NAME ${SHADER} NAME)
set(SPIRV "${SHADER_BINARY_DIR}/${SHADER_NAME}.spv")
add_custom_command(
OUTPUT ${SPIRV}
COMMAND ${GLSLC} ${SHADER} -o ${SPIRV}
DEPENDS ${SHADER}
COMMENT "Compiling shader ${SHADER_NAME}"
)
list(APPEND SHADER_BINARIES ${SPIRV})
endforeach()
add_custom_target(chiselcad_shaders ALL DEPENDS ${SHADER_BINARIES})
set(CHISELCAD_GUI_SOURCES
src/main.cpp
# App
src/app/Application.cpp
src/app/Config.cpp
src/app/MeshBuilder.cpp
# Editor (external editor + file watcher only; no embedded editor in v1)
src/editor/ExternalEditor.cpp
src/editor/DiagnosticsPanel.cpp
${PLATFORM_SOURCES}
# Render
src/render/VulkanContext.cpp
src/render/VmaAllocator.cpp
src/render/Swapchain.cpp
src/render/RenderGraph.cpp
src/render/GpuMesh.cpp
src/render/Pipeline.cpp
src/render/Camera.cpp
src/render/Renderer.cpp
# GUI-only "open a bare .stl file" viewer path (needs render::Vertex
# for direct GPU upload). Not part of the .scad build pipeline —
# CsgEvaluator's import() builtin uses StlLoader.cpp directly, which
# lives in chiselcad_core instead.
src/import/StlImporter.cpp
)
add_executable(chiselcad ${CHISELCAD_GUI_SOURCES})
add_dependencies(chiselcad chiselcad_shaders)
target_include_directories(chiselcad PRIVATE
src/
third_party/
)
target_link_libraries(chiselcad PRIVATE
chiselcad_core
Vulkan::Vulkan
GPUOpen::VulkanMemoryAllocator
glfw
imgui::imgui
)
if(MSVC)
target_compile_options(chiselcad PRIVATE /W4 /WX /permissive-)
else()
target_compile_options(chiselcad PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
target_compile_definitions(chiselcad PRIVATE
CHISELCAD_SHADER_DIR="${SHADER_BINARY_DIR}/"
CHISELCAD_RESOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/resources/"
CHISELCAD_VERSION="${PROJECT_VERSION}"
GLM_FORCE_DEPTH_ZERO_TO_ONE # Vulkan depth range [0,1] not [-1,1]
)
install(TARGETS chiselcad RUNTIME DESTINATION bin)
install(DIRECTORY ${SHADER_BINARY_DIR} DESTINATION share/chiselcad)
endif()
# ============================================================
# Tests (Catch2 — via vcpkg, same binary cache as every other dependency,
# rather than FetchContent building it from source on every CI run)
# ============================================================
enable_testing()
find_package(Catch2 3 CONFIG REQUIRED)
set(CHISELCAD_TEST_SOURCES
tests/test_main.cpp
tests/test_lexer.cpp
tests/test_parser.cpp
tests/test_csg_evaluator.cpp
tests/test_interpreter.cpp
tests/test_source_loader.cpp
tests/test_stl_loader.cpp
tests/test_off_loader.cpp
tests/test_dxf_loader.cpp
tests/test_svg_loader.cpp
tests/test_3mf_loader.cpp
tests/test_amf_loader.cpp
tests/test_surface_loader.cpp
tests/test_text_loader.cpp
tests/test_headless_build.cpp
)
add_executable(chiselcad_tests ${CHISELCAD_TEST_SOURCES})
target_include_directories(chiselcad_tests PRIVATE src/ third_party/)
target_compile_definitions(chiselcad_tests PRIVATE
CHISELCAD_TEST_FIXTURE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/fixtures/"
CHISELCAD_RESOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/resources/"
)
target_link_libraries(chiselcad_tests PRIVATE
chiselcad_core
Catch2::Catch2WithMain
)
if(MSVC)
target_compile_options(chiselcad_tests PRIVATE /W4 /WX /permissive-)
else()
target_compile_options(chiselcad_tests PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
include(Catch)
catch_discover_tests(chiselcad_tests)