forked from christofmuc/JammerNetz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
209 lines (178 loc) · 7.51 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
#
# Copyright (c) 2019-2020 Christof Ruch. All rights reserved.
#
# Dual licensed: Distributed under Affero GPL license by default, an MIT license is available for purchase
#
cmake_minimum_required(VERSION 3.14)
# Target a specific macOS version to allow older hardware to run the client
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "Minimum OS X version to target for deployment")
project(JammerNetz)
# Since we also build MacOS, we need C++ 17. Which is not a bad thing.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
IF(APPLE)
# -fno-aligned-allocation is required for macOS 10.13 and the newer Intel TBBs
add_compile_options(-Wno-unused-command-line-argument -fno-aligned-allocation)
ENDIF()
# To avoid dependency on WebKit. This also came with MacOS, but as webkit is heavyweight, it is probably a good idea to turn it off for all
option(JUCE_CONFIG_JUCE_WEB_BROWSER OFF)
# Allow to turn on crash reporting via Sentry. This is turned on by default for the builds I upload to github
OPTION(SENTRY_CRASH_REPORTING "Turn on crash reporting via Internet/Sentry")
set(SENTRY_DSN "Sentry DSN URL" CACHE STRING "https://[email protected]/XXXX")
IF(SENTRY_CRASH_REPORTING)
message("Internet-based crash reporting is turned on, using Sentry endpoint authorization from SENTRY_DSN CMake variable")
SET(SENTRY_INSTALL_PATH "${CMAKE_CURRENT_LIST_DIR}/third_party/sentry-native/install")
SET(SENTRY_DISTRIBUTION_FILES "${SENTRY_INSTALL_PATH}/bin/sentry.dll" "${SENTRY_INSTALL_PATH}/bin/crashpad_handler.exe")
set(SENTRY_INCLUDE_DIR "${SENTRY_INSTALL_PATH}/include")
message(STATUS "Setting SENTRY_INSTALL_PATH to ${SENTRY_INSTALL_PATH}")
ENDIF()
# We need a little bit support for the JUCE library, and also want to put our own CMake helpers on the module path
SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Include useful scripts for CMake
include(FetchContent)
# Configure time downloads of more third_party libraries that can not be maintained as git submodules
# Make sure to read and accept the Steinberg licensing agreement in the directory _deps/asiosdk-src when you build the Windows version!
if (WIN32)
FetchContent_Declare(
asiosdk
URL https://www.steinberg.net/asiosdk
)
FetchContent_MakeAvailable(asiosdk)
set(ASIO_SDK_DIRECTORY "${asiosdk_SOURCE_DIR}/common")
FetchContent_Declare(
vcredist
URL https://aka.ms/vs/16/release/vc_redist.x64.exe
DOWNLOAD_NO_EXTRACT true
)
FetchContent_MakeAvailable(vcredist)
set(VCREDIST_PATH "${CMAKE_CURRENT_BINARY_DIR}/_deps/vcredist-subbuild/vcredist-populate-prefix/src")
elseif(APPLE)
# Supress a warning from juce_TargetPlatform by letting it know the build type
# NOTE that NDEBUG is set automatically in Release
if (NOT CMAKE_BUILD_TYPE MATCHES Release)
add_compile_definitions(DEBUG)
endif()
elseif(UNIX)
# This else branch is Linux, then.
ADD_DEFINITIONS(-DJUCE_JACK)
# Include useful scripts for CMake
find_package(PkgConfig REQUIRED)
find_package(OpenGL)
# These calls create special `PkgConfig::<MODULE>` variables
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(GLEW REQUIRED IMPORTED_TARGET glew)
pkg_check_modules(WEBKIT REQUIRED IMPORTED_TARGET webkit2gtk-4.0) # TODO Test that this is really no longer required
endif()
# We need a cryptographic key that server and client will share so they can communicate. In its simplest form, we will just take some random numbers from the internet
set(CRYPTO_FILE "${CMAKE_CURRENT_LIST_DIR}/RandomNumbers.bin")
if(NOT EXISTS ${CRYPTO_FILE})
message(STATUS "Creating 72 random byte crypto seed with the help of random.org")
file(DOWNLOAD "https://www.random.org/cgi-bin/randbyte?nbytes=72&format=f" ${CRYPTO_FILE}
TIMEOUT 60 # seconds
)
endif()
# Use all cores
IF (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
enable_testing()
include(GoogleTest)
set(gtest_force_shared_crt ON) # needed to build on Windows
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # otherwise the flag set above is ignored?
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
# See https://cmake.org/cmake/help/v3.10/module/GoogleTest.html
# Keep cache clean
mark_as_advanced(
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
gmock_build_tests gtest_build_samples gtest_build_tests
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
)
# Define the list of link libraries required on Linux linking with JUCE, this must be used by any executable / module to run standalone
if(UNIX AND NOT APPLE)
set(LINUX_JUCE_LINK_LIBRARIES
PkgConfig::WEBKIT
PkgConfig::GTK
PkgConfig::GLEW
Xext
X11
pthread
${CMAKE_DL_LIBS}
freetype
curl
asound)
# Also, as we will be building a shared module for Python, make sure GCC generates relocatable code suited for inclusion in a shared library
add_definitions(-fPIC)
ENDIF()
# Adding JUCE 6.1.x
ADD_DEFINITIONS(-DJUCE_MODAL_LOOPS_PERMITTED)
add_subdirectory("third_party/JUCE" EXCLUDE_FROM_ALL)
# Build a static library from juce
add_library(juce-static STATIC)
target_link_libraries(juce-static
PRIVATE
juce::juce_audio_basics juce::juce_audio_devices juce::juce_audio_formats
juce::juce_audio_processors juce::juce_audio_utils juce::juce_core
juce::juce_cryptography juce::juce_data_structures juce::juce_dsp
juce::juce_events juce::juce_graphics juce::juce_gui_basics
juce::juce_gui_extra juce::juce_opengl juce::juce_video
${LINUX_JUCE_LINK_LIBRARIES}
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags)
target_compile_definitions(juce-static
PUBLIC
JUCE_PLUGINHOST_VST=0
JUCE_PLUGINHOST_AU=0
DONT_SET_USING_JUCE_NAMESPACE=1
JUCE_DISPLAY_SPLASH_SCREEN=0
JUCE_REPORT_APP_USAGE=0
JUCE_CHECK_MEMORY_LEAKS=0
JUCE_QUICKTIME=0
JUCE_USE_DIRECTWRITE=1
JUCE_ASIO=1
JUCE_WASAPI_LOGGING=1
#JUCE_DIRECT2D=1 # That doesn't work, and the JUCE forum is full of confusing threads about Direct2D and font rendering
JUCE_CATCH_UNHANDLED_EXCEPTIONS=0
JUCE_COREGRAPHICS_DRAW_ASYNC=1
JUCE_WIN_PER_MONITOR_DPI_AWARE=1
JUCE_USE_FLAC=1
# JUCE_USE_WINRT_MIDI=1 # So much doesn't work when activating this that this is really scary
INTERFACE
$<TARGET_PROPERTY:juce-static,COMPILE_DEFINITIONS>)
target_include_directories(juce-static
INTERFACE
$<TARGET_PROPERTY:juce-static,INCLUDE_DIRECTORIES>
if (WIN32)
PRIVATE
"${ASIO_SDK_DIRECTORY}"
endif()
)
set_target_properties(juce-static PROPERTIES
POSITION_INDEPENDENT_CODE TRUE
VISIBILITY_INLINES_HIDDEN TRUE
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden)
# Configure TBB
set(TBB_TEST OFF)
if(WIN32)
string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION})
list(GET VERSION_LIST 0 MSVC_VERSION_MAJOR)
list(GET VERSION_LIST 1 MSVC_VERSION_MINOR)
SET(MY_TBB_BINARY_DIR_BASE msvc_${MSVC_VERSION_MAJOR}.${MSVC_VERSION_MINOR}_cxx17_64_md)
message("Determined TBB binary directory base as ${MY_TBB_BINARY_DIR_BASE}")
endif()
# Add subdirectories
add_subdirectory("third_party/JUCE-user-modules")
add_subdirectory("third_party/json")
add_subdirectory("third_party/fmt")
add_subdirectory("third_party/spdlog")
add_subdirectory("modules/juce-utils")
add_subdirectory("modules/juce-widgets")
message(${CMAKE_MODULE_PATH})
add_subdirectory("third_party/oneTBB" EXCLUDE_FROM_ALL)
add_subdirectory("common")
add_subdirectory("Server")
add_subdirectory("Client")
# The client installer now contains the server as well for local testing - make sure to always build the server
add_dependencies(JammerNetzClient JammerNetzServer)