-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
204 lines (168 loc) · 10.7 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
# Example Audio Plugin CMakeLists.txt
# To get started on a new plugin, copy this entire folder (containing this file and C++ sources) to
# a convenient location, and then start making modifications.
# 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.15)
# 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.
# Set message log level to VERBOSE to see more details about what CMake is doing.
#set(CMAKE_MESSAGE_LOG_LEVEL VERBOSE)
# Name of the project and the plugin. Avoid spaces and special characters.
set(PROJECT_NAME "Speclet")
set(CURRENT_VERSION "1.0.1")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
set(PRODUCT_NAME_POSTFIX "")
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPERCASE)
if (NOT "${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELEASE")
set(PRODUCT_NAME_POSTFIX "-${CMAKE_BUILD_TYPE}")
message(STATUS "PRODUCT_NAME_POSTFIX: ${PRODUCT_NAME_POSTFIX}")
endif()
# For simplilicity, the name of the project is also the name of the targe.
project(${PROJECT_NAME} VERSION ${CURRENT_VERSION})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(Environment)
# Build Options
option(JUCE_BUILD_EXTRAS "Build JUCE Extras" OFF)
option(JUCE_BUILD_EXAMPLES "Build JUCE Examples" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF) # needed for fftw to not depend on dll
# Import dependencies
#CPMAddPackage("https://math.ryerson.ca/~lkolasa/xxx.tar.gz") # Not online anymore (2022). Now directly included in this repository.
CPMGetPackage(JUCE)
CPMGetPackage(fftw)
CPMGetPackage(span)
# If you've installed JUCE somehow (via a package manager, or directly using the CMake install
# target), you'll need to tell this project that it depends on the installed copy of JUCE. If you've
# included JUCE directly in your source tree (perhaps as a submodule), you'll need to tell CMake to
# include that subdirectory as part of the build.
# find_package(JUCE CONFIG REQUIRED) # If you've installed JUCE to your system
# or
# add_subdirectory(${JUCE_SOURCE_DIR}) # If you've put JUCE in a subdirectory called JUCE
# If you are building a VST2 or AAX plugin, CMake needs to be told where to find these SDKs on your
# system. This setup should be done before calling `juce_add_plugin`.
# juce_set_vst2_sdk_path(...)
# juce_set_aax_sdk_path(...)
# `juce_add_plugin` adds a static library target with the name passed as the first argument
# (Speclet here). This target is a normal CMake target, but has a lot of extra properties set
# up by default. As well as this shared code static library, this function adds targets for each of
# the formats specified by the FORMATS arguments. 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("${PROJECT_NAME}"
PRODUCT_NAME "${PROJECT_NAME}${PRODUCT_NAME_POSTFIX}" # The name of the final executable, which can differ from the target name
COMPANY_NAME "Johannes Troppacher" # Specify the name of the plugin's author
COMPANY_COPYRIGHT "(c)2011 by Johannes Troppacher" # Specify the copyright notice for the plugin
COMPANY_WEBSITE "https://github.com/JohT/speclet" # Specify the website for the plugin
DESCRIPTION "Audio Spectrum Analyzer using Fourier- and Wavelet-Transformation (v${CURRENT_VERSION})" # A short description of the plugin
# VERSION 0.9.0 # Set this if the plugin version is different to the project version
FORMATS VST3 AU Standalone # The formats to build. Other valid formats are: AAX Unity VST AU AUv3
PLUGIN_MANUFACTURER_CODE "JohT" # A four-character manufacturer id with at least one upper-case character
PLUGIN_CODE "SpcJ" # A unique four-character plugin id with exactly one upper-case character
# GarageBand 10.3 requires the first letter to be upper-case, and the remaining letters to be lower-case
# ICON_SMALL ...
ICON_BIG "${CMAKE_CURRENT_SOURCE_DIR}/image/SpecletBlueIcon.png"
IS_SYNTH FALSE # Is this a synth or an effect?
NEEDS_MIDI_INPUT FALSE # Does the plugin need midi input?
NEEDS_MIDI_OUTPUT FALSE # Does the plugin need midi output?
IS_MIDI_EFFECT FALSE # Is this plugin a MIDI effect?
EDITOR_WANTS_KEYBOARD_FOCUS FALSE # Does the editor need keyboard focus?
# COPY_PLUGIN_AFTER_BUILD TRUE # Should the plugin be installed to a default location after building?
VST3_CATEGORIES "Analyzer" # VST3 Plugin Category
)
# `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("${PROJECT_NAME}")
# Compile Project with C++20 Standard
target_compile_features("${PROJECT_NAME}" PRIVATE cxx_std_20)
message(VERBOSE "C++ Language Standard set to C++20 for Target ${PROJECT_NAME}")
# Get all source files in the src directory and store them in the project_sources variable.
# GLOB_RECURSE is not recommended but used here for simplicity: https://cmake.org/cmake/help/latest/command/file.html?highlight=CONFIGURE_DEPENDS#filesystem
FILE(GLOB_RECURSE project_sources CONFIGURE_DEPENDS "src/*.cpp")
message(VERBOSE "Sources in ${CMAKE_CURRENT_SOURCE_DIR}/src:")
foreach(source ${project_sources})
message(VERBOSE "'${source}'")
endforeach()
# `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.
target_sources("${PROJECT_NAME}" PRIVATE ${project_sources})
# Import fftw3 api headers to include with #include "fftw3.h"
if (fftw_ADDED)
include_directories("${PROJECT_NAME}" PRIVATE "${fftw_SOURCE_DIR}/api")
message(VERBOSE "FFTW api (headers) directory included for all targets: ${fftw_SOURCE_DIR}/api")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
# Using GNU or Clang compiler
target_compile_options(fftw3 PRIVATE "-m64;-fPIC;")
endif()
endif()
# Import span header to include with #include "tcb/span.hpp"
if (span_ADDED)
include_directories("${PROJECT_NAME}" PRIVATE "${span_SOURCE_DIR}/include")
message(VERBOSE "tcb span headers directory included for all targets: ${span_SOURCE_DIR}/include")
endif()
# Import magic_enum header to include with #include "magic_enum.hpp"
#if (magic_enum_ADDED)
# include_directories("${PROJECT_NAME}" PRIVATE "${magic_enum_SOURCE_DIR}/include")
# message(VERBOSE "magic_enum headers directory included for all targets: ${magic_enum_SOURCE_DIR}/include")
#endif()
# List all include directories for the target.
get_target_property(PROJECT_INCLUDES "${PROJECT_NAME}" INCLUDE_DIRECTORIES)
foreach(dir ${PROJECT_INCLUDES})
message(VERBOSE "Project_include_dir='${dir}'")
endforeach()
# Add libraries to the target that needed to be included inside the repository:
add_subdirectory(lib/wave++)
include_directories("${PROJECT_NAME}" PRIVATE "lib/wave++/source")
# `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("${PROJECT_NAME}"
PUBLIC
# JUCE_WEB_BROWSER and JUCE_USE_CURL would be on by default, but you might not need them.
JUCE_DISPLAY_SPLASH_SCREEN=0 # Plugins with GPL3 License can disable splash screen
JUCE_REPORT_APP_USAGE=0
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
$<$<CONFIG:Debug>:LOG_PERFORMANCE> # Create performancelog.json in Debug build for google chrome tracing
_USE_MATH_DEFINES
)
# Sets compile options for the target:
include(CompilerOptions)
# If your target needs extra binary assets, you can add them 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 your target is built.
# juce_add_binary_data(AudioPluginData SOURCES ...)
# `target_link_libraries` links libraries and JUCE modules to other libraries or executables. Here,
# we're linking our executable target to the `juce::juce_audio_utils` module. Inter-module
# dependencies are resolved automatically, so `juce_core`, `juce_events` and so on will also be
# linked automatically. If we'd generated a binary data target above, we would need to link to it
# here too. This is a standard CMake command.
target_link_libraries("${PROJECT_NAME}"
PRIVATE
# AudioPluginData # If we'd created a binary data target, we'd link to it here
juce::juce_core
juce::juce_dsp
juce::juce_audio_utils
juce::juce_gui_basics
fftw3
wave++
PUBLIC
Speclet::CompilerOptions
juce::juce_recommended_config_flags
juce::juce_recommended_lto_flags
juce::juce_recommended_warning_flags)
# Add tests
add_subdirectory(test)