-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
167 lines (145 loc) · 7.08 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
# Copyright (c) 2020 - Fielding DSP GmbH
cmake_minimum_required(VERSION 3.1)
project(FastFourier)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS_RELEASE -Ofast)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# When building the public API, don't include any symbols from static libraries that we depend on
if ((ANDROID) OR (CMAKE_SYSTEM_NAME MATCHES Linux))
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--exclude-libs,ALL ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
# Set a default build type if none was specified
set(default_build_type "Release")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(default_build_type "Debug")
endif()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_definitions("-DDEBUG=1" "-D_DEBUG=1")
if ((NOT ANDROID) AND (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")))
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address,undefined")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address,undefined")
set(SANITIZERS_ENABLED 1)
else()
set(SANITIZERS_ENABLED 0)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG}")
endif()
elseif(CMAKE_BUILD_TYPE MATCHES "Release")
set(SANITIZERS_ENABLED 0)
add_definitions("-DNDEBUG=1")
else()
message(FATAL_ERROR "Unknown build configuration \"${CMAKE_BUILD_TYPE}\": must be Debug or Release")
endif()
#increase warning level
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-missing-field-initializers -Wshadow-all -Wshorten-64-to-32 -Wstrict-aliasing -Wuninitialized -Wunused-parameter -Wsign-compare -Wint-conversion -Wconditional-uninitialized -Wreorder -Wconstant-conversion -Wunused-private-field -Wbool-conversion -Wextra-semi -Wno-ignored-qualifiers -Wunreachable-code")
# clang on Linux/android has a bug where it can't link with -Wl,--no-undefined when sanitizers are enabled :-(
if ((NOT SANITIZERS_ENABLED) OR (NOT (CMAKE_SYSTEM_NAME MATCHES Linux)))
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--no-undefined")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-missing-field-initializers -Wshadow -Wstrict-aliasing -Wuninitialized -Wunused-parameter -Wsign-compare -Wreorder -Wno-ignored-qualifiers -Wunreachable-code")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--no-undefined")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
########################################################
##### Set Library paths and find common libraries ######
########################################################
if(APPLE)
find_library(ACCELERATE_LIBRARY Accelerate)
endif()
if(ANDROID)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
if(ANDROID_ABI MATCHES "^arm.*$")
find_library(ne10 NAMES NE10 PATHS "ne10/${ANDROID_ABI}")
else()
set(INTEL_IPP_LIB_PATH "intel_ipp/android/${ANDROID_ABI}")
find_library(intel_ipps NAMES ipps PATHS ${INTEL_IPP_LIB_PATH})
find_library(intel_ippvm NAMES ippvm PATHS ${INTEL_IPP_LIB_PATH})
find_library(intel_ippcore NAMES ippcore PATHS ${INTEL_IPP_LIB_PATH})
endif()
endif()
if(CMAKE_SYSTEM_NAME MATCHES Windows)
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
set(INTEL_IPP_LIB_PATH "intel_ipp/windows/x86_64")
else()
set(INTEL_IPP_LIB_PATH "intel_ipp/windows/x86")
endif()
find_library(intel_ipps NAMES ippsmt PATHS ${INTEL_IPP_LIB_PATH})
find_library(intel_ippvm NAMES ippvmmt PATHS ${INTEL_IPP_LIB_PATH})
find_library(intel_ippcore NAMES ippcoremt PATHS ${INTEL_IPP_LIB_PATH})
endif()
if(CMAKE_SYSTEM_NAME MATCHES Linux)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86" OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
set(INTEL_IPP_LIB_PATH "intel_ipp/linux/x86_64")
else()
set(INTEL_IPP_LIB_PATH "intel_ipp/linux/x86")
endif()
find_library(intel_ipps NAMES ipps PATHS ${INTEL_IPP_LIB_PATH})
find_library(intel_ippvm NAMES ippvm PATHS ${INTEL_IPP_LIB_PATH})
find_library(intel_ippcore NAMES ippcore PATHS ${INTEL_IPP_LIB_PATH})
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm.*$" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
find_library(ne10 NAMES NE10 PATHS "ne10/${ANDROID_ABI}")
else()
message(FATAL_ERROR "Unknown processor \"${CMAKE_SYSTEM_PROCESSOR}\"")
endif()
endif()
if(CMAKE_SYSTEM_NAME MATCHES Linux)
set(FFT_ENGINE_LIBRARY ${intel_ipps} ${intel_ippvm} ${intel_ippcore})
elseif(APPLE)
# iOS and macOS will use the system's Accelerate framework which is linked in anyway
endif()
########################################################
############# Select the right FFT engine ##############
########################################################
if(ANDROID)
if(ANDROID_ABI MATCHES "^arm.*$")
set(FFT_ENGINE_LIBRARY ${ne10})
else()
set(FFT_ENGINE_LIBRARY ${intel_ipps} ${intel_ippvm} ${intel_ippcore})
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES Windows)
set(FFT_ENGINE_LIBRARY ${intel_ipps} ${intel_ippvm} ${intel_ippcore})
elseif(CMAKE_SYSTEM_NAME MATCHES Linux)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86" OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
set(FFT_ENGINE_LIBRARY ${intel_ipps} ${intel_ippvm} ${intel_ippcore})
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm.*$" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(FFT_ENGINE_LIBRARY ${ne10})
else()
message(FATAL_ERROR "Unknown processor \"${CMAKE_SYSTEM_PROCESSOR}\"")
endif()
elseif(APPLE)
# iOS and macOS will use the system's Accelerate framework which is linked in anyway
endif()
########################################################
################### The main target ####################
########################################################
add_library(FastFourier SHARED FastFourier.cpp FastFourier.h)
target_link_libraries(FastFourier ${FFT_ENGINE_LIBRARY} ${ACCELERATE_LIBRARY} Threads::Threads)
# on macOS/iOS we build a framework
if(APPLE)
set_target_properties(FastFourier PROPERTIES FRAMEWORK TRUE)
set_target_properties(FastFourier PROPERTIES FRAMEWORK_VERSION A)
set_target_properties(FastFourier PROPERTIES MACOSX_FRAMEWORK_IDENTIFIER com.fieldingdsp.lib.FastFourier)
if(IOS)
set_target_properties(FastFourier PROPERTIES MACOSX_FRAMEWORK_INFO_PLIST ${CMAKE_SOURCE_DIR}/iOS.plist)
else()
set_target_properties(FastFourier PROPERTIES MACOSX_FRAMEWORK_INFO_PLIST ${CMAKE_SOURCE_DIR}/macOS.plist)
endif()
set_target_properties(FastFourier PROPERTIES PUBLIC_HEADER FastFourier.h)
endif()
if(CMAKE_SYSTEM_NAME MATCHES Linux)
install(TARGETS FastFourier DESTINATION lib)
install(FILES FastFourier.h DESTINATION include)
endif()