-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
274 lines (236 loc) · 11.9 KB
/
CMakeLists.txt
File metadata and controls
274 lines (236 loc) · 11.9 KB
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
# TODO: work out how to remove local libtorch path from linker
# The first line of any CMake project should be a call to `cmake_minimum_required`, which checks
# that the installed CMake will be able to understand the following CMakeLists, and ensures that
# CMake's behaviour is compatible with the named version. This is a standard CMake command, so more
# information can be found in the CMake docs.
cmake_minimum_required(VERSION 3.22)
function(print_matching_variables pattern)
get_cmake_property(variable_names VARIABLES)
message(STATUS "Variables matching ${pattern}:")
foreach(variable_name ${variable_names})
if (${variable_name} MATCHES "${pattern}")
message(STATUS "${variable_name} = ${${variable_name}}")
endif()
endforeach()
endfunction()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# enable AddressSanitizer to detect memory issues
# mainly useful for debugging segmentation faults during compilation
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
# set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fsanitize=address")
# ThreadSanitizer to detect deadlocks
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -g")
# set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} -fsanitize=thread")
endif()
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum macOS deployment version")
# The top-level CMakeLists.txt file for a project must contain a literal, direct call to the
# `project()` command. `project()` sets up some helpful variables that describe source/binary
# directories, and the current project version. This is a standard CMake command.
project(ENVIRONMENTAL_INSTRUMENTS VERSION 2.0.2)
# For debugging linker commands
# set(CMAKE_VERBOSE_MAKEFILE ON)
# Bundle linked libraries, so don't add local paths
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
add_subdirectory(JUCE) # If you've put JUCE in a subdirectory called JUCE
juce_add_plugin(EnvironmentalInstruments
# VERSION ... # Set this if the plugin version is different to the project version
# ICON_BIG ... # ICON_* arguments specify a path to an image file to use as an icon for the Standalone
# ICON_SMALL ...
COMPANY_NAME "GoldenAudio"
IS_SYNTH TRUE
# NEEDS_MIDI_INPUT TRUE/FALSE # Does the plugin need midi input?
# NEEDS_MIDI_OUTPUT TRUE/FALSE # Does the plugin need midi output?
# IS_MIDI_EFFECT TRUE/FALSE # Is this plugin a MIDI effect?
# EDITOR_WANTS_KEYBOARD_FOCUS TRUE/FALSE # Does the editor need keyboard focus?
COPY_PLUGIN_AFTER_BUILD TRUE
PLUGIN_MANUFACTURER_CODE Auri
PLUGIN_CODE Envi
# GarageBand 10.3 requires the first letter to be upper-case, and the remaining letters to be lower-case
FORMATS VST3 Standalone # The formats to build. Other valid formats are: AAX Unity VST AU AUv3
PRODUCT_NAME "EnvironmentalInstruments")
# `juce_generate_juce_header` will create a JuceHeader.h for a given target, which will be generated
# into your build tree. This should be included with `#include <JuceHeader.h>`. The include path for
# this header will be automatically added to the target. The main function of the JuceHeader is to
# include all your JUCE module headers; if you're happy to include module headers directly, you
# probably don't need to call this.
# juce_generate_juce_header(AudioPluginExample)
target_sources(EnvironmentalInstruments
PRIVATE
PluginEditor.cpp
PluginProcessor.cpp
MovementIn.cpp
SpinningDial.cpp
MovementDial.cpp
SensorToAudio.cpp
circular_buffer.h
Types.h
GaussianNoise.cpp
Logger.h
)
target_compile_definitions(EnvironmentalInstruments
PUBLIC
# JUCE_WEB_BROWSER and JUCE_USE_CURL would be on by default, but you might not need them.
JUCE_WEB_BROWSER=0 # If you remove this, add `NEEDS_WEB_BROWSER TRUE` to the `juce_add_plugin` call
JUCE_USE_CURL=0 # If you remove this, add `NEEDS_CURL TRUE` to the `juce_add_plugin` call
JUCE_VST3_CAN_REPLACE_VST2=0)
# Make CMAKE_BUILD_TYPE known to code
target_compile_definitions(EnvironmentalInstruments
PRIVATE
CMAKE_BUILD_TYPE=\"${CMAKE_BUILD_TYPE}\"
PROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
PROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}
PROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}
)
# add NN model (bundle model)
# Copy the model to the VST3 plugin bundle
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/EnvironmentalInstruments_artefacts/${CMAKE_BUILD_TYPE}/VST3/EnvironmentalInstruments.vst3/Contents/Resources)
add_custom_command(
TARGET EnvironmentalInstruments POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/models/cornellbird_causal_epoch373_0.99.ts
${CMAKE_BINARY_DIR}/EnvironmentalInstruments_artefacts/${CMAKE_BUILD_TYPE}/VST3/EnvironmentalInstruments.vst3/Contents/Resources/
COMMENT "Copying model to VST3 bundle..."
)
# Copy the model to the Standalone app bundle
add_custom_command(
TARGET EnvironmentalInstruments POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/models/cornellbird_causal_epoch373_0.99.ts
${CMAKE_BINARY_DIR}/EnvironmentalInstruments_artefacts/${CMAKE_BUILD_TYPE}/Standalone/EnvironmentalInstruments.app/Contents/Resources/
COMMENT "Copying model to Standalone app bundle..."
)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -faligned-allocation")
if (CMAKE_OSX_ARCHITECTURES STREQUAL "")
set(CMAKE_OSX_ARCHITECTURES ${CMAKE_HOST_SYSTEM_PROCESSOR})
endif()
message("CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
endif()
# Include pytorch
# include MKL on MacOS x86 builds
if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
# get MKL 2023.2.2 from Intel website
# comment the line target_link_libraries(caffe2::mkl INTERFACE ${MKL_LIBRARIES}) from deps/x86_64/libtorch/share/cmake/Caffe2/public/mkl.cmake
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/deps/x86_64/oneapi/mkl/latest")
endif()
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/deps/${CMAKE_OSX_ARCHITECTURES}/libtorch")
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET EnvironmentalInstruments
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
# FIXME: this probably needs to be set to something for windows build
$<TARGET_FILE_DIR:example-app>)
endif (MSVC)
# Include backend
add_subdirectory(${CMAKE_SOURCE_DIR}/backend)
target_include_directories(EnvironmentalInstruments
PRIVATE
${CMAKE_SOURCE_DIR}/backend
)
add_subdirectory(JoyConBridge/src/JoyConBridge)
target_include_directories(EnvironmentalInstruments PRIVATE ${CMAKE_SOURCE_DIR}/JoyConBridge/src/JoyConBridge)
message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message("TORCH_LIBRARIES: ${TORCH_LIBRARIES}")
target_link_libraries(EnvironmentalInstruments
PRIVATE
# "${TORCH_LIBRARIES}"
backend
juce::juce_audio_utils
JoyConBridge
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags
)
message(STATUS "Binary directory: ${CMAKE_BINARY_DIR}")
message(STATUS "TORCH_INSTALL_PREFIX: ${TORCH_INSTALL_PREFIX}")
# Get the JUCE formats for the EnvironmentalInstruments target
get_target_property(EI_FORMATS EnvironmentalInstruments JUCE_FORMATS)
message(STATUS "Target formats: ${EI_FORMATS}")
if (APPLE)
# Iterate over the formats and set INSTALL_RPATH for each sub-target
# Loads dylibs from bundle
foreach(format ${EI_FORMATS})
set_target_properties(EnvironmentalInstruments_${format} PROPERTIES
# BUILD_WITH_INSTALL_RPATH TRUE
# INSTALL_RPATH "@loader_path"
BUILD_WITH_INSTALL_RPATH FALSE
LINK_FLAGS "-Wl,-rpath,@loader_path/"
)
message(STATUS "Set INSTALL_RPATH for EnvironmentalInstruments_${format}")
endforeach()
# COPY TORCH DYLIB IN THE LOADER FOLDER FOR STANDALONE
add_custom_command(
TARGET EnvironmentalInstruments
POST_BUILD
COMMAND cp "${TORCH_INSTALL_PREFIX}/lib/*.dylib" "${CMAKE_BINARY_DIR}/EnvironmentalInstruments_artefacts/${CMAKE_BUILD_TYPE}/Standalone/EnvironmentalInstruments.app/Contents/MacOS/"
COMMENT "Copy Torch Libraries to Standalone"
)
# COPY TORCH DYLIB IN THE LOADER FOLDER FOR VST3
add_custom_command(
TARGET EnvironmentalInstruments
POST_BUILD
COMMAND cp "${TORCH_INSTALL_PREFIX}/lib/*.dylib" "${CMAKE_BINARY_DIR}/EnvironmentalInstruments_artefacts/${CMAKE_BUILD_TYPE}/VST3/EnvironmentalInstruments.vst3/Contents/MacOS/"
COMMENT "Copy Torch Libraries to VST3"
)
add_custom_command(
TARGET EnvironmentalInstruments
POST_BUILD
COMMAND cp "${CMAKE_BINARY_DIR}/JoyConBridge/src/JoyConBridge/hidapi/src/mac/*.dylib"
"${CMAKE_BINARY_DIR}/EnvironmentalInstruments_artefacts/${CMAKE_BUILD_TYPE}/Standalone/EnvironmentalInstruments.app/Contents/MacOS/"
COMMENT "Copy HIDAPI dylibs to Standalone target"
)
add_custom_command(
TARGET EnvironmentalInstruments
POST_BUILD
COMMAND cp "${CMAKE_BINARY_DIR}/JoyConBridge/src/JoyConBridge/hidapi/src/mac/*.dylib"
"${CMAKE_BINARY_DIR}/EnvironmentalInstruments_artefacts/${CMAKE_BUILD_TYPE}/VST3/EnvironmentalInstruments.vst3/Contents/MacOS/"
COMMENT "Copy HIDAPI dylibs to VST3 target"
)
# if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
# add_custom_command(
# TARGET EnvironmentalInstruments
# POST_BUILD
# COMMAND "codesign" "--force" "--deep" "-s" "-" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${EnvironmentalInstruments_EXTERN_OUTPUT_NAME}.mxo"
# COMMENT "Codesign external"
# )
# endif()
endif()
if (MSVC) # COPY TORCH DLL IN THE LOADER FOLDER
add_custom_command(TARGET EnvironmentalInstruments POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${TORCH_INSTALL_PREFIX}/lib/" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/
)
set_property(TARGET EnvironmentalInstruments PROPERTY CXX_STANDARD 20)
endif()
# Show all defined targets
# Taken from https://stackoverflow.com/a/62311397
function(get_all_targets var)
set(targets)
get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR})
set(${var} ${targets} PARENT_SCOPE)
endfunction()
macro(get_all_targets_recursive targets dir)
get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
foreach(subdir ${subdirectories})
get_all_targets_recursive(${targets} ${subdir})
endforeach()
get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
list(APPEND ${targets} ${current_targets})
endmacro()
get_all_targets(all_targets)
message("All targets: ${all_targets}")
# get_target_property(install_rpath_use_link_path EnvironmentalInstruments_Standalone INSTALL_RPATH_USE_LINK_PATH)
# get_target_property(target_rpath EnvironmentalInstruments_Standalone INSTALL_RPATH)
# get_target_property(target_build_rpath EnvironmentalInstruments_Standalone BUILD_WITH_INSTALL_RPATH)
# message(STATUS "INSTALL_RPATH of EnvironmentalInstruments_Standalone: ${target_rpath}")
# message(STATUS "BUILD_WITH_INSTALL_RPATH of EnvironmentalInstruments_Standalone: ${target_build_rpath}")
# message(STATUS "INSTALL_RPATH_USE_LINK_PATH of EnvironmentalInstruments_Standalone: ${INSTALL_RPATH_USE_LINK_PATH}")