-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
329 lines (296 loc) · 9.73 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# CMake definitions for airspy-fmradion
cmake_minimum_required(VERSION 3.18)
project(airspy-fmradion)
# Workaround for the compilation warning
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
# Enable compile_commands.json as default
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Use cmake-git-version-tracking
include(FetchContent)
FetchContent_Declare(
cmake_git_version_tracking
GIT_REPOSITORY
https://github.com/jj1bdx/cmake-git-version-tracking.git
GIT_TAG 6c0cb87edd029ddfb403a8e24577c144a03605a6)
FetchContent_MakeAvailable(cmake_git_version_tracking)
# EXPORT_COMPILE_COMMANDS is supported for CMake version 3.20 or later
# only
if(CMAKE_VERSION VERSION_LESS 3.20.0)
message(STATUS "No EXPORT_COMPILE_COMMANDS available")
message(STATUS "Use compdb for proper compile_commands.json handling")
else()
set_target_properties(cmake_git_version_tracking
PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
endif()
# Use pkg-config
include(FindPkgConfig)
# Find Threads package
find_package(Threads)
# Find Volk library.
pkg_check_modules(PKG_VOLK volk)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_library(
VOLK_LIBRARY libvolk.dylib HINTS /usr/local/lib /opt/homebrew/lib
${PKG_VOLK_LIBRARY_DIRS})
else()
find_library(VOLK_LIBRARY libvolk.so HINTS ${PKG_VOLK_LIBRARY_DIRS})
endif()
message(STATUS "volk ${PKG_VOLK_VERSION}: ${VOLK_LIBRARY}")
# Find Airspy library.
pkg_check_modules(PKG_AIRSPY libairspy)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_path(
AIRSPY_INCLUDE_DIR airspy.h
HINTS /usr/local/include/libairspy /opt/homebrew/include/libairspy
${PKG_AIRSPY_INCLUDE_DIRS})
find_library(
AIRSPY_LIBRARY libairspy.dylib
HINTS /usr/local/lib /opt/homebrew/lib ${PKG_AIRSPY_LIBRARY_DIRS})
set(AIRSPY_INCLUDE_OPTION
"-I/usr/local/include -I/opt/homebrew/include")
else()
find_path(AIRSPY_INCLUDE_DIR airspy.h
HINTS ${PKG_AIRSPY_INCLUDE_DIRS})
find_library(AIRSPY_LIBRARY libairspy.so
HINTS ${PKG_AIRSPY_LIBRARY_DIRS})
set(AIRSPY_INCLUDE_OPTION "")
endif()
message(
STATUS
"libairspy ${PKG_AIRSPY_VERSION}: ${AIRSPY_INCLUDE_DIR}, ${AIRSPY_LIBRARY}"
)
# Find Airspy HF library.
pkg_check_modules(PKG_AIRSPYHF libairspyhf)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_path(
AIRSPYHF_INCLUDE_DIR airspyhf.h
HINTS /usr/local/include/libairspyhf
/opt/homebrew/include/libairspyhf
${PKG_AIRSPYHF_INCLUDE_DIRS})
find_library(
AIRSPYHF_LIBRARY libairspyhf.dylib
HINTS /usr/local/lib /opt/homebrew/lib ${PKG_AIRSPYHF_LIBRARY_DIRS})
set(AIRSPYHF_INCLUDE_OPTION
"-I/usr/local/include -I/opt/homebrew/include")
else()
find_path(AIRSPYHF_INCLUDE_DIR airspyhf.h
HINTS ${PKG_AIRSPYHF_INCLUDE_DIRS})
find_library(AIRSPYHF_LIBRARY libairspyhf.so
HINTS ${PKG_AIRSPYHF_LIBRARY_DIRS})
set(AIRSPYHF_INCLUDE_OPTION "")
endif()
message(
STATUS
"libairspyhf ${PKG_AIRSPYHF_VERSION}: ${AIRSPYHF_INCLUDE_DIR}, ${AIRSPYHF_LIBRARY}"
)
# Find RTL-SDR library.
pkg_check_modules(PKG_RTLSDR librtlsdr)
find_path(RTLSDR_INCLUDE_DIR rtl-sdr.h HINTS ${PKG_RTLSDR_INCLUDE_DIRS})
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_library(RTLSDR_LIBRARY librtlsdr.dylib
HINTS ${PKG_RTLSDR_LIBRARY_DIRS})
else()
find_library(RTLSDR_LIBRARY librtlsdr.so
HINTS ${PKG_RTLSDR_LIBRARY_DIRS})
endif()
message(
STATUS
"librtlsdr ${PKG_RTLSDR_VERSION}: ${RTLSDR_INCLUDE_DIR}, ${RTLSDR_LIBRARY}"
)
# Find libusb
#
# See
# https://github.com/texane/stlink/blob/master/cmake/modules/FindLibUSB.cmake
pkg_check_modules(PKG_LIBUSB libusb-1.0)
find_path(
LIBUSB_INCLUDE_DIR libusb.h
HINTS /usr /usr/local /opt /opt/homebrew ${PKG_LIBUSB_INCLUDE_DIRS}
PATH_SUFFIXES libusb-1.0)
set(LIBUSB_NAME usb-1.0)
find_library(
LIBUSB_LIBRARY ${LIBUSB_NAME}
HINTS /usr /usr/local /opt /opt/homebrew ${PKG_LIBUSB_LIBRARY_DIRS})
message(
STATUS
"libusb ${PKG_LIBUSB_VERSION}: ${LIBUSB_INCLUDE_DIR}, ${LIBUSB_LIBRARY}"
)
# Find sndfile library
pkg_check_modules(PKG_SNDFILE sndfile)
find_path(SNDFILE_INCLUDE_DIR sndfile.h
HINTS ${PKG_SNDFILE_INCLUDE_DIRS})
find_library(SNDFILE_LIBRARY sndfile)
message(
STATUS
"sndfile ${PKG_SNDFILE_VERSION}: ${SNDFILE_LIBRARY}, ${SNDFILE_INCLUDE_DIR}"
)
# Determine MP3 support on sndfile
if(PKG_SNDFILE_VERSION VERSION_GREATER_EQUAL "1.1")
set(SNDFILE_INCLUDE_OPTION "-DLIBSNDFILE_MP3_ENABLED")
message(STATUS "sndfile MP3 support enabled")
endif()
# for PortAudio
pkg_check_modules(PORTAUDIO2 portaudio-2.0)
if(PORTAUDIO2_FOUND)
set(PORTAUDIO_INCLUDE_DIRS ${PORTAUDIO2_INCLUDE_DIRS})
set(PORTAUDIO_LIBRARY_DIRS ${PORTAUDIO2_LIBRARY_DIRS})
set(PORTAUDIO_LINK_LIBRARIES ${PORTAUDIO2_LINK_LIBRARIES})
set(PORTAUDIO_VERSION 19)
set(PORTAUDIO_FOUND TRUE)
find_path(PORTAUDIO_INCLUDE_DIR portaudio.h
HINTS /usr/local/include /opt/homebrew/include
${PORTAUDIO_INCLUDE_DIRS})
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_library(
PORTAUDIO_LIBRARY libportaudio.dylib
HINTS /usr/local/lib /opt/homebrew/lib ${PORTAUDIO_LIBRARY_DIRS})
else(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_library(
PORTAUDIO_LIBRARY libportaudio.so
HINTS /usr/local/lib /opt/homebrew/lib ${PORTAUDIO_LIBRARY_DIRS})
endif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
else(PORTAUDIO2_FOUND)
message(FATAL_ERROR "Could not find Portaudio")
endif(PORTAUDIO2_FOUND)
message(
STATUS
"libportaudio ${PORTAUDIO2_VERSION}: ${PORTAUDIO_INCLUDE_DIR}, ${PORTAUDIO_LIBRARY}"
)
message(STATUS "PortAudio libs: ${PORTAUDIO_LINK_LIBRARIES}")
set(RTLSDR_INCLUDE_DIRS ${RTLSDR_INCLUDE_DIR} ${LIBUSB_INCLUDE_DIR})
set(RTLSDR_LIBRARIES ${RTLSDR_LIBRARY} ${LIBUSB_LIBRARY})
set(AIRSPY_INCLUDE_DIRS ${AIRSPY_INCLUDE_DIR} ${LIBUSB_INCLUDE_DIR})
set(AIRSPY_LIBRARIES ${AIRSPY_LIBRARY} ${LIBUSB_LIBRARY})
set(AIRSPYHF_INCLUDE_DIRS ${AIRSPYHF_INCLUDE_DIR} ${LIBUSB_INCLUDE_DIR})
set(AIRSPYHF_LIBRARIES ${AIRSPYHF_LIBRARY} ${LIBUSB_LIBRARY})
# cmake-format: off
##
# Optimization flags and options.
#
# Enable speed-based optimization
# Do not apply -ffast-math; it enables -menable-no-nans
# which cancels detection functions of multipath filter abnormality!
#
set(OPTIMIZATION_FLAGS "-O3 -ftree-vectorize ")
##
# Use conservative options when failed to run
#
#set(OPTIMIZATION_FLAGS "-O2")
##
# For vectorization analysis (in Clang only)
#
#set(OPTIMIZATION_FLAGS "-O3 -ftree-vectorize -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize")
##
# For clang profiling with optimization
#
#set(OPTIMIZATION_FLAGS "-O3 -ftree-vectorize -g -fprofile-instr-generate -fcoverage-mapping")
#SET(CMAKE_EXE_LINKER_FLAGS "-fprofile-instr-generate")
##
# For Sanitizers
# with Thread Sanitizer
#
#set(OPTIMIZATION_FLAGS "-fsanitize=thread -O3 -ftree-vectorize ")
# with Address Sanitizer
#
#set(OPTIMIZATION_FLAGS "-fsanitize=address -O3 -ftree-vectorize ")
# For valgrind check
#
#set(OPTIMIZATION_FLAGS "-g")
#
##
# cmake-format: on
# Common compiler flags and options.
#
set(CMAKE_CXX_FLAGS
"-Wall -std=c++20 ${OPTIMIZATION_FLAGS} ${AIRSPY_INCLUDE_OPTION} ${AIRSPYHF_INCLUDE_OPTION} ${SNDFILE_INCLUDE_OPTION} ${EXTRA_FLAGS}"
)
# For building airspy-fmradion sources
set(sfmbase_SOURCES
sfmbase/AfSimpleAgc.cpp
sfmbase/AirspyHFSource.cpp
sfmbase/AirspySource.cpp
sfmbase/AmDecode.cpp
sfmbase/AudioResampler.cpp
sfmbase/AudioOutput.cpp
sfmbase/ConfigParser.cpp
sfmbase/FileSource.cpp
sfmbase/Filter.cpp
sfmbase/FilterParameters.cpp
sfmbase/FineTuner.cpp
sfmbase/FmDecode.cpp
sfmbase/IfResampler.cpp
sfmbase/IfSimpleAgc.cpp
sfmbase/MultipathFilter.cpp
sfmbase/NbfmDecode.cpp
sfmbase/PhaseDiscriminator.cpp
sfmbase/PilotPhaseLock.cpp
sfmbase/RtlSdrSource.cpp)
set(sfmbase_HEADERS
include/AfSimpleAgc.h
include/AirspyHFSource.h
include/AirspySource.h
include/AmDecode.h
include/AudioResampler.h
include/AudioOutput.h
include/ConfigParser.h
include/DataBuffer.h
include/FileSource.h
include/Filter.h
include/FilterParameters.h
include/FineTuner.h
include/FmDecode.h
include/FourthConverterIQ.h
include/git.h
include/IfResampler.h
include/IfSimpleAgc.h
include/MovingAverage.h
include/MultipathFilter.h
include/NbfmDecode.h
include/PhaseDiscriminator.h
include/PilotPhaseLock.h
include/RtlSdrSource.h
include/Source.h
include/SoftFM.h
include/Utility.h)
# cmake-format: off
# For building r8brain-free-src
# See https://github.com/baconpaul/SampleRateComparison for the details
# (Licensed GPLv3)
# Use R8B_PFFFT_DOUBLE for double-precision conversion
# cmake-format: on
add_library(r8b r8brain-free-src/r8bbase.cpp
r8brain-free-src/pffft_double/pffft_double.c)
target_include_directories(r8b PUBLIC r8brain-free-src)
target_compile_definitions(r8b PUBLIC R8B_EXTFFT=1 R8B_FASTTIMING=1
R8B_PFFFT_DOUBLE=1)
# Base sources
set(sfmbase_SOURCES ${sfmbase_SOURCES} ${sfmbase_HEADERS})
# Libraries
add_library(sfmbase STATIC ${sfmbase_SOURCES})
# Executable
add_executable(airspy-fmradion main.cpp)
include_directories(
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/r8brain-free-src
${AIRSPYHF_INCLUDE_DIRS}
${AIRSPY_INCLUDE_DIRS}
${RTLSDR_INCLUDE_DIRS}
${PORTAUDIO_INCLUDE_DIR}
${EXTRA_INCLUDES})
target_link_libraries(
airspy-fmradion
sfmbase
r8b
${CMAKE_THREAD_LIBS_INIT}
${PORTAUDIO_LINK_LIBRARIES}
${VOLK_LIBRARY}
${EXTRA_LIBS}
cmake_git_version_tracking)
target_link_libraries(
sfmbase ${SNDFILE_LIBRARY} ${AIRSPY_LIBRARY} ${AIRSPYHF_LIBRARY}
${RTLSDR_LIBRARY} ${LIBUSB_LIBRARY})
# Installation
install(TARGETS airspy-fmradion DESTINATION bin)
install(TARGETS sfmbase DESTINATION lib)
# End of CMakeLists.txt