-
Notifications
You must be signed in to change notification settings - Fork 16
/
CMakeLists.txt
234 lines (212 loc) · 9.27 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
#-------------------------------------------------------------------------------
# Require VERSION 3.15.0 is needed to correctly handle virtualenvs with
# FindPython3
#-------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.15.0)
#--------------------------------------------------------------------------------
# Allow deployment on older versions of macOS (back to 10.14 Mojave),
# and default to the include/lib paths of the current Python virtualenv
# (important for cross-compiling wheels)
#--------------------------------------------------------------------------------
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum macOS deployment version" FORCE)
set(Python_FIND_VIRTUALENV STANDARD)
set(Python_FIND_FRAMEWORKS LAST)
#-------------------------------------------------------------------------------
# Note that project() call should come after set CMAKE_OSX_DEPLOYMENT_TARGET,
# but CMAKE_SYSTEM_NAME is only available *after* project(), so any platform-
# dependent code should come later on.
#-------------------------------------------------------------------------------
project(SignalFlow C CXX)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Develop)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
#-------------------------------------------------------------------------------
# On Apple, build the current native system by default
#-------------------------------------------------------------------------------
if (NOT CMAKE_OSX_ARCHITECTURES)
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CMAKE_OSX_ARCHITECTURES
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
#-------------------------------------------------------------------------------
# Select the appropriate homebrew prefix by architecture.
# This is necessary so that the library is correctly linked against
# dependencies later on.
#-------------------------------------------------------------------------------
if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(CMAKE_PREFIX_PATH /opt/homebrew)
else()
set(CMAKE_PREFIX_PATH /usr/local)
endif()
endif()
#--------------------------------------------------------------------------------
# Print config setup to help with debugging
#--------------------------------------------------------------------------------
include(CMakePrintHelpers)
cmake_print_variables(CMAKE_SYSTEM_NAME)
cmake_print_variables(CMAKE_OSX_ARCHITECTURES)
cmake_print_variables(CMAKE_PREFIX_PATH)
#-------------------------------------------------------------------------------
# Use C++11
#-------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MACOSX_RPATH 1)
#-------------------------------------------------------------------------------
# Compiler flags for optimisations, warnings, etc.
#-------------------------------------------------------------------------------
if (MSVC)
#-------------------------------------------------------------------------------
# Windows Visual C: Enable parallelisation
#-------------------------------------------------------------------------------
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
else()
#-------------------------------------------------------------------------------
# GCC/Clang: Enable strict compiler warnings
#-------------------------------------------------------------------------------
add_compile_options(
-pedantic
-fPIC
-Wall
)
#-------------------------------------------------------------------------------
# Hide superfluous compiler warnings on macOS
#-------------------------------------------------------------------------------
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_options(
-Wno-gnu-zero-variadic-macro-arguments
-Wno-vla-extension
)
endif()
endif()
include_directories(
/usr/local/include
/opt/homebrew/include
source/include
source/lib
source/lib/pybind11/include
)
#-------------------------------------------------------------------------------
# Compiler flags for debug vs release vs dev mode
#-------------------------------------------------------------------------------
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
message("Building in debug mode")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_options(-O1)
else()
add_compile_options(-ggdb3 -O0 -DDEBUG)
endif()
elseif (${CMAKE_BUILD_TYPE} STREQUAL "Release")
message("Building in release mode")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_options(-O2)
else()
add_compile_options(-O3 -funroll-loops)
endif()
else()
message("Building in dev mode")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_options(-O1)
else()
add_compile_options(-O0)
endif()
endif()
#-------------------------------------------------------------------------------
# Specify source files.
# See source/CMakeLists.
#-------------------------------------------------------------------------------
set(SRC)
add_subdirectory("source/src")
set(SRC ${SRC} source/lib/json11/json11.cpp)
#-------------------------------------------------------------------------------
# For builds of the Python bindings, add Python dependencies and flags
#-------------------------------------------------------------------------------
if (CMAKE_BUILD_PYTHON)
find_package (Python3 COMPONENTS Interpreter Development)
include_directories(${Python3_INCLUDE_DIRS})
set(CMAKE_SHARED_LIBRARY_PREFIX "")
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
add_link_options(-w -undefined dynamic_lookup)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".pyd")
endif()
endif()
#-------------------------------------------------------------------------------
# Specify output library
#-------------------------------------------------------------------------------
add_library(signalflow SHARED ${SRC})
#-------------------------------------------------------------------------------
# Pass SIGNALFLOW_VERSION from CMake flag to compiler
#-------------------------------------------------------------------------------
add_compile_definitions(SIGNALFLOW_VERSION="${SIGNALFLOW_VERSION}")
#-------------------------------------------------------------------------------
# Dependency: libsndfile
#-------------------------------------------------------------------------------
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(SNDFILE_BINARY_DIR "${PROJECT_SOURCE_DIR}/../libsndfile-1.2.2-win64" CACHE PATH "For Windows, path to downloaded sndfile directory")
add_definitions(-DHAVE_SNDFILE)
target_link_libraries(signalflow "${SNDFILE_BINARY_DIR}/lib/sndfile.lib")
include_directories(signalflow "${SNDFILE_BINARY_DIR}/include/")
else()
find_library(SNDFILE sndfile)
if (SNDFILE)
message("Found sndfile")
add_definitions(-DHAVE_SNDFILE)
target_link_libraries(signalflow ${SNDFILE})
else()
message(FATAL_ERROR "Couldn't find libsndfile")
endif()
endif()
#-------------------------------------------------------------------------------
# Dependency: fftw3
#-------------------------------------------------------------------------------
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(FFTW_BUILD_DIR "${PROJECT_SOURCE_DIR}/../fftw-3.3.5-dll64" CACHE PATH "Path to prebuilt FFTW library (will use find_library if blank)")
include_directories("${FFTW_BUILD_DIR}")
add_definitions(-DFFT_FFTW)
target_link_libraries(signalflow
"${FFTW_BUILD_DIR}/libfftw3-3.lib"
"${FFTW_BUILD_DIR}/libfftw3f-3.lib"
"${FFTW_BUILD_DIR}/libfftw3l-3.lib"
)
else()
find_library(FFTW3F fftw3f)
if (FFTW3F)
message("Found fftw3f")
target_link_libraries(signalflow ${FFTW3F})
add_definitions(-DFFT_FFTW)
else()
message(FATAL_ERROR "Couldn't find fftw3f")
endif()
endif()
endif(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_library(VAMP vamp-hostsdk)
if (VAMP)
message("Found vamp")
add_definitions(-DHAVE_VAMP)
target_link_libraries(signalflow ${VAMP})
else()
message(WARNING "Couldn't find vamp")
endif()
#-------------------------------------------------------------------------------
# Specify additional linker dependencies
#-------------------------------------------------------------------------------
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_libraries(signalflow
"-framework Accelerate"
"-framework AppKit"
)
endif()
if (CMAKE_BUILD_PYTHON)
# TODO: Check this logic (why doesn't Darwin require linking against Python3?)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(signalflow ${Python3_LIBRARIES})
endif()
endif()
#-------------------------------------------------------------------------------
# Install shared lib and all includes
#-------------------------------------------------------------------------------
install(TARGETS signalflow DESTINATION lib)
install(DIRECTORY source/include/signalflow DESTINATION include)