-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
216 lines (175 loc) Β· 7.55 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
cmake_minimum_required(VERSION 3.24)
project(tangerine
DESCRIPTION "Procedural 3D model creation")
if (MSVC)
message(FATAL_ERROR
"Currently CMake is only used on the Linux platform.\
Visual Studio users should open the .sln file directly, instead.")
endif()
include(GNUInstallDirs)
#######################################################################
## Build options:
option(EMBED_LUA "Embed Lua support" ON)
option(EMBED_RACKET "Embed Racket support" OFF)
set(INSTALL_PKG_SUBPATH "tangerine" CACHE PATH
"Subdirectory to form PKGDATADIR from DATADIR")
mark_as_advanced(INSTALL_PKG_SUBPATH)
#######################################################################
## Required dependencies:
find_package(SDL2 REQUIRED)
find_package(Threads REQUIRED)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 17)
#######################################################################
## Additional debug defines:
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
#######################################################################
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
#######################################################################
## Set up PKGDATADIR (e.g. "share/tangerine/shaders"):
cmake_path(APPEND CMAKE_INSTALL_DATADIR "${INSTALL_PKG_SUBPATH}"
OUTPUT_VARIABLE INSTALL_PKGDATADIR)
cmake_path(RELATIVE_PATH INSTALL_PKGDATADIR
BASE_DIRECTORY CMAKE_INSTALL_BINDIR
OUTPUT_VARIABLE PKGDATADIR_FROM_BINDIR)
cmake_path(APPEND CMAKE_BINARY_DIR "${INSTALL_PKGDATADIR}"
OUTPUT_VARIABLE BUILD_PKGDATADIR)
file(GLOB_RECURSE SHADER_FILES CONFIGURE_DEPENDS
"shaders/*.glsl"
"shaders/defines.h")
if(EMBED_LUA)
file(GLOB_RECURSE MODELS_LUA_FILES CONFIGURE_DEPENDS "models/*.lua")
endif()
if(EMBED_RACKET)
file(GLOB_RECURSE MODELS_RKT_FILES CONFIGURE_DEPENDS "models/*.rkt")
endif()
cmake_path(APPEND BUILD_PKGDATADIR "shaders" OUTPUT_VARIABLE BUILD_SHADERS_DIR)
file(MAKE_DIRECTORY "${BUILD_SHADERS_DIR}")
foreach(X IN LISTS SHADER_FILES)
configure_file("${X}" "${BUILD_SHADERS_DIR}" COPYONLY)
endforeach()
cmake_path(APPEND BUILD_PKGDATADIR "models" OUTPUT_VARIABLE BUILD_MODELS_DIR)
file(MAKE_DIRECTORY "${BUILD_MODELS_DIR}")
foreach(X IN LISTS MODELS_LUA_FILES MODELS_RKT_FILES)
configure_file("${X}" "${BUILD_MODELS_DIR}" COPYONLY)
endforeach()
install(DIRECTORY "${BUILD_PKGDATADIR}/"
DESTINATION $<PATH:APPEND,${CMAKE_INSTALL_FULL_DATADIR},${INSTALL_PKG_SUBPATH}>)
#######################################################################
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
#######################################################################
## Third-Party Libraries:
#######################################################################
## fmt:
add_library(fmt OBJECT "third_party/fmt/src/format.cc")
target_include_directories(fmt PUBLIC "third_party/fmt/include")
#######################################################################
## GLAD:
add_library(glad OBJECT "third_party/glad/src/gl.c")
target_include_directories(glad PUBLIC "third_party/glad/include")
#######################################################################
## GLM:
add_subdirectory("third_party/glm-0.9.9.8/")
#######################################################################
## atomic_queue:
add_library(atomic_queue INTERFACE)
target_include_directories(atomic_queue INTERFACE "third_party/atomic_queue/include/")
#######################################################################
## ImGui:
file(GLOB TANGERINE_IMGUI_FILES CONFIGURE_DEPENDS
"third_party/imgui/*.cpp"
"third_party/imgui/backends/imgui_impl_opengl3.cpp"
"third_party/imgui/backends/imgui_impl_sdl.cpp")
add_library(imgui OBJECT "${TANGERINE_IMGUI_FILES}")
target_link_libraries(imgui PUBLIC SDL2::SDL2 glad)
# some complexity to make both <imgui/imgui.h> and "imgui.h" work
# FIXME same problem with glm ... can we just move the source?
target_include_directories(imgui PUBLIC
$<BUILD_INTERFACE:$<PATH:APPEND,${CMAKE_BINARY_DIR},imgui-include-dir>>
$<BUILD_INTERFACE:$<PATH:APPEND,${CMAKE_BINARY_DIR},imgui-include-dir/imgui>>
$<BUILD_INTERFACE:$<PATH:APPEND,${CMAKE_BINARY_DIR},imgui-include-dir/imgui/backends>>
$<INSTALL_INTERFACE:"${CMAKE_INSTALL_FULL_INCLUDEDIR}">)
file(GLOB TANGERINE_IMGUI_HEADERS CONFIGURE_DEPENDS "third_party/imgui/*.h")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/imgui-include-dir/imgui/backends")
foreach(X IN ITEMS "third_party/imgui/backends/imgui_impl_opengl3.h"
"third_party/imgui/backends/imgui_impl_sdl.h")
configure_file("${X}" "imgui-include-dir/imgui/backends" COPYONLY)
endforeach()
foreach(X IN LISTS TANGERINE_IMGUI_HEADERS)
configure_file("${X}" "imgui-include-dir/imgui")
endforeach()
#######################################################################
## ImFileDialog:
add_library(ImFileDialog OBJECT
"third_party/ImFileDialog/ImFileDialog.cpp"
"third_party/stb/stb.cpp")
target_link_libraries(ImFileDialog PUBLIC imgui)
target_include_directories(ImFileDialog
PUBLIC "third_party/ImFileDialog" #/ImFileDialog.h"
PRIVATE "third_party/stb") #/stb_image.h")
#######################################################################
## naive-surface-nets:
add_library(NaiveSurfaceNets OBJECT
"third_party/naive-surface-nets/src/surface_nets.cpp")
target_include_directories(NaiveSurfaceNets
PUBLIC "third_party/naive-surface-nets/include")
#######################################################################
## VoxWriter:
add_library(VoxWriter OBJECT "third_party/voxwriter/VoxWriter.cpp")
target_sources(VoxWriter
PUBLIC FILE_SET HEADERS
BASE_DIRS "third_party/voxwriter/"
FILES "third_party/voxwriter/VoxWriter.h")
#######################################################################
## whereami:
add_library(whereami OBJECT "third_party/whereami/src/whereami.c")
target_include_directories(whereami PUBLIC "third_party/whereami/src/")
#######################################################################
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
#######################################################################
## Tangerine, the executable:
file(GLOB_RECURSE TANGERINE_FILES CONFIGURE_DEPENDS "tangerine/*.cpp")
add_executable(tangerine ${TANGERINE_FILES})
set_target_properties(tangerine
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
$<PATH:APPEND,${CMAKE_BINARY_DIR},${CMAKE_INSTALL_BINDIR}>)
target_compile_definitions(tangerine PRIVATE
"TANGERINE_PKGDATADIR_FROM_BINDIR=${PKGDATADIR_FROM_BINDIR}")
target_link_libraries(tangerine PRIVATE
atomic
fmt
glad
glm
atomic_queue
imgui
ImFileDialog
NaiveSurfaceNets
VoxWriter
whereami
tinfo # see https://gitlab.kitware.com/cmake/cmake/-/issues/23236
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS})
install(TARGETS tangerine)
#######################################################################
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
#######################################################################
## Optional Scripting Languages:
#######################################################################
## Lua:
if(EMBED_LUA)
file(GLOB TANGERINE_LUA_FILES CONFIGURE_DEPENDS "third_party/lua-5.4.4/lua/*.c")
list(FILTER
TANGERINE_LUA_FILES
EXCLUDE REGEX
".*/lua/(onelua|lua|luac)\.c") # these define main
add_library(lua OBJECT "${TANGERINE_LUA_FILES}")
target_include_directories(lua INTERFACE "third_party/lua-5.4.4")
target_link_libraries(tangerine PRIVATE lua)
endif()
target_compile_definitions(tangerine PRIVATE
"EMBED_LUA=$<BOOL:${EMBED_LUA}>")
#######################################################################
## Racket:
# FIXME!