forked from surge-synthesizer/surge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
199 lines (173 loc) · 6.99 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
# vi:set sw=2 et:
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11 CACHE STRING "Minimum macOS version")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
if(NOT BUILD_TESTING)
option(BUILD_TESTING "" OFF)
endif()
project(Surge VERSION 1.1.0 LANGUAGES C CXX ASM)
# Banner {{{
message(STATUS "It's Surge XT, folks! Version is ${PROJECT_VERSION}")
message(STATUS "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}")
message(STATUS "CMake version is ${CMAKE_VERSION}")
message(STATUS "Compiler version is ${CMAKE_CXX_COMPILER_VERSION}")
math(EXPR SURGE_BITNESS "${CMAKE_SIZEOF_VOID_P} * 8" OUTPUT_FORMAT DECIMAL)
message(STATUS "Targeting ${SURGE_BITNESS}-bit configuration")
# }}}
# Make Sure the REpo is properly cloned {{{
set(SURGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if (NOT EXISTS "${SURGE_SOURCE_DIR}/libs/tuning-library/README.md")
message(FATAL_ERROR "Cannot find the contents of the tuning-library submodule, but this usually means"
" that you haven't done a git submodule update; and so your repo will not build properly. "
"To resolve this, please run `git submodule update --init --recursive` and re-run cmake")
endif()
# }}}
# Global compiler/linker settings {{{
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND UNIX AND NOT APPLE AND NOT SURGE_SKIP_PIE_CHANGE)
message(STATUS "Setting -no-pie on EXE flags; use SURGE_SKIP_PIE_CHANGE=TRUE to avoid" )
set(CMAKE_EXE_LINKER_FLAGS "-no-pie")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
if (${SURGE_SANITIZE})
message(STATUS "Sanitizer is On" )
endif()
# Any Clang or any GCC
add_compile_options(
-Wno-multichar
# Targeting Windows with GCC/Clang is experimental
$<$<NOT:$<BOOL:${WIN32}>>:-Werror>
# PE/COFF doesn't support visibility
$<$<NOT:$<BOOL:${WIN32}>>:-fvisibility=hidden>
# Inlines visibility is only relevant with C++
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<COMPILE_LANGUAGE:CXX>>:-fvisibility-inlines-hidden>
# BP note: If you want to turn on llvm/gcc sanitize undo this and the link options below
$<$<BOOL:${SURGE_SANITIZE}>:-fsanitize=address>
$<$<BOOL:${SURGE_SANITIZE}>:-fsanitize=undefined>
)
add_link_options(
$<$<BOOL:${SURGE_SANITIZE}>:-fsanitize=address>
$<$<BOOL:${SURGE_SANITIZE}>:-fsanitize=undefined>
)
# Enable SSE2 on x86-32 only. It's implied on x86-64 and N/A elsewhere.
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("#ifndef __i386__
#error
#endif
int main() {}" SURGE_ARCH_I386)
if(SURGE_ARCH_I386)
add_compile_options(-msse2 -mfpmath=sse)
endif()
endif()
# Add AVX support
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#if defined(__x86_64__) || defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
#ifndef __AVX__
#error
#endif
#endif
int main() {}" COMPILER_HAS_AVX_OR_IS_ARM)
if(NOT COMPILER_HAS_AVX_OR_IS_ARM)
message(STATUS "Holding off on AVX support. See #4479 for the strategy")
# add_compile_options("-mavx")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Any Clang
add_compile_options(
-Wno-unused-command-line-argument
-Wno-deprecated-declarations
-Werror=inconsistent-missing-override
-Werror=logical-op-parentheses
-Werror=dynamic-class-memaccess
-Werror=undefined-bool-conversion
-Werror=bitwise-op-parentheses
-Werror=pointer-bool-conversion
)
if(CMAKE_CXX_COMPILER_ID MATCHES "^AppleClang$")
# Apple Clang only
add_compile_options(
-faligned-allocation
-fasm-blocks
)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^GNU$")
# GCC only
add_compile_options(
-Wformat-truncation=0 # squelch warning about snprintf truncating strings (see PR #3977)
-Wno-free-nonheap-object # https://github.com/surge-synthesizer/surge/issues/4251
-Wno-return-local-addr # squelch sqlite3 error: function may return address of local variable
)
endif()
endif()
if(MSVC)
add_compile_options(
-WX # treat all warnings as errors
# MSVC-only warnings, Clang-cl silently ignores these
/wd4244 # float to double
/wd4305 # truncation of variable
/wd4267 # int and size_t
/wd4018 # signed unsigned mismatch
/wd4388 # signed unsigned mismatch in comparison
/wd4065 # standalone default in a switch with no case
/wd4702 # unreachable code. I generally do if( a ) return foo else return bar; return nullptr so don't warn on that
# Clang-cl-only warnings
$<$<CXX_COMPILER_ID:Clang>:-Wno-microsoft-exception-spec>
$<$<CXX_COMPILER_ID:Clang>:-Wno-pragma-pack>
/Zc:alignedNew
/bigobj
# /arch:AVX
# Build with Multiple Processes (Clang-cl builds use Ninja instead)
$<$<CXX_COMPILER_ID:MSVC>:/MP>
# Set source and executable charsets to UTF-8
$<$<CXX_COMPILER_ID:MSVC>:/utf-8>
)
endif()
# }}}
# Source Groups {{{
source_group("Libraries" REGULAR_EXPRESSION "libs/")
source_group("AirWindows" REGULAR_EXPRESSION "libs/airwindows/")
source_group("Surge Core" REGULAR_EXPRESSION "src/common/.*\.cpp")
source_group("Surge DSP" REGULAR_EXPRESSION "src/common/dsp/")
source_group("Surge FX" REGULAR_EXPRESSION "src/common/dsp/effects/")
source_group("Surge GUI" REGULAR_EXPRESSION "src/surge-xt/gui/")
source_group("Generated Code" REGULAR_EXPRESSION "version.cpp")
source_group("Headless" REGULAR_EXPRESSION "src/surge-testrunner/")
source_group("Surge XT Juce" REGULAR_EXPRESSION "src/surge-xt/")
source_group("Surge FX Juce" REGULAR_EXPRESSION "src/surge-fx/")
# }}}
add_subdirectory(resources)
add_subdirectory(src)
# CI Pipeline {{{
include(cmake/stage-extra-content.cmake)
# We have a special target here which the PR pipeline uses to make sure things
# are of the appropriate code quality. This allows us to write CMAKE rules which
# become linters and stuff. The code will run on macos in the pipeline. I suppose
# you could run it locally to, but really, you should know what you are doing if you
# do that. And I'll document it so you can know that when I use it earnest in 1.9
add_custom_target(code-quality-pipeline-checks)
# Check 1: The extra content is properly specified.
add_dependencies(code-quality-pipeline-checks download-extra-content)
# Clang Format checks
set(CLANG_FORMAT_DIRS src)
set(CLANG_FORMAT_EXTS cpp h)
foreach(dir ${CLANG_FORMAT_DIRS})
foreach(ext ${CLANG_FORMAT_EXTS})
list(APPEND CLANG_FORMAT_GLOBS "':(glob)${dir}/**/*.${ext}'")
endforeach()
endforeach()
add_custom_command(TARGET code-quality-pipeline-checks
POST_BUILD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E echo About to check clang-format
COMMAND git ls-files -- ${CLANG_FORMAT_GLOBS} | xargs clang-format --dry-run --Werror
)
# }}}