-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
385 lines (322 loc) · 14 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# On top of the usual `target_link_libraries`, you must also call `cool_setup` with your target name. E.g.:
# ```
# add_subdirectory(Cool)
# target_link_libraries(${PROJECT_NAME} PRIVATE Cool::Core)
# cool_setup(${PROJECT_NAME})
# ```
cmake_minimum_required(VERSION 3.20)
option(COOL_USE_INSTALLER "Turn this on if you are using an installer for your application (NB: you still need to generate the installer yourself)" OFF)
add_library(Cool)
add_library(Cool::Core ALIAS Cool)
add_library(Cool-PublicProperties INTERFACE) # This is needed by both Cool and its tests
add_library(Cool-PrivateProperties INTERFACE) # This is needed by both Cool and its tests
target_link_libraries(Cool PUBLIC Cool-PublicProperties)
target_link_libraries(Cool PRIVATE Cool-PrivateProperties)
# Choose C++ version
target_compile_features(Cool-PublicProperties INTERFACE cxx_std_20)
# Set warning level
if(MSVC)
target_compile_options(Cool-PrivateProperties INTERFACE /W4)
else()
target_compile_options(Cool-PrivateProperties INTERFACE -Wall -Wextra -Wpedantic -pedantic-errors -Wconversion -Wsign-conversion -Wimplicit-fallthrough)
endif()
# Maybe enable warnings as errors
set(WARNINGS_AS_ERRORS_FOR_COOL OFF CACHE BOOL "ON iff you want to treat warnings as errors") # Might be overriden in the CMake cache
if(WARNINGS_AS_ERRORS_FOR_COOL)
if(MSVC)
target_compile_options(Cool-PrivateProperties INTERFACE /WX)
else()
target_compile_options(Cool-PrivateProperties INTERFACE -Werror)
endif()
endif()
# Set COOL_PATH as the path to Cool, relative to the main project's CMakeLists.txt. It will look like "third-party/Cool"
cmake_path(RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR BASE_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE COOL_PATH)
set(COOL_PATH_INTERNAL ${COOL_PATH} CACHE INTERNAL "") # Make a global variable so that `cool_setup()` will be able to use it when it is called outside of this CMake file
target_compile_definitions(Cool-PublicProperties INTERFACE
$<$<CONFIG:Debug>:DEBUG> # Define DEBUG in debug mode
COOL_PATH=\"${COOL_PATH}\" # This is useful to set the path to Cool's res directory
$<$<CONFIG:Debug>:COOL_DEBUG_ONLY__CMAKE_SOURCE_DIR=\"${CMAKE_SOURCE_DIR}\"> # This is useful to set the current working directory in debug mode.
IMGUI_DEFINE_MATH_OPERATORS
COOL_APP_NAME=\"${COOL_APP_NAME}\"
)
if(COOL_USE_INSTALLER)
target_compile_definitions(Cool-PrivateProperties INTERFACE COOL_USE_INSTALLER=1)
else()
target_compile_definitions(Cool-PrivateProperties INTERFACE COOL_USE_INSTALLER=0)
endif()
# ----------------------
# ---Add Cool sources---
# ----------------------
file(GLOB_RECURSE COOL_SOURCES CONFIGURE_DEPENDS src/*)
set(COOL_APP_VERSION_STRING "\"${COOL_APP_VERSION}\"")
configure_file("src/Cool/Dump/app_version.cpp.in" "src/Cool/Dump/app_version.cpp")
list(APPEND COOL_SOURCES "src/Cool/Dump/app_version.cpp")
target_sources(Cool PRIVATE ${COOL_SOURCES})
# -----------------------------
# ---Set include directories---
# -----------------------------
target_include_directories(Cool-PublicProperties INTERFACE src)
target_include_directories(Cool-PublicProperties SYSTEM INTERFACE lib)
target_precompile_headers(Cool-PublicProperties INTERFACE # More info on precompiled headers: https://julesfouchy.github.io/Learn--Cpp-And-Dev-Practices/docs/lessons/precompiled-header
<Cool/UDL/std.h> # Make std literals available everywhere. E.g. "Hello"s will create a std::string, not a const char*.
<vector>
<string>
<memory>
<functional>
<variant>
<optional>
<algorithm>
<unordered_map>
<deque>
<thread>
<utility>
<chrono>
<list>
<imgui/imgui.h>
<imgui/misc/cpp/imgui_stdlib.h>
<glm/glm.hpp>
<glm/gtc/type_ptr.hpp>
<ser20/access.hpp>
<ser20/types/vector.hpp>
<ser20/types/string.hpp>
<ser20/types/variant.hpp>
<boxer/boxer.h>
<nfd.hpp>
<IconFontCppHeaders/IconsFontAwesome6.h>
<scope_guard/scope_guard.hpp>
<fmt/format.h>
<fmt/core.h>
<fmt/std.h>
<fmt/compile.h>
<gsl/gsl>
<tl/expected.hpp>
<Cool/Log/Log.hpp>
<Cool/Geometry/imvec_glm_conversions.h>
<Cool/Serialization/filesystem.h>
<Cool/Serialization/img.h>
<Cool/Serialization/GlmSerialization.h> # must be included after <glm/glm.hpp> because it depends on it
<Cool/ostream/glm.h> # must be included after <glm/glm.hpp> because it depends on it
<Cool/ostream/vector.h> # must be included after <vector> because it depends on it
)
if(COOL_USE_VULKAN)
target_precompile_headers(Cool-PublicProperties INTERFACE
<vulkan/vulkan.hpp>
<vku/vku.hpp>
)
elseif(COOL_USE_OPENGL)
target_precompile_headers(Cool-PublicProperties INTERFACE
<glad/gl.h>
<Cool/Gpu/OpenGL/GLDebug.h>
)
endif()
# -------------------------
# ---Add Vulkan / OpenGL---
# -------------------------
if(COOL_USE_VULKAN)
target_compile_definitions(Cool-PublicProperties INTERFACE
COOL_VULKAN
COOL_VULKAN_VERSION=${COOL_USE_VULKAN})
find_package(Vulkan REQUIRED)
target_link_libraries(Cool-PublicProperties INTERFACE Vulkan::Vulkan)
add_subdirectory(lib/Vookoo/include)
target_link_libraries(Cool-PublicProperties INTERFACE Vookoo::Vookoo)
install(FILES "lib/Vookoo/LICENSE" DESTINATION "license/Vookoo")
add_subdirectory(lib/easy-shaderc)
target_link_libraries(Cool-PublicProperties INTERFACE easy_shaderc::shaderc)
elseif(COOL_USE_OPENGL)
target_compile_definitions(Cool-PublicProperties INTERFACE
COOL_OPENGL
COOL_OPENGL_VERSION=${COOL_USE_OPENGL})
add_subdirectory(lib/glpp-extended)
target_compile_definitions(glpp-extended PRIVATE $<$<CONFIG:Debug>:GLPP_SHOULD_CHECK_ERRORS>)
target_link_libraries(Cool-PublicProperties INTERFACE glpp::extended)
if(APPLE)
target_compile_definitions(Cool-PublicProperties INTERFACE
COOL_PARTICLES_DISABLED_REASON="Particles are not supported on MacOS for now.")
endif()
endif()
# -------------------
# ---Add libraries---
# -------------------
# folder_watcher
add_subdirectory(lib/folder_watcher)
target_link_libraries(Cool-PublicProperties INTERFACE folder_watcher::folder_watcher)
# imgui_gradient
add_subdirectory(lib/imgui_gradient)
target_include_directories(imgui_gradient SYSTEM PRIVATE lib/imgui) # imgui_gradient needs acces to imgui
target_link_libraries(Cool-PublicProperties INTERFACE imgui_gradient::imgui_gradient)
# algorithms
add_subdirectory(lib/algorithms)
target_link_libraries(Cool-PublicProperties INTERFACE algorithms::algorithms)
# scope_guard
install(FILES "lib/scope_guard/LICENSE" DESTINATION "license/scope_guard")
# GLFW
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory(lib/glfw)
target_link_libraries(Cool-PublicProperties INTERFACE glfw)
install(FILES "lib/glfw/LICENSE.md" DESTINATION "license/glfw")
# ser20
add_subdirectory(lib/ser20)
target_link_libraries(Cool-PublicProperties INTERFACE ser20::ser20)
install(FILES "lib/ser20/LICENSE" DESTINATION "license/ser20")
# smart
add_subdirectory(lib/smart)
target_link_libraries(Cool-PublicProperties INTERFACE smart::smart)
# IconFontCppHeaders
install(FILES "lib/IconFontCppHeaders/licence.txt" DESTINATION "license/IconFontCppHeaders")
# Boxer
add_subdirectory(lib/Boxer)
target_link_libraries(Cool-PublicProperties INTERFACE Boxer)
install(FILES "lib/Boxer/LICENSE" DESTINATION "license/Boxer")
# Native File Dialog
set(NFD_OVERRIDE_RECENT_WITH_DEFAULT ON CACHE BOOL "" FORCE)
add_subdirectory(lib/nativefiledialog-extended EXCLUDE_FROM_ALL)
target_link_libraries(Cool-PublicProperties INTERFACE nfd)
install(FILES "lib/nativefiledialog-extended/LICENSE" DESTINATION "license/nativefiledialog-extended")
# GSL
add_subdirectory(lib/GSL)
target_link_libraries(Cool-PublicProperties INTERFACE Microsoft.GSL::GSL)
install(FILES "lib/GSL/LICENSE" DESTINATION "license/GSL")
# spdlog
target_include_directories(Cool-PrivateProperties SYSTEM INTERFACE lib/spdlog/include)
install(FILES "lib/spdlog/LICENSE" DESTINATION "license/spdlog")
# img
add_subdirectory(lib/img)
target_link_libraries(Cool-PublicProperties INTERFACE img::img)
# easy_ffmpeg
add_subdirectory(lib/easy_ffmpeg)
target_link_libraries(Cool-PublicProperties INTERFACE easy_ffmpeg::easy_ffmpeg)
# Audio
add_subdirectory(lib/Audio)
target_link_libraries(Cool-PublicProperties INTERFACE Cool::Audio)
# exe_path
add_subdirectory(lib/exe_path)
target_link_libraries(Cool-PublicProperties INTERFACE exe_path::exe_path)
# fix_tdr_delay
add_subdirectory(lib/fix-tdr-delay)
target_link_libraries(Cool-PrivateProperties INTERFACE fix_tdr_delay::fix_tdr_delay)
# serv
add_subdirectory(lib/serv)
target_link_libraries(Cool-PublicProperties INTERFACE serv::serv)
# stringify
add_subdirectory(lib/stringify)
target_link_libraries(Cool-PublicProperties INTERFACE stringify::stringify)
# op
add_subdirectory(lib/op)
target_link_libraries(Cool-PublicProperties INTERFACE op::op)
# reg
add_subdirectory(lib/reg)
target_link_libraries(Cool-PublicProperties INTERFACE reg::reg)
# wafl
add_subdirectory(lib/wafl)
target_link_libraries(Cool-PublicProperties INTERFACE wafl::wafl)
# open_link
add_subdirectory(lib/open)
target_link_libraries(Cool-PublicProperties INTERFACE Cool::open)
# os_name
add_subdirectory(lib/os_name)
target_link_libraries(Cool-PublicProperties INTERFACE os_name::os_name)
# tl::expected
target_include_directories(Cool-PublicProperties SYSTEM INTERFACE lib/expected/include)
# nlohmann json
target_include_directories(Cool-PublicProperties SYSTEM INTERFACE lib/json/single_include)
install(FILES "lib/json/LICENSE.MIT" DESTINATION "license/nlohmann_json")
# Dear ImGui
add_subdirectory(lib/imgui)
target_include_directories(Cool-PublicProperties SYSTEM INTERFACE lib/imgui)
install(FILES "lib/imgui/LICENSE.txt" DESTINATION "license/imgui")
# wcam
set(WCAM_DONT_INCLUDE_FMT ON)
add_subdirectory(lib/wcam)
target_link_libraries(Cool-PublicProperties INTERFACE wcam::wcam)
# get_system_error
# add_subdirectory(lib/get_system_error) # Already done by wcam
target_link_libraries(Cool-PublicProperties INTERFACE Cool::get_system_error)
# RtMidi
add_subdirectory(lib/RtMidiWrapper)
target_link_libraries(Cool-PublicProperties INTERFACE RtMidiW::RtMidiW)
# oscpack
add_subdirectory(lib/oscpack)
target_link_libraries(Cool-PrivateProperties INTERFACE oscpack)
# GLSL-Color-Functions
install(FILES "res/shaders/GLSL-Color-Functions/LICENSE" DESTINATION "license/GLSL-Color-Functions")
# Build ImGui with glfw
target_link_libraries(ImGui PRIVATE glfw)
target_sources(ImGui PRIVATE lib/imgui/backends/imgui_impl_glfw.cpp)
# Build ImGui with Vulkan / OpenGL
if(COOL_USE_VULKAN)
target_sources(ImGui PRIVATE lib/imgui/backends/imgui_impl_vulkan.cpp)
target_link_libraries(ImGui PRIVATE Vulkan::Vulkan)
elseif(COOL_USE_OPENGL)
target_sources(ImGui PRIVATE lib/imgui/backends/imgui_impl_opengl3.cpp)
endif()
target_link_libraries(Cool-PublicProperties INTERFACE ImGui::ImGui)
# ImGuiNodeEditor
add_subdirectory(lib/imgui-node-editor)
target_include_directories(ImGuiNodeEditor SYSTEM PUBLIC lib/imgui)
target_link_libraries(Cool-PublicProperties INTERFACE ImGuiNodeEditor::ImGuiNodeEditor)
install(FILES "lib/imgui-node-editor/LICENSE" DESTINATION "license/imgui-node-editor")
# imgui_markdown
install(FILES "lib/imgui_markdown/License.txt" DESTINATION "license/imgui_markdown")
# ImStyleEd
add_subdirectory(lib/ImGui_StyleEditor)
target_include_directories(ImStyleEd SYSTEM PRIVATE lib)
target_link_libraries(Cool-PublicProperties INTERFACE ImStyleEd::ImStyleEd)
# ImGuiNotify
add_subdirectory(lib/ImGuiNotify)
target_include_directories(ImGuiNotify SYSTEM PRIVATE lib/imgui)
target_link_libraries(Cool-PublicProperties INTERFACE ImGuiNotify::ImGuiNotify)
# no-sleep
add_subdirectory(lib/no-sleep)
target_link_libraries(Cool-PublicProperties INTERFACE no_sleep::no_sleep)
# ----------------
# ---Copy files---
# ----------------
include("CMakeUtils/files_and_folders.cmake")
function(cool_setup TARGET_NAME)
ffmpeg_copy_libs(${TARGET_NAME})
Cool__target_copy_folder(${TARGET_NAME} ${COOL_PATH_INTERNAL}/res)
install(DIRECTORY ${COOL_PATH_INTERNAL}/res DESTINATION bin/${COOL_PATH_INTERNAL})
endfunction()
# ------------------
# ---Set the app icon---
# ------------------
# Call this function if you want to set an icon for your app.
# It will be used as the executable's icon and be visible in the corner of your app's window.
# To do so you will need both a .png and .ico files containing your logo.
#
# The .ico will only be used at compile time. For more info about .ico, see https://docs.fileformat.com/image/ico/.
# It needs to be in the same folder as a .rc file containing "IDI_ICON1 ICON DISCARDABLE "your_icon.ico""
# where your_icon.ico is the name of your .ico file.
# `RC_FILE` is the path to that .rc file.
#
# The .png (or actually any image format supported by CoolLab) will be used at runtime.
# It needs to be copied alongside your executable using `Cool__target_copy_file` or `Cool__target_copy_folder`.
# `IMAGE_FILE` is the path to that .png file.
# It MUST be relative to the root of your project (a.k.a. to `Cool::Path::root()`).
function(Cool__set_app_icon
TARGET
IMAGE_FILE
RC_FILE
)
target_compile_definitions(Cool-PrivateProperties INTERFACE COOL_APP_ICON_FILE=\"${IMAGE_FILE}\")
if(WIN32)
target_sources(${TARGET} PRIVATE ${RC_FILE})
endif()
endfunction()
# ---------------------
# ---Setup the tests---
# ---------------------
add_executable(Tests-Cool tests/tests.cpp ${COOL_SOURCES})
target_link_libraries(Tests-Cool PRIVATE Cool-PublicProperties)
target_link_libraries(Tests-Cool PRIVATE Cool-PrivateProperties)
target_compile_definitions(Tests-Cool PRIVATE COOL_ENABLE_TESTS)
ffmpeg_copy_libs(Tests-Cool)
set(DOCTEST_NO_INSTALL ON CACHE BOOL "" FORCE)
add_subdirectory(lib/doctest)
target_link_libraries(Tests-Cool PRIVATE doctest::doctest)
install(FILES "lib/doctest/LICENSE.txt" DESTINATION "license/doctest")
set_target_properties(Tests-Cool PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE})