-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
353 lines (304 loc) · 11.7 KB
/
CMakeLists.txt
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
include(FetchContent)
cmake_minimum_required(VERSION 3.16)
# set(CMAKE_VERBOSE_MAKEFILE ON)
# force universal binary on osx (must go BEFORE project call)
# TODO: universal binary not working with webgpu-distribution
# set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "" FORCE)
# # specify minimum support macOS version
# if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
# # If no deployment target has been set default to the minimum supported
# # OS version (this has to be set before the first project() call)
# if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
# set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0 CACHE STRING "iOS Deployment Target")
# else()
# set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10 CACHE STRING "macOS Deployment Target")
# endif()
# endif()
project(
ChuGL
VERSION 0.1.0
LANGUAGES CXX C
)
if(LINUX OR EMSCRIPTEN)
add_compile_options(-fPIC) # needed for emcripten
#set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
endif()
set(
CORE
src/core/log.c
src/core/hashmap.c
src/core/memory.cpp
)
set(
VENDOR
src/implementations.cpp
vendor/mikktspace/mikktspace.c
# cimgui (no freetype )
vendor/cimgui/cimgui.cpp
vendor/cimgui/imgui/imgui.cpp
vendor/cimgui/imgui/imgui_draw.cpp
vendor/cimgui/imgui/imgui_demo.cpp
vendor/cimgui/imgui/imgui_widgets.cpp
vendor/cimgui/imgui/imgui_tables.cpp
vendor/cimgui/imgui/misc/cpp/imgui_stdlib.cpp
vendor/cimgui/imgui/backends/imgui_impl_glfw.cpp
vendor/cimgui/imgui/backends/imgui_impl_wgpu.cpp
)
set(
RENDERER_TESTS
# src/tests/obj.cpp
src/tests/gltf.cpp
src/tests/imgui_test.cpp
src/tests/test_box2d.cpp
src/tests/test_lines2d.cpp
)
if (CHUGL_BUILD_RENDERER_TESTS)
message(STATUS "Building Renderer Tester")
add_executable(
ChuGL-Renderer-Tester
src/main.cpp
${CORE}
${VENDOR}
${RENDERER_TESTS}
)
# benchamrks TODO: put behind option flag, link with compile options
# add_executable(
# ChuGL-Benchmarks
# bench/hashmap.cpp
# ${CORE}
# )
set_target_properties(ChuGL-Renderer-Tester PROPERTIES
CXX_STANDARD 11
CXX_EXTENSIONS OFF
COMPILE_WARNING_AS_ERROR ON
VS_DEBUGGER_ENVIRONMENT "DAWN_DEBUG_BREAK_ON_ERROR=1"
)
# IDE setup
if(XCODE)
set_target_properties(ChuGL-Renderer-Tester PROPERTIES
XCODE_GENERATE_SCHEME ON
XCODE_SCHEME_ENABLE_GPU_FRAME_CAPTURE_MODE "Metal"
XCODE_SCHEME_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
endif()
endif()
# chugl library
if (EMSCRIPTEN)
# emcmake can't handle shared libraries. SIDE_LOAD executable is the only option
add_executable(
${PROJECT_NAME}
src/chugl.cpp
${CORE}
${VENDOR}
)
else()
add_library(
${PROJECT_NAME} SHARED
src/chugl.cpp
# src/ulib_imgui.cpp
${CORE}
${VENDOR}
)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
COMPILE_WARNING_AS_ERROR ON
VS_DEBUGGER_ENVIRONMENT "DAWN_DEBUG_BREAK_ON_ERROR=1"
POSITION_INDEPENDENT_CODE ON
PREFIX ""
OUTPUT_NAME ${PROJECT_NAME}
SUFFIX ".chug"
)
if(XCODE)
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_GENERATE_SCHEME ON
XCODE_SCHEME_ENABLE_GPU_FRAME_CAPTURE_MODE "Metal"
XCODE_SCHEME_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
endif()
# =================================================================================
# interface library for CMake properties
# =================================================================================
add_library(chugl_shared_properties INTERFACE)
# Defines
target_compile_definitions(chugl_shared_properties INTERFACE
$<$<CONFIG:Debug>:CHUGL_DEBUG>
$<$<CONFIG:Release>:CHUGL_RELEASE>
GLM_FORCE_DEPTH_ZERO_TO_ONE # glm force depth range to 0-1
GLM_ENABLE_EXPERIMENTAL
LOG_USE_COLOR
)
# increasing warning levels
if (MSVC)
target_compile_options(chugl_shared_properties INTERFACE /W4)
else()
target_compile_options(chugl_shared_properties INTERFACE -Wall -Wextra -pedantic)
# disable warnings
target_compile_options(chugl_shared_properties INTERFACE
-Wno-unused-parameter
# in release mode only, allowed unused params (to get around ASSERT)
$<$<CONFIG:Release>:-Wno-unused-variable>
$<$<CONFIG:Release>:-Wno-unused-function>
-Wno-deprecated-declarations
-Wno-compound-token-split-by-macro
-Wno-sign-compare
-Wno-unused-but-set-variable
)
endif()
# Ignore Windows warnings
if (MSVC)
target_compile_options(
chugl_shared_properties INTERFACE
# Ignore a warning that GLM requires to bypass
# Disable warning C4201: nonstandard extension used: nameless struct/union
/wd4201
# Required for GLM lookat()
# Disable warning C4127: conditional expression is constant
/wd4127
# Disable warning C4305: truncation from 'int' to 'bool' in 'if' condition
/wd4305
# Ignore a warning that stb_image requires to bypass
# Disable warning C4244: conversion from 'int' to 'short', possible loss of data
/wd4244
# ignore fopen warning for cgltf
/wd4996
# ignore warning for using 'bitwise and' to check if flag is set
/wd26813
# ignore hiding of previous local declaration
/wd4456
# ignore unused local variables
/wd4189
# ignore uninitialized member variables
/wd26495
)
target_compile_options(
${PROJECT_NAME} PRIVATE
# allow unused variables for the ChuGin DLL Query
/wd4100
)
endif (MSVC)
if ( MSVC )
# Set the startup project to be the actual project instead of ALL_BUILD
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
set(CHUCK_EXECUTABLE_DEBUG "${CMAKE_SOURCE_DIR}/chuck-debug.exe")
set(CHUCK_EXECUTABLE_RELEASE "${CMAKE_SOURCE_DIR}/chuck-release.exe")
set(CHUGIN_PATH_DEBUG "--chugin-path:${CMAKE_TARGET_DIR}./build/Debug")
set(CHUGIN_PATH_RELEASE "--chugin-path:${CMAKE_TARGET_DIR}./build/Release")
set_target_properties( ${PROJECT_NAME} PROPERTIES
# VS_DEBUGGER_COMMAND $<$<CONFIG:Debug>:${CHUCK_EXECUTABLE_DEBUG}>$<$<CONFIG:Release>:${CHUCK_EXECUTABLE_RELEASE}>
VS_DEBUGGER_COMMAND "C:/Program Files/ChucK/chuck.exe"
VS_DEBUGGER_COMMAND_ARGUMENTS "$<$<CONFIG:Debug>:${CHUGIN_PATH_DEBUG}>$<$<CONFIG:Release>:${CHUGIN_PATH_RELEASE}> --chugin-probe"
VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") # static linking with CRT
endif()
# add include path
target_include_directories(chugl_shared_properties
INTERFACE src
INTERFACE vendor
INTERFACE vendor/cimgui
INTERFACE vendor/cimgui/imgui
INTERFACE vendor/cimgui/imgui
INTERFACE vendor/box2d/include
)
# vendor dependencies ==========================================================
if (NOT EMSCRIPTEN)
add_subdirectory(vendor/glfw)
endif()
add_subdirectory(vendor/glfw3webgpu)
# host our own distribution of WebGPU on CCRMA
# switching to static library instead of dynami b/c
# chuck cannot find build/Debug/webgpu_native.dll.
# throws Error [126]: The specified module could not be found.
# i.e. ChuGL DLL needs wgpu DLL which cannot be not found.
# will need to fix this to implement ChuGLins
FetchContent_Declare(
webgpu
GIT_REPOSITORY https://github.com/AndrewAday/webgpu-distribution
GIT_TAG main
)
FetchContent_MakeAvailable(webgpu)
# FreeType font rendering
# set default freetype options
set(FT_DISABLE_BROTLI ON CACHE BOOL "" FORCE)
set(FT_DISABLE_BZIP2 ON CACHE BOOL "" FORCE)
set(FT_DISABLE_HARFBUZZ ON CACHE BOOL "" FORCE)
set(FT_DISABLE_PNG ON CACHE BOOL "" FORCE)
set(FT_DISABLE_ZLIB ON CACHE BOOL "" FORCE)
set(FT_ENABLE_ERROR_STRINGS ON CACHE BOOL "" FORCE)
add_subdirectory(vendor/freetype)
# # fetch freetype
# FetchContent_Declare (
# freetype
# GIT_REPOSITORY https://github.com/freetype/freetype.git
# GIT_TAG VER-2-13-2
# )
# make available
# FetchContent_MakeAvailable (freetype)
# box2d v3.0
# FetchContent_Declare(
# box2d
# GIT_REPOSITORY https://github.com/erincatto/box2c
# GIT_TAG main
# )
# FetchContent_MakeAvailable(box2d)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
option(BOX2D_AVX2 "Enable AVX2 (faster)" ON)
endif()
# Needed for samples.exe to find box2d.dll
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
# set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# The Box2D library uses simde https://github.com/simd-everywhere/simde
add_subdirectory(vendor/simde)
add_subdirectory(vendor/box2d/src)
# linking
# target_link_libraries(${PROJECT_NAME} PRIVATE webgpu glfw glfw3webgpu)
target_link_libraries(chugl_shared_properties INTERFACE webgpu glfw glfw3webgpu box2d freetype)
target_link_libraries(${PROJECT_NAME} PRIVATE chugl_shared_properties)
if (CHUGL_BUILD_RENDERER_TESTS)
target_link_libraries(ChuGL-Renderer-Tester PRIVATE chugl_shared_properties)
endif()
# emscripten specific options =================================================
if (EMSCRIPTEN)
# know to rebuild when assets/ directory changes
# set(SHELL_FILE shell_minimal.html)
# set_property(
# TARGET ${PROJECT_NAME}
# PROPERTY LINK_DEPENDS
# ${CMAKE_CURRENT_SOURCE_DIR}/${SHELL_FILE}
# )
# set_target_properties(${PROJECT_NAME} PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/assets)
target_compile_options(${PROJECT_NAME} PRIVATE -pthread)
target_link_options(${PROJECT_NAME} PRIVATE -sENVIRONMENT=worker)
target_link_options(${PROJECT_NAME} PRIVATE -pthread)
# Add Emscripten-specific link options
target_link_options(${PROJECT_NAME} PRIVATE
-sUSE_GLFW=3 # Use Emscripten-provided GLFW
-sUSE_WEBGPU # Handle WebGPU symbols
-sALLOW_MEMORY_GROWTH # allow memory to grow dynamically
-sSIDE_MODULE=1 # needed for chuck to dynamically load the chugin
# add thread support
# -pthread
# removing because ASYNCIFY not supported in side module
# using infinite loop instead
# -sASYNCIFY # Required for emscripten_sleep in the async wgpu adapter and device request
# -sDISABLE_EXCEPTION_CATCHING=0
# uncomment to include local files in the build
# https://emscripten.org/docs/porting/files/packaging_files.html
# https://emscripten.org/docs/getting_started/Tutorial.html#tutorial-files
# To include files outside of the current working directory
# use the `--preload-file srcpath@dstpath` syntax to explicitly
# specify the target location
# --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/assets@./assets
# Can specify custom html template
# https://github.com/emscripten-core/emscripten/blob/main/src/shell_minimal.html
# --shell-file ${CMAKE_CURRENT_SOURCE_DIR}/${SHELL_FILE}
)
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".wasm")
# emscripten only generates .html properly if target is a MAIN_MODULE
# set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html")
endif (EMSCRIPTEN)