-
-
Notifications
You must be signed in to change notification settings - Fork 942
/
Copy pathCMakeLists.txt
372 lines (331 loc) · 12.1 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
cmake_minimum_required(VERSION 3.2)
message(STATUS "CMakeLists: Sonic Pi Qt GUI")
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
endif()
project("Sonic Pi"
LANGUAGES CXX C
DESCRIPTION "A code-based music creation and performance tool"
VERSION 4.4.0
HOMEPAGE_URL "https://sonic-pi.net"
)
set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(QTAPP_ROOT ${CMAKE_CURRENT_LIST_DIR})
list(APPEND CMAKE_MODULE_PATH ${QTAPP_ROOT}/cmake)
# Set cmake prefix path so it can find the Qt libraries
if((${BUILD_32BIT}) AND (DEFINED ENV{QT_INSTALL_LOCATION32}))
message(STATUS "Setting up a 32 bit Qt Build")
message(STATUS "Setting prefix to user-defined Qt (32-bit) install location: $ENV{QT_INSTALL_LOCATION32}")
set(CMAKE_PREFIX_PATH $ENV{QT_INSTALL_LOCATION32})
elseif(DEFINED ENV{QT_INSTALL_LOCATION})
message(STATUS "Setting prefix to user-defined Qt install location: $ENV{QT_INSTALL_LOCATION}")
set(CMAKE_PREFIX_PATH $ENV{QT_INSTALL_LOCATION})
elseif(APPLE AND EXISTS /usr/local/opt/qt@5)
# Homebrew installs Qt into/usr/local/qt5
message(STATUS "Setting prefix to Homebrew's Qt install location: /usr/local/opt/qt@5")
set(CMAKE_PREFIX_PATH /usr/local/opt/qt@5)
endif()
# Qt Setup
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(QT_TOOLS_DIR ${CMAKE_PREFIX_PATH}/bin)
set_property(GLOBAL PROPERTY AUTOMOC_FOLDER Automoc)
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER Automoc)
find_package(Qt6 QUIET)
if(Qt6_FOUND AND WITH_QT_GUI_WEBENGINE)
find_package(Qt6 COMPONENTS Core Widgets Gui Concurrent Network OpenGLWidgets PrintSupport Xml Svg LinguistTools WebEngineWidgets REQUIRED)
add_compile_definitions(WITH_WEBENGINE)
elseif(Qt6_FOUND)
find_package(Qt6 COMPONENTS Core Widgets Gui Concurrent Network OpenGLWidgets PrintSupport Xml Svg LinguistTools REQUIRED)
elseif(WITH_QT_GUI_WEBENGINE)
find_package(Qt5 COMPONENTS Core Widgets Gui Concurrent Network OpenGL PrintSupport Xml Svg LinguistTools WebEngineWidgets REQUIRED)
add_compile_definitions(WITH_WEBENGINE)
else()
find_package(Qt5 COMPONENTS Core Widgets Gui Concurrent Network OpenGL PrintSupport Xml Svg LinguistTools REQUIRED)
endif()
find_package(Threads REQUIRED)
if(USE_SYSTEM_LIBS)
find_package(QScintilla REQUIRED)
else()
# We build QScintilla as part of the main project to make it easy to debug/fix
# It is not built as part of externals
add_subdirectory(QScintilla_src-2.13.3)
endif()
add_subdirectory(vendor/SingleApplication)
set(APP_NAME sonic-pi)
set(MACOS_APP_NAME "Sonic Pi")
set(NEW_API_SOURCES
${QTAPP_ROOT}/qt_api_client.cpp
${QTAPP_ROOT}/qt_api_client.h
${QTAPP_ROOT}/visualizer/scope_window.cpp
${QTAPP_ROOT}/visualizer/scope_window.h
)
set(EDITOR_SOURCES
${QTAPP_ROOT}/widgets/sonicpiscintilla.cpp
${QTAPP_ROOT}/widgets/sonicpilexer.cpp
${QTAPP_ROOT}/widgets/sonicpilexer.h
${QTAPP_ROOT}/widgets/sonicpiscintilla.h
)
set(QT_SOURCES
${QTAPP_ROOT}/widgets/infowidget.cpp
${QTAPP_ROOT}/widgets/settingswidget.cpp
${QTAPP_ROOT}/widgets/bpmscrubwidget.cpp
${QTAPP_ROOT}/widgets/bpmscrubwidget.h
${QTAPP_ROOT}/mainwindow.cpp
${QTAPP_ROOT}/mainwindow.h
${QTAPP_ROOT}/model/sonicpitheme.cpp
${QTAPP_ROOT}/model/sonicpitheme.h
${QTAPP_ROOT}/widgets/infowidget.h
${QTAPP_ROOT}/widgets/settingswidget.h
)
set(SOURCES
${QTAPP_ROOT}/main.cpp
${QTAPP_ROOT}/utils/scintilla_api.cpp
${QTAPP_ROOT}/utils/sonicpi_i18n.cpp
${QTAPP_ROOT}/widgets/sonicpilog.cpp
${QTAPP_ROOT}/widgets/sonicpilog.h
${QTAPP_ROOT}/widgets/sonicpicontext.cpp
${QTAPP_ROOT}/widgets/sonicpicontext.h
${QTAPP_ROOT}/widgets/sonicpimetro.cpp
${QTAPP_ROOT}/widgets/sonicpimetro.h
${QTAPP_ROOT}/widgets/timewarpedit.h
${QTAPP_ROOT}/widgets/timewarpedit.cpp
${QTAPP_ROOT}/widgets/sonicpieditor.cpp
${QTAPP_ROOT}/widgets/sonicpieditor.h
${QTAPP_ROOT}/utils/scintilla_api.h
${QTAPP_ROOT}/utils/sonicpi_i18n.h
${QTAPP_ROOT}/utils/ruby_help.h
${QTAPP_ROOT}/utils/lang_list.h
${QTAPP_ROOT}/model/settings.h
)
if(WITH_QT_GUI_WEBENGINE)
set(SOURCES
${SOURCES}
${QTAPP_ROOT}/widgets/phxwebview.h
${QTAPP_ROOT}/widgets/phxwebview.cpp
${QTAPP_ROOT}/widgets/phxwidget.h
${QTAPP_ROOT}/widgets/phxwidget.cpp
${QTAPP_ROOT}/widgets/phxurlinterceptor.h
${QTAPP_ROOT}/widgets/phxurlinterceptor.cpp
)
endif()
SET(RESOURCES
${QTAPP_ROOT}/SonicPi.qrc
${QTAPP_ROOT}/help_files.qrc
${QTAPP_ROOT}/info_files.qrc
${QTAPP_ROOT}/SonicPi.rc
${QTAPP_ROOT}/images/app.icns
)
SET(TS_FILES
${QTAPP_ROOT}/lang/sonic-pi_ar.ts
${QTAPP_ROOT}/lang/sonic-pi_bg.ts
${QTAPP_ROOT}/lang/sonic-pi_bn.ts
${QTAPP_ROOT}/lang/sonic-pi_bs.ts
${QTAPP_ROOT}/lang/sonic-pi_ca.ts
${QTAPP_ROOT}/lang/[email protected]
${QTAPP_ROOT}/lang/sonic-pi_cs.ts
${QTAPP_ROOT}/lang/sonic-pi_da.ts
${QTAPP_ROOT}/lang/sonic-pi_de.ts
${QTAPP_ROOT}/lang/sonic-pi_el.ts
${QTAPP_ROOT}/lang/sonic-pi_en_AU.ts
${QTAPP_ROOT}/lang/sonic-pi_en_US.ts
${QTAPP_ROOT}/lang/sonic-pi_eo.ts
${QTAPP_ROOT}/lang/sonic-pi_es.ts
${QTAPP_ROOT}/lang/sonic-pi_et.ts
${QTAPP_ROOT}/lang/sonic-pi_eu.ts
${QTAPP_ROOT}/lang/sonic-pi_fa.ts
${QTAPP_ROOT}/lang/sonic-pi_fi.ts
${QTAPP_ROOT}/lang/sonic-pi_fr.ts
${QTAPP_ROOT}/lang/sonic-pi_ga.ts
${QTAPP_ROOT}/lang/sonic-pi_gl.ts
${QTAPP_ROOT}/lang/sonic-pi_he.ts
${QTAPP_ROOT}/lang/sonic-pi_hi.ts
${QTAPP_ROOT}/lang/sonic-pi_hu.ts
${QTAPP_ROOT}/lang/sonic-pi_hy.ts
${QTAPP_ROOT}/lang/sonic-pi_id.ts
${QTAPP_ROOT}/lang/sonic-pi_is.ts
${QTAPP_ROOT}/lang/sonic-pi_it.ts
${QTAPP_ROOT}/lang/sonic-pi_ja.ts
${QTAPP_ROOT}/lang/sonic-pi_ka.ts
${QTAPP_ROOT}/lang/sonic-pi_ko.ts
${QTAPP_ROOT}/lang/sonic-pi_nb.ts
${QTAPP_ROOT}/lang/sonic-pi_nl.ts
${QTAPP_ROOT}/lang/sonic-pi_pl.ts
${QTAPP_ROOT}/lang/sonic-pi_pt_BR.ts
${QTAPP_ROOT}/lang/sonic-pi_pt.ts
${QTAPP_ROOT}/lang/sonic-pi_ro.ts
${QTAPP_ROOT}/lang/sonic-pi_ru.ts
${QTAPP_ROOT}/lang/sonic-pi_si.ts
${QTAPP_ROOT}/lang/sonic-pi_sk.ts
${QTAPP_ROOT}/lang/sonic-pi_sl.ts
${QTAPP_ROOT}/lang/sonic-pi_sv.ts
${QTAPP_ROOT}/lang/sonic-pi_sw.ts
${QTAPP_ROOT}/lang/sonic-pi_th.ts
${QTAPP_ROOT}/lang/sonic-pi_tr.ts
${QTAPP_ROOT}/lang/sonic-pi_ug.ts
${QTAPP_ROOT}/lang/sonic-pi_uk.ts
${QTAPP_ROOT}/lang/sonic-pi_vi.ts
${QTAPP_ROOT}/lang/sonic-pi_zh_HK.ts
${QTAPP_ROOT}/lang/sonic-pi_zh_TW.ts
${QTAPP_ROOT}/lang/sonic-pi_zh-Hans.ts
${QTAPP_ROOT}/lang/sonic-pi_zh.ts
)
# Enable tracy profiler on debug and rel with debug builds
if(WIN32)
SET (SOURCES ${SOURCES} ${APP_ROOT}/external/tracy/TracyClient.cpp)
elseif(APPLE)
SET (SOURCES ${SOURCES} ${QTAPP_ROOT}/platform/macos.mm)
SET (SOURCES ${SOURCES} ${QTAPP_ROOT}/platform/macos.h)
endif()
set(ALL_SOURCES ${QT_SOURCES} ${SOURCES} ${EDITOR_SOURCES} ${OLD_API_SOURCES} ${NEW_API_SOURCES})
# Create the Qt version of the app
if (APPLE)
# NOTE! The underscore here works around a subtle problem with vcpkg toolchain and is required
_add_executable(${APP_NAME} MACOSX_BUNDLE ${ALL_SOURCES} ${RESOURCES} )
else()
add_executable(${APP_NAME} WIN32 ${ALL_SOURCES} ${RESOURCES}) # Win32 ignored on non-windows
endif()
# Translations: Convert the .ts files into .qm files
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION ${QTAPP_ROOT}/lang)
if (Qt6_FOUND)
qt_add_lrelease(${APP_NAME} TS_FILES ${TS_FILES})
else()
qt5_add_translation(QM_FILES ${TS_FILES})
set_property(SOURCE ${APP_NAME} APPEND PROPERTY OBJECT_DEPENDS ${QM_FILES})
endif()
if (APPLE)
set_target_properties(
${APP_NAME} PROPERTIES
OUTPUT_NAME "Sonic Pi"
MACOSX_RPATH TRUE
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME TRUE
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
MACOSX_BUNDLE_GUI_IDENTIFIER "net.sonic-pi.app"
MACOSX_BUNDLE_INFO_STRING "A code-based music creation and performance tool"
MACOSX_BUNDLE_ICON_FILE "app.icns"
MACOSX_BUNDLE_LONG_VERSION_STRING ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
RESOURCE "images/app.icns"
LINK_FLAGS "-framework AppKit"
OUTPUT_NAME ${MACOS_APP_NAME}
)
file(
GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/run-macdeployqt.sh"
CONTENT "PATH=$PATH:/usr/local/opt/qt@5/bin macdeployqt \"$1\""
)
add_custom_command(
TARGET ${APP_NAME}
POST_BUILD
COMMAND bash "${CMAKE_CURRENT_BINARY_DIR}/run-macdeployqt.sh" ${MACOS_APP_NAME}.app
)
add_custom_command(
TARGET ${APP_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ../../../../../../../app app
POST_BUILD
WORKING_DIRECTORY ${MACOS_APP_NAME}.app/Contents/Resources
)
add_custom_command(
TARGET ${APP_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ../../../../../../server server
POST_BUILD
WORKING_DIRECTORY ${MACOS_APP_NAME}.app/Contents/Resources
)
add_custom_command(
TARGET ${APP_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ../../../../../../../etc etc
POST_BUILD
WORKING_DIRECTORY ${MACOS_APP_NAME}.app/Contents/Resources
)
add_custom_command(
TARGET ${APP_NAME}
POST_BUILD
COMMAND chmod +w ${MACOS_APP_NAME}.app/Contents/Info.plist && plutil -replace NSHighResolutionCapable -bool true ${MACOS_APP_NAME}.app/Contents/Info.plist
)
endif()
message(STATUS "App Root: ${APP_ROOT}")
set_property(TARGET ${APP_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) # Qt requires this?
target_include_directories(${APP_NAME}
PRIVATE
${QTAPP_ROOT}
${APP_ROOT}/external/scsynth-boost-1.74.0
${APP_ROOT}/external/TLSF-2.4.6/src
${APP_ROOT}/external
${QTAPP_ROOT}/osc
${QTAPP_ROOT}/model
${QTAPP_ROOT}/visualizer
${QTAPP_ROOT}/widgets
${QTAPP_ROOT}/Utils
${CMAKE_BINARY_DIR}
include)
target_link_libraries(${APP_NAME}
PRIVATE
SonicPi::API
QScintilla
Threads::Threads
SingleApplication::SingleApplication)
if(Qt5_FOUND)
target_link_libraries(${APP_NAME}
PRIVATE
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::OpenGL
Qt5::Concurrent
Qt5::Network)
else()
target_link_libraries(${APP_NAME}
PRIVATE
Qt::Core
Qt::Gui
Qt::Widgets
Qt::OpenGL
Qt::Concurrent
Qt::Network
Qt::OpenGLWidgets)
endif()
if(WITH_QT_GUI_WEBENGINE)
if(Qt5_FOUND)
target_link_libraries(${APP_NAME}
PRIVATE
Qt5::WebEngineWidgets)
else()
target_link_libraries(${APP_NAME}
PRIVATE
Qt::WebEngineWidgets)
endif()
endif()
# Compile options and OS specific libraries
if(WIN32)
# Workaround Qt + MSVC 19 compile issue in release build.
target_compile_options(${APP_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/wd4005 /W3 /D_CRT_SECURE_NO_WARNINGS /D_WINSOCK_DEPRECATED_NO_WARNINGS /DBOOST_DATE_TIME_NO_LIB>)
target_compile_options(${APP_NAME} PRIVATE "$<$<CONFIG:DEBUG>:-DTRACY_ENABLE=1>")
target_compile_options(${APP_NAME} PRIVATE "$<$<CONFIG:RELWITHDEBINFO>:-DTRACY_ENABLE=1>")
elseif(${CMAKE_SYSTEM_NAME} MATCHES Linux)
# Link librt
target_link_libraries(${APP_NAME} PRIVATE rt)
endif()
# Deploy Qt binaries to the output on windows, and copy the CRT to the release folder
if(WIN32)
# Visual Studio
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP true)
include(InstallRequiredSystemLibraries)
file(COPY ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Release)
# Run winddeployqt if it can be found, to ensure installed dependencies
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_PREFIX_PATH}/bin/windeployqt $<TARGET_FILE:${APP_NAME}>)
endif() # Win32
# Make convenient source groups in the IDE
source_group(SonicPi FILES ${SOURCES})
source_group(Osc FILES ${OSC_SOURCES})
source_group(Scintilla FILES ${EDITOR_SOURCES})
source_group(Qt FILES ${QT_SOURCES})
source_group(OldApi FILES ${OLD_API_SOURCES})
source_group(NewApi FILES ${NEW_API_SOURCES})
source_group(Qt\\AutoMoc FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_automoc.cpp )
source_group(Qt\\AutoMoc REGULAR_EXPRESSION "(mocs_*|qrc_.*|QtAwesome.*)" )