This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
CMakeLists.txt
190 lines (166 loc) · 8.05 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
cmake_minimum_required(VERSION 3.15)
project(rave-vst VERSION 0.0.1)
set (target_name ${PROJECT_NAME})
##### Compilation options
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
if(APPLE)
set (formats AU VST3 Standalone)
else()
set (formats VST3 Standalone)
endif()
include("cmake/compiler_settings.cmake")
setup_compilers()
set(CMAKE_CXX_FLAGS "-fPIC")
set(CMAKE_CXX_STANDARD 20)
# Torch does not compile with C++ standard 20 on Windows
if (MSVC)
set(CMAKE_CXX_STANDARD 17)
endif (MSVC)
##### Helper function to add all images from a given folder into a JUCE binary data file
function(add_images_from_directory target imagesSubFolder)
set (ImagesDir ${CMAKE_CURRENT_LIST_DIR}/${imagesSubFolder})
file(GLOB_RECURSE images
"${ImagesDir}/*.jpg"
"${ImagesDir}/*.png"
"${ImagesDir}/*.jpeg"
)
if(NOT images STREQUAL "")
set (ImagesTarget "${target}-Images")
juce_add_binary_data(${ImagesTarget} SOURCES ${images})
target_link_libraries(${target} PRIVATE ${ImagesTarget})
endif()
endfunction()
##### Torch related
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(add_torch)
list(APPEND CMAKE_PREFIX_PATH "${torch_dir}/libtorch")
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
##### Juce related
option(JUCE_BUILD_EXTRAS "Build JUCE Extras" OFF)
option(JUCE_BUILD_EXAMPLES "Build JUCE Examples" OFF)
# As we're getting JUCE via git submodules and not using a possible system JUCE
add_subdirectory(juce)
##### `juce_add_console_app` adds an executable target with the name passed as the first argument
# (ConsoleAppExample here). This target is a normal CMake target, but has a lot of extra properties
# set up by default. This function accepts many optional arguments. Check the readme at
# `docs/CMake API.md` in the JUCE repo for the full list.
juce_add_plugin(${target_name}
ICON_BIG assets/icon.png # ICON_* arguments specify a path to an image file to use as an icon for the Standalone
ICON_SMALL assets/icon.png
COMPANY_NAME acids # Specify the name of the plugin's author
VST2_CATEGORY kPlugCategEffect
VST3_CATEGORIES Fx Generator Synth
PLUGIN_MANUFACTURER_CODE Acid # A four-character manufacturer id with at least one upper-case character
PLUGIN_CODE Rave # A unique four-character plugin id with exactly one upper-case character
FORMATS ${formats} # The formats to build. Other valid formats are: AAX Unity VST AU AUv3
PRODUCT_NAME "RAVE") # The name of the final executable, which can differ from the target name
##### `juce_generate_juce_header` will create a JuceHeader.h for a given target, which will be generated
# into the build tree. This header 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 the JUCE module headers for a particular target; if you're happy to
# include module headers directly, you probably don't need to call this.
juce_generate_juce_header(rave-vst)
##### `target_sources` adds source files to a target. We pass the target that needs the sources as the
# first argument, then a visibility parameter for the sources which should normally be PRIVATE.
# Finally, we supply a list of source files that will be built into the target. This is a standard
# CMake command.
add_subdirectory(source)
add_images_from_directory(${target_name} assets)
##### `target_compile_definitions` adds some preprocessor definitions to our target. In a Projucer
# project, these might be passed in the 'Preprocessor Definitions' field. JUCE modules also make use
# of compile definitions to switch certain features on/off, so if there's a particular feature you
# need that's not on by default, check the module header for the correct flag to set here. These
# definitions will be visible both to your code, and also the JUCE module code, so for new
# definitions, pick unique names that are unlikely to collide! This is a standard CMake command.
target_compile_definitions(${target_name}
PRIVATE
# 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_console_app` call
JUCE_USE_CURL=0
JUCE_VST3_CAN_REPLACE_VST2=0
) # If you remove this, add `NEEDS_CURL TRUE` to the `juce_add_console_app` call
# If the target needs extra binary assets, they can be added here. The first argument is the name of
# a new static library target that will include all the binary resources. There is an optional
# `NAMESPACE` argument that can specify the namespace of the generated binary data class. Finally,
# the SOURCES argument should be followed by a list of source files that should be built into the
# static library. These source files can be of any kind (wav data, images, fonts, icons etc.).
# Conversion to binary-data will happen when the target is built.
# juce_add_binary_data(ConsoleAppData SOURCES ...)
##### Automatically bundle libtorch into the targets
get_target_property(active_formats ${target_name} JUCE_FORMATS)
if (APPLE)
set(libtorch_files
"${TORCH_INSTALL_PREFIX}/lib/libtorch.dylib"
"${TORCH_INSTALL_PREFIX}/lib/libtorch_cpu.dylib"
"${TORCH_INSTALL_PREFIX}/lib/libc10.dylib"
)
endif (APPLE)
##### Unix
if (UNIX AND NOT APPLE)
if (NOT EXISTS "${TORCH_INSTALL_PREFIX}/lib/libiomp5.so")
message(STATUS "UNIX plateform detected: Downloading MKL shared libs")
set(mkl_dir ${TORCH_INSTALL_PREFIX}/lib/)
set(mkl_url "https://github.com/01org/mkl-dnn/releases/download/v0.9/mklml_lnx_2018.0.20170425.tgz")
file(DOWNLOAD
${mkl_url}
${mkl_dir}/mkl_cc.tgz
SHOW_PROGRESS
)
message(STATUS "extracting")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf mkl_cc.tgz
WORKING_DIRECTORY ${mkl_dir})
file(REMOVE ${mkl_dir}/mkl_cc.tgz)
configure_file(
"${TORCH_INSTALL_PREFIX}/lib/mklml_lnx_2018.0.20170425/lib/libiomp5.so"
"${TORCH_INSTALL_PREFIX}/lib/libiomp5.so"
)
endif()
set(libtorch_files
"${TORCH_INSTALL_PREFIX}/lib/libtorch.so"
"${TORCH_INSTALL_PREFIX}/lib/libtorch_cpu.so"
"${TORCH_INSTALL_PREFIX}/lib/libc10.so"
"${TORCH_INSTALL_PREFIX}/lib/libiomp5.so"
)
endif (UNIX AND NOT APPLE)
#####
foreach(kind IN LISTS active_formats)
foreach(resource_file IN LISTS libtorch_files)
target_sources(${target_name}_${kind} PRIVATE ${resource_file})
set_source_files_properties(${resource_file} PROPERTIES
MACOSX_PACKAGE_LOCATION "torch/libtorch"
)
endforeach()
endforeach()
# `target_link_libraries` links libraries and JUCE modules to other libraries or executables. Here,
# we're linking our executable target to the `juce::juce_core` module. Inter-module dependencies are
# resolved automatically. If you'd generated a binary data target above, you would need to link to
# it here too. This is a standard CMake command.
target_link_libraries(${target_name}
PRIVATE
# ConsoleAppData # If you'd created a binary data target, you'd link to it here
juce::juce_core
juce::juce_events
juce::juce_graphics
juce::juce_gui_basics
juce::juce_audio_utils
juce::juce_audio_basics
juce::juce_dsp
torch
PUBLIC
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags)
##### Windows
if (MSVC)
set(base_folder "${CMAKE_CURRENT_BINARY_DIR}/rave-vst_artefacts/${CMAKE_BUILD_TYPE}/Standalone")
add_custom_target(build-time-make-directory ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${base_folder})
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
${base_folder}/)
endif()