forked from flucoma/flucoma-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
247 lines (202 loc) · 7.01 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
# Part of the Fluid Corpus Manipulation Project (http://www.flucoma.org/)
# Copyright University of Huddersfield.
# Licensed under the BSD-3 License.
# See license.md file in the project root for full license information.
# This project has received funding from the European Research Council (ERC)
# under the European Union’s Horizon 2020 research and innovation programme
# (grant agreement No 725899).
cmake_minimum_required (VERSION 3.18)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/script")
#set module path at top level so wrapper projects can easily include fluid_version script
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/script"
PARENT_SCOPE)
endif()
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "")
#A consequence of targetting 10.8. Needs to be set globally from 10.15 onwards in order for the test program to compile successfully during configure
string(APPEND CMAKE_CXX_FLAGS " -stdlib=libc++")
endif()
project (flucoma-core LANGUAGES CXX)
include(flucoma-buildtype)
include(FlucomaVersion.cmake)
include(FlucomaClients.cmake)
include(FetchContent)
set(HISS_PATH "" CACHE PATH "The path to a HISSTools_Library folder. Will pull from github if not set")
set(EIGEN_PATH "" CACHE PATH "The path to an Eigen installation (>=3.3.5). Will pull from github if not set")
set(SPECTRA_PATH "" CACHE PATH "The path to aa Spectra installation. Will pull from github if not set")
IF(APPLE)
find_library(ACCELERATE Accelerate)
IF (NOT ACCELERATE)
message(FATAL_ERROR "Accelerate framework not found")
ENDIF()
ENDIF (APPLE)
# Grab the Fluid Decpomposition header files so they can be added to IDE builds
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/**/*.hpp")
# Either download or point to dependencies
FetchContent_Declare(
HISSTools
GIT_REPOSITORY https://github.com/AlexHarker/HISSTools_Library
GIT_PROGRESS TRUE
GIT_TAG f3292ad
)
FetchContent_Declare(
Eigen
GIT_SHALLOW TRUE
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_PROGRESS TRUE
GIT_BRANCH "3.4"
GIT_TAG "3.4.0"
)
FetchContent_Declare(
Spectra
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/yixuan/spectra
GIT_PROGRESS TRUE
GIT_BRANCH "master"
GIT_TAG "v1.0.1"
)
FetchContent_Declare(
tl_optional
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/TartanLlama/optional.git
GIT_PROGRESS TRUE
)
#see https://json.nlohmann.me/integration/cmake/#fetchcontent
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
set(JSON_SystemInclude ON CACHE BOOL "")
FetchContent_Declare(
Memory
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/foonathan/memory.git
GIT_PROGRESS TRUE
GIT_TAG main
)
set(FMT_INSTALL OFF CACHE BOOL "")
FetchContent_Declare(
fmt
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_PROGRESS TRUE
GIT_TAG master
)
if(HISS_PATH) #if hiss path is set, this will stop it downloading
get_filename_component(FETCHCONTENT_SOURCE_DIR_HISSTOOLS ${HISS_PATH} ABSOLUTE)
endif()
if(EIGEN_PATH) #if eigen path is set, this will stop it downloading
get_filename_component(FETCHCONTENT_SOURCE_DIR_EIGEN ${EIGEN_PATH} ABSOLUTE)
endif()
if(SPECTRA_PATH) #if spectra path is set, this will stop it downloading
get_filename_component(FETCHCONTENT_SOURCE_DIR_SPECTRA ${SPECTRA_PATH} ABSOLUTE)
endif()
if(JSON_PATH)
get_filename_component(FETCHCONTENT_SOURCE_DIR_JSON ${JSON_PATH} ABSOLUTE)
endif()
FetchContent_GetProperties(HISSTools)
if(NOT hisstools_POPULATED)
FetchContent_Populate(HISSTools)
endif()
FetchContent_GetProperties(Eigen)
if(NOT eigen_POPULATED)
FetchContent_Populate(Eigen)
endif()
FetchContent_GetProperties(Spectra)
if(NOT spectra_POPULATED)
FetchContent_Populate(Spectra)
endif()
set(OPTIONAL_BUILD_PACKAGE OFF CACHE BOOL "" FORCE)
set(OPTIONAL_BUILD_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_GetProperties(tl_optional)
if(NOT tl_optional_POPULATED)
FetchContent_Populate(tl_optional)
endif()
add_subdirectory(${tl_optional_SOURCE_DIR} ${tl_optional_BINARY_DIR} EXCLUDE_FROM_ALL)
FetchContent_GetProperties(json)
if(NOT json_POPULATED)
FetchContent_Populate(json)
endif()
add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
set(FOONATHAN_MEMORY_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(FOONATHAN_MEMORY_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(FOONATHAN_MEMORY_BUILD_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_GetProperties(Memory)
if(NOT memory_POPULATED)
FetchContent_Populate(Memory)
endif()
add_subdirectory(${memory_SOURCE_DIR} ${memory_BINARY_DIR} EXCLUDE_FROM_ALL)
FetchContent_GetProperties(fmt)
if(NOT fmt_POPULATED)
FetchContent_Populate(fmt)
endif()
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR} EXCLUDE_FROM_ALL)
# Brute force staic runtime on windwos
if(MSVC)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach()
endif()
#Fluid Decomposition header-only target
add_library(FLUID_DECOMPOSITION INTERFACE)
target_include_directories(
FLUID_DECOMPOSITION INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include"
)
target_include_directories(
FLUID_DECOMPOSITION SYSTEM INTERFACE #we don't want warnings from Eigen or HissTools
"${eigen_SOURCE_DIR}"
"${spectra_SOURCE_DIR}/include"
"${hisstools_SOURCE_DIR}/include"
"${memory_SOURCE_DIR}/include/foonathan"
"${fmt_SOURCE_DIR}/include"
)
target_link_libraries(
FLUID_DECOMPOSITION INTERFACE
flucoma_VERSION_LIB
tl::optional
nlohmann_json::nlohmann_json
foonathan_memory
fmt::fmt
)
target_sources(
FLUID_DECOMPOSITION INTERFACE ${HEADERS}
)
if(MSVC)
target_compile_definitions(
FLUID_DECOMPOSITION INTERFACE NOMINMAX _USE_MATH_DEFINES
)
endif()
#GCC vomits on using HostVector = HostVector<U> without this flag on
if(CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(FLUID_DECOMPOSITION INTERFACE -fpermissive)
endif()
target_compile_definitions(FLUID_DECOMPOSITION INTERFACE EIGEN_MPL2_ONLY=1)
if(APPLE)
#targeting <= 10.9, need to really emphasise that we want libc++ both to compiler and linker
target_compile_options(FLUID_DECOMPOSITION INTERFACE -stdlib=libc++)
target_link_libraries(FLUID_DECOMPOSITION INTERFACE -stdlib=libc++ ${ACCELERATE})
endif()
#Apply any vector instruction flags
if(DEFINED FLUID_ARCH)
target_compile_options(FLUID_DECOMPOSITION INTERFACE ${FLUID_ARCH})
endif()
#Examples
option(BUILD_EXAMPLES "Build C++ example code (off by default)" OFF)
if(BUILD_EXAMPLES)
add_subdirectory(
"${CMAKE_CURRENT_SOURCE_DIR}/examples"
)
endif()
enable_testing()
if(FLUCOMA_TESTS)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/tests")
endif()