-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
489 lines (420 loc) · 20.4 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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
cmake_minimum_required(VERSION 3.20)
project(umgebung-lib)
#option(SET_COMPILER_FLAGS "Set Compiler Flags to C++17" OFF)
message(STATUS "----------------------------------------")
message(STATUS "UMGEBUNG_APP : ${PROJECT_NAME}")
#if (NOT DEFINED UMGEBUNG_APP OR "${UMGEBUNG_APP}" STREQUAL "")
# message(STATUS "CHARACTER : using umgebung standalone ( UMGEBUNG_APP not set )")
# set(BUILD_STANDALONE ON)
#else ()
# set(BUILD_STANDALONE OFF)
#endif ()
##########################################################################################################
### COMPILER FLAGS ###
##########################################################################################################
#function(set_umgebung_compiler_flags)
# set(CMAKE_CXX_STANDARD 17 PARENT_SCOPE)
# set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
## set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGL_SILENCE_DEPRECATION" PARENT_SCOPE)
# set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for Mac OS X" FORCE)
#endfunction()
# TODO somehow this does not work?!?
## NOTE can and should be set in root cmake script
#function(set_umgebung_compiler_flags)
# #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
# set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGL_SILENCE_DEPRECATION")
# #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++17-extensions")
# #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3")
# #set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for Mac OS X")
#endfunction()
#if (SET_COMPILER_FLAGS)
# message(STATUS "COMPILER_FLAGS: Umgebung is setting compiler flags")
# # TODO check if this is necessary or if they can be inherited from the parent project
# # TODO does not work if called via function … investigate
## set_umgebung_compiler_flags()
# set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for Mac OS X")
#else (SET_COMPILER_FLAGS)
# message(STATUS "COMPILER_FLAGS: Umgebung is expecting compiler flags to be set by root script")
#endif (SET_COMPILER_FLAGS)
##########################################################################################################
### CHECK FOR HOMEBREW ###
##########################################################################################################
find_program(BREW_FOUND brew)
if (APPLE)
if (BREW_FOUND)
execute_process(COMMAND brew --prefix
OUTPUT_VARIABLE HOMEBREW_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(HOMEBREW_LIB_PATH "${HOMEBREW_PREFIX}/lib")
message(STATUS "HOMEBREW LIBS : ${HOMEBREW_LIB_PATH}")
else ()
message(WARNING "HOMEBREW not found.")
endif ()
endif (APPLE)
##########################################################################################################
### SUPPLEMENT LIBRARY SEARCH PATH ###
##########################################################################################################
# NOTE this does not work when executed after `add_executable` or `add_library` … which is exactly what happens :(
# if (APPLE)
# # NOTE add default search path for libraries on macOS e.g for default Homebrew installation
# link_directories("/usr/local/lib")
# link_directories("/opt/homebrew/lib")
# message(STATUS "GLOBAL LIB : adding `/usr/local/lib` + `/opt/homebrew/lib` to library search path")
# elseif (UNIX)
# elseif (WIN32)
# else ()
# endif ()
##########################################################################################################
### ADD SOURCE + HEADER FILES ###
##########################################################################################################
# Add library target
if (APPLE)
file(GLOB UMGEBUNG_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/*.mm
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ip/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ip/posix/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/osc/*.cpp
)
elseif (UNIX)
file(GLOB UMGEBUNG_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ip/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ip/posix/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/osc/*.cpp
)
elseif (WIN32)
file(GLOB UMGEBUNG_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ip/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ip/win32/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/osc/*.cpp
)
else ()
file(GLOB UMGEBUNG_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ip/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ip/posix/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/osc/*.cpp
)
endif ()
add_library(umgebung-lib ${UMGEBUNG_SOURCE_FILES})
#target_compile_features(umgebung-lib PUBLIC cxx_std_17)
#target_compile_options(umgebung-lib PUBLIC -std=c++17)
# Specify include directories for the library
target_include_directories(umgebung-lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/ip
${CMAKE_CURRENT_SOURCE_DIR}/include/osc
${CMAKE_CURRENT_SOURCE_DIR}/include/midi
${CMAKE_CURRENT_SOURCE_DIR}/include/dr_libs
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/ip>
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/osc>
)
##########################################################################################################
### EN/DISABLE LIBRARIES ###
##########################################################################################################
add_library(umgebung-lib-interface INTERFACE)
if (DISABLE_GRAPHICS)
target_compile_definitions(umgebung-lib-interface INTERFACE DISABLE_GRAPHICS)
target_compile_definitions(${PROJECT_NAME} PUBLIC DISABLE_GRAPHICS)
message(STATUS "DISABLING : graphics")
endif (DISABLE_GRAPHICS)
if (DISABLE_AUDIO)
target_compile_definitions(umgebung-lib-interface INTERFACE DISABLE_AUDIO)
target_compile_definitions(${PROJECT_NAME} PUBLIC DISABLE_AUDIO)
message(STATUS "DISABLING : audio")
endif (DISABLE_AUDIO)
if (DISABLE_VIDEO)
target_compile_definitions(umgebung-lib-interface INTERFACE DISABLE_VIDEO)
target_compile_definitions(${PROJECT_NAME} PUBLIC DISABLE_VIDEO)
message(STATUS "DISABLING : video")
endif (DISABLE_VIDEO)
if (ENABLE_PORTAUDIO)
target_compile_definitions(umgebung-lib-interface INTERFACE ENABLE_PORTAUDIO)
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_PORTAUDIO)
message(STATUS "ENABLING : Portaudio Driver")
endif (ENABLE_PORTAUDIO)
if (ENABLE_IMGUI)
if (NOT DEFINED IMGUI_PATH)
message(FATAL_ERROR "IMGUI_PATH must be set in CMakeLists.txt")
elseif (NOT EXISTS ${IMGUI_PATH})
message(FATAL_ERROR "IMGUI_PATH does not point to valid directory")
endif ()
target_compile_definitions(umgebung-lib-interface INTERFACE ENABLE_IMGUI)
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_IMGUI)
# Compile as static library
file(GLOB IMGUI_SOURCES ${IMGUI_PATH}/*.cpp)
file(GLOB IMGUI_SOURCE_FILES
${IMGUI_PATH}/*.cpp
${IMGUI_PATH}/*.h
${IMGUI_PATH}/backends/imgui_impl_opengl2.h
${IMGUI_PATH}/backends/imgui_impl_opengl2.cpp
${IMGUI_PATH}/backends/imgui_impl_sdl2.cpp
${IMGUI_PATH}/backends/imgui_impl_sdl2.h)
add_library("ImGui" STATIC ${IMGUI_SOURCE_FILES})
target_include_directories("ImGui" PUBLIC ${IMGUI_PATH})
target_include_directories("ImGui" PUBLIC ${IMGUI_PATH}/backends)
message(STATUS "ENABLING : IMGui")
endif (ENABLE_IMGUI)
if (ENABLE_CAPTURE)
target_compile_definitions(umgebung-lib-interface INTERFACE ENABLE_CAPTURE)
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_CAPTURE)
message(STATUS "ENABLING : Capture")
endif (ENABLE_CAPTURE)
##########################################################################################################
### CREATE EXECUTABLE ###
##########################################################################################################
#if (BUILD_STANDALONE)
# add_executable(${PROJECT_NAME} ${UMGEBUNG_SOURCE_FILES})
# target_compile_definitions(${PROJECT_NAME} PUBLIC UMGEBUNG_STANDALONE)
#else (BUILD_STANDALONE)
target_sources(${PROJECT_NAME}
PUBLIC
${UMGEBUNG_SOURCE_FILES}
)
#endif (BUILD_STANDALONE)
##########################################################################################################
### CHECK SYSTEM TYPE ###
##########################################################################################################
if (APPLE)
message(STATUS "SYSTEM : macOS")
target_compile_definitions(umgebung-lib-interface INTERFACE SYSTEM_MACOS)
target_compile_definitions(${PROJECT_NAME} PUBLIC SYSTEM_MACOS)
elseif (UNIX)
message(STATUS "SYSTEM : UNIX ( including RPI )")
target_compile_definitions(umgebung-lib-interface INTERFACE SYSTEM_UNIX)
target_compile_definitions(${PROJECT_NAME} PUBLIC SYSTEM_UNIX)
elseif (WIN32)
message(STATUS "SYSTEM : Windows")
target_compile_definitions(umgebung-lib-interface INTERFACE SYSTEM_WIN32)
target_compile_definitions(${PROJECT_NAME} PUBLIC SYSTEM_WIN32)
else ()
message(STATUS "SYSTEM : Undefined, Good Luck!")
target_compile_definitions(umgebung-lib-interface INTERFACE SYSTEM_UNDEFINED)
target_compile_definitions(${PROJECT_NAME} PUBLIC SYSTEM_UNDEFINED)
endif ()
# NOTE removed specific system check for now ( because it fails with ninja build system ). it may not be necessary to have such a specific check for RPI.
#try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
# ${UMGEBUNG_PATH}/tools/system_check
# ${UMGEBUNG_PATH}/tools/system_check.cpp
# RUN_OUTPUT_VARIABLE SYSTEM_CHECK_OUTPUT)
#
#if(RUN_RESULT_VAR EQUAL 1)
# set(IS_WINDOWS ON)
# message(STATUS "Running on Windows")
#elseif(RUN_RESULT_VAR EQUAL 2)
# set(IS_MACOS ON)
# message(STATUS "Running on macOS")
#elseif(RUN_RESULT_VAR EQUAL 3)
# set(IS_RASPBERRY_PI ON)
# message(STATUS "Running on Raspberry Pi")
#elseif(RUN_RESULT_VAR EQUAL 4)
# set(IS_LINUX ON)
# message(STATUS "Running on Linux (non-Raspberry Pi)")
#else()
# set(IS_UNKNOWN_SYSTEM ON)
# message(STATUS "Running on an unknown system")
#endif()
##########################################################################################################
### SUPRESS WARNINGS FOR APPLE ###
##########################################################################################################
if (APPLE)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON)
endif (APPLE)
##########################################################################################################
### FIND PACKAGES + LIBRARIES ###
##########################################################################################################
find_package(PkgConfig REQUIRED)
if (WIN32)
elseif (APPLE)
elseif (UNIX)
find_package(Threads REQUIRED)
else ()
endif ()
# GRAPHICS + VIDEO
if (NOT DISABLE_GRAPHICS)
# OpenGL + GLEW + FTGL
pkg_search_module(GLEW REQUIRED glew)
pkg_search_module(FTGL REQUIRED ftgl)
if (APPLE)
pkg_search_module(SDL2 REQUIRED sdl2)
find_package(OpenGL REQUIRED) # or `OPENGL`
elseif (UNIX)
pkg_search_module(SDL2 REQUIRED sdl2)
find_package(OpenGL REQUIRED)
elseif (WIN32)
find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
else ()
message(STATUS "plattform may not be supported.")
pkg_search_module(SDL2 REQUIRED sdl2)
find_package(OpenGL REQUIRED)
endif ()
# FFMPEG
if (NOT DISABLE_VIDEO)
pkg_search_module(AVCODEC REQUIRED libavcodec)
pkg_search_module(AVFORMAT REQUIRED libavformat)
pkg_search_module(AVUTIL REQUIRED libavutil)
pkg_search_module(SWSCALE REQUIRED libswscale)
pkg_check_modules(SWRESAMPLE REQUIRED libswresample)
pkg_check_modules(AVDEVICE REQUIRED libavdevice)
if (APPLE)
elseif (UNIX)
elseif (WIN32)
else ()
message(STATUS "plattform may not be supported ... assuming windows.")
endif ()
endif (NOT DISABLE_VIDEO)
endif (NOT DISABLE_GRAPHICS)
# AUDIO
if (NOT DISABLE_AUDIO)
if (ENABLE_PORTAUDIO)
pkg_search_module(PORTAUDIO REQUIRED portaudio-2.0)
else (ENABLE_PORTAUDIO)
pkg_search_module(SDL2 REQUIRED sdl2)
endif (ENABLE_PORTAUDIO)
endif (NOT DISABLE_AUDIO)
# MIDI
if (NOT DISABLE_MIDI)
pkg_search_module(RTMIDI REQUIRED rtmidi)
endif (NOT DISABLE_MIDI)
##########################################################################################################
### SUPRESS WARNINGS FOR APPLE ###
##########################################################################################################
if (WIN32)
elseif (APPLE)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS OFF)
elseif (UNIX)
else ()
endif ()
##########################################################################################################
### INCLUDE + LINK LIBRARIES ###
##########################################################################################################
if (HOMEBREW_LIB_PATH)
target_link_directories(${PROJECT_NAME} PUBLIC ${HOMEBREW_LIB_PATH})
endif ()
if (WIN32)
target_link_libraries(${PROJECT_NAME} wsock32 ws2_32 winmm)
elseif (APPLE)
elseif (UNIX)
target_link_libraries(${PROJECT_NAME} Threads::Threads)
else ()
endif ()
# GRAPHICS + VIDEO + AUDIO
if (NOT DISABLE_AUDIO)
target_link_libraries(${PROJECT_NAME} ${PORTAUDIO_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${PORTAUDIO_INCLUDE_DIRS})
endif (NOT DISABLE_AUDIO)
if (NOT DISABLE_GRAPHICS OR NOT DISABLE_AUDIO)
find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${SDL2_INCLUDE_DIRS})
# IMGUI
if (ENABLE_IMGUI)
target_link_libraries(ImGui PRIVATE SDL2::SDL2)
target_link_libraries(${PROJECT_NAME} ImGui)
target_include_directories(${PROJECT_NAME} PUBLIC ImGui)
endif (ENABLE_IMGUI)
endif (NOT DISABLE_GRAPHICS OR NOT DISABLE_AUDIO)
if (NOT DISABLE_GRAPHICS)
# OpenGL + FTGL + GLEW
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${OPENGL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${FTGL_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${FTGL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${GLEW_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${GLEW_INCLUDE_DIRS})
# FFMPEG
if (NOT DISABLE_VIDEO)
target_link_libraries(${PROJECT_NAME}
${AVCODEC_LIBRARIES}
${AVFORMAT_LIBRARIES}
${AVUTIL_LIBRARIES}
${SWSCALE_LIBRARIES}
${AVDEVICE_LIBRARIES}
${SWRESAMPLE_LIBRARIES}
)
target_include_directories(${PROJECT_NAME} PUBLIC ${AVCODEC_INCLUDE_DIRS} ${AVFORMAT_INCLUDE_DIRS} ${AVUTIL_INCLUDE_DIRS} ${SWSCALE_INCLUDE_DIRS})
if (APPLE)
target_link_libraries(${PROJECT_NAME}
"-framework AVFoundation"
"-framework Foundation"
"-framework CoreMedia"
)
elseif (UNIX)
elseif (WIN32)
message(STATUS "plattform may not be supported")
else ()
message(STATUS "plattform may not be supported ... assuming windows.")
endif ()
endif (NOT DISABLE_VIDEO)
endif (NOT DISABLE_GRAPHICS)
# MIDI
if (NOT DISABLE_MIDI)
target_link_libraries(${PROJECT_NAME} ${RTMIDI_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${RTMIDI_INCLUDE_DIRS})
add_definitions(${RTMIDI_CFLAGS_OTHER})
# target_compile_definitions(${PROJECT_NAME} PUBLIC ${RTMIDI_CFLAGS_OTHER})
endif (NOT DISABLE_MIDI)
##########################################################################################################
### COMPILER FLAGS ###
##########################################################################################################
function(add_umgebung_libs)
# Check if umgebung-lib-interface target already exists
if (NOT TARGET umgebung-lib-interface)
message(FATAL_ERROR "umgebung-lib-interface target not found. Make sure it is defined before calling add_umgebung_libs.")
endif ()
# Check if umgebung-lib target already exists
if (NOT TARGET umgebung-lib)
message(FATAL_ERROR "umgebung-lib target not found. Make sure it is defined before calling add_umgebung_libs.")
endif ()
# Link the libraries if they exist
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(${PROJECT_NAME} PRIVATE umgebung-lib-interface)
target_link_libraries(${PROJECT_NAME} PRIVATE umgebung-lib)
endfunction()
##########################################################################################################
### TODO ###
##########################################################################################################
# TODO implement curses for headless mode
## ncurses
#if (UNIX)
# find_package(Curses REQUIRED)
# include_directories(${CURSES_INCLUDE_DIR})
# target_link_libraries(${PROJECT_NAME} PUBLIC ${CURSES_LIBRARIES})
#endif (UNIX)
#if (WIN32)
# target_link_libraries(${PROJECT_NAME} PUBLIC pdcurses)
#endif (WIN32)
##########################################################################################################
### NOTE ###
##########################################################################################################
# use these in projects:
# - prepare umgebung ( before `add_executable` ): `include(${UMGEBUNG_PATH}/cmake/default-pre.cmake)`
# - prepare umgebung ( after `add_executable` ): `include(${UMGEBUNG_PATH}/cmake/default-post.cmake)`
##########################################################################################################
### TEST ###
##########################################################################################################
option(BUILD_TESTING "Enable tests" OFF)
if (BUILD_TESTING)
message(STATUS "TESTING : enabled")
enable_testing()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for Mac OS X")
add_executable(umgebung-tests test/umgebung_test.cpp)
target_link_libraries(umgebung-tests umgebung-lib umgebung-lib-interface)
add_test(NAME UmgebungTest COMMAND umgebung-tests)
else ()
endif ()
# run test from CLI with `cmake -B build -DBUILD_TESTING=ON ; cmake --build build ; ctest --test-dir build`
##########################################################################################################
### END OF SCRIPT ###
##########################################################################################################
message(STATUS "----------------------------------------")