forked from theori-io/nrsc5
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
321 lines (284 loc) · 11.5 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
cmake_minimum_required (VERSION 2.8)
include (CheckLibraryExists)
include (CheckSymbolExists)
include (ExternalProject)
include (FindPkgConfig)
project (nrsc5 C)
execute_process (COMMAND ${CMAKE_C_COMPILER} -dumpmachine OUTPUT_VARIABLE HOST_TRIPLE_DEFAULT OUTPUT_STRIP_TRAILING_WHITESPACE)
option (USE_NEON "Use NEON instructions")
option (USE_SSE "Use SSE3 instructions")
option (USE_FAAD2 "AAC decoding with FAAD2" ON)
option (USE_STATIC "Link with static libraries")
option (USE_SYSTEM_FFTW "Use system provided fftw" ON)
set (SDR_DRIVER "sdrplay" CACHE STRING "Selected SDR driver (one of: rtlsdr, sdrplay, soapy)")
option (USE_SYSTEM_RTLSDR "Use system provided rtl-sdr" ON)
option (USE_SYSTEM_LIBUSB "Use system provided libusb" ON)
option (USE_SYSTEM_LIBAO "Use system provided libao" ON)
set (FAAD2_CONFIGURE_ARGS "" CACHE STRING "Extra arguments for FAAD2 configure command")
set (LIBRARY_DEBUG_LEVEL "5" CACHE STRING "Debug logging level for libnrsc5: 1=debug, 2=info, 3=warn, 4=error, 5=none")
set (HOST_TRIPLE "${HOST_TRIPLE_DEFAULT}" CACHE STRING "Override default host triple")
if (HOST_TRIPLE)
set (HOST_TRIPLE_ARG "--host=${HOST_TRIPLE}")
endif()
message (STATUS "Building for ${HOST_TRIPLE}")
find_program (AUTOCONF autoconf)
if (NOT AUTOCONF)
message (FATAL_ERROR "Missing autoconf. Install autoconf package and try again.")
endif ()
find_program (AUTOMAKE automake)
if (NOT AUTOMAKE)
message (FATAL_ERROR "Missing automake. Install autoconf package and try again.")
endif ()
find_program (LIBTOOLIZE NAMES libtoolize glibtoolize)
if (NOT LIBTOOLIZE)
message (FATAL_ERROR "Missing libtoolize. Install libtool package and try again.")
endif ()
find_program (PATCH patch)
if (NOT PATCH)
message (FATAL_ERROR "Missing patch. Install patch package and try again.")
endif()
if (USE_SYSTEM_FFTW)
find_library (FFTW3F_LIBRARIES fftw3f)
pkg_search_module (FFTW3F fftw3f)
if (NOT FFTW3F_LIBRARIES)
message (WARNING "libfftw3f not found. Building from source.")
set (USE_SYSTEM_FFTW OFF)
endif ()
endif ()
if (SDR_DRIVER STREQUAL rtlsdr AND USE_SYSTEM_RTLSDR)
find_library (SDR_DRIVER_LIBRARIES rtlsdr)
pkg_search_module (SDR_DRIVER librtlsdr)
if (NOT SDR_DRIVER_LIBRARIES)
message (WARNING "librtlsdr not found. Building from source.")
set (USE_SYSTEM_RTLSDR OFF)
endif ()
endif ()
if (SDR_DRIVER STREQUAL rtlsdr AND USE_SYSTEM_LIBUSB)
find_library (LIBUSB_LIBRARIES usb-1.0)
pkg_search_module (LIBUSB libusb-1.0)
if (NOT LIBUSB_LIBRARIES)
message (WARNING "libusb-1.0 not found. Building from source.")
set (USE_SYSTEM_LIBUSB OFF)
endif ()
endif ()
if (SDR_DRIVER STREQUAL sdrplay)
if (UNIX)
find_library (SDR_DRIVER_LIBRARIES libsdrplay_api.so.3)
get_filename_component (SDR_DRIVER_LIBRARY_DIRS "${SDR_DRIVER_LIBRARIES}" DIRECTORY)
find_path (SDR_DRIVER_INCLUDE_DIRS sdrplay_api.h)
if (NOT SDR_DRIVER_LIBRARIES)
message (FATAL_ERROR "libsdrplay_api v3 not found.")
endif ()
elseif (WIN32)
if (DEFINED ENV{SDRPLAY_API_BASE_DIR})
# cross-compile: get SDRPLAY_API_BASE_DIR from the env variables
set (SDRPLAY_API_DIR "$ENV{SDRPLAY_API_BASE_DIR}/app/API")
# link against the .dll (*not* the .lib)
# see this bug in x86_64-w64-mingw32-gcc version 9.3:
# https://stackoverflow.com/questions/64082149/different-mingw-w64-version-breaks-dll-loading
set (SDRPLAY_API_LIBRARY_SUFFIX dll)
list (APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".${SDRPLAY_API_LIBRARY_SUFFIX}")
else()
# Native Windows build
get_filename_component (SDRPLAY_API_DIR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SDRplay\\Service\\API;Install_Dir]" ABSOLUTE)
set (SDRPLAY_API_LIBRARY_SUFFIX lib)
endif()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message (STATUS "64 bit compiler detected")
set (EX_PLATFORM_NAME "x64")
else ()
message (STATUS "32 bit compiler detected")
set (EX_PLATFORM_NAME "x86")
endif ()
find_path(SDR_DRIVER_INCLUDE_DIRS NAMES sdrplay_api.h
PATHS
"${SDRPLAY_API_DIR}/inc"
)
if (NOT SDR_DRIVER_INCLUDE_DIRS)
message (FATAL_ERROR "sdrplay_api.h not found.")
endif ()
find_library(SDR_DRIVER_LIBRARIES NAMES sdrplay_api.${SDRPLAY_API_LIBRARY_SUFFIX}
PATHS
"${SDRPLAY_API_DIR}/${EX_PLATFORM_NAME}"
)
if (NOT SDR_DRIVER_LIBRARIES)
message (FATAL_ERROR "sdrplay_api.${SDRPLAY_API_LIBRARY_SUFFIX} not found.")
endif ()
endif ()
endif ()
if (SDR_DRIVER STREQUAL soapy)
find_library (SDR_DRIVER_LIBRARIES SoapySDR)
pkg_search_module (SDR_DRIVER SoapySDR)
set (SDR_DRIVER_LIBRARY_DIRS "${SDR_DRIVER_LIBDIR}")
set (SDR_DRIVER_INCLUDE_DIRS "${SDR_DRIVER_INCLUDEDIR}")
if (NOT SDR_DRIVER_LIBRARIES)
message (FATAL_ERROR "SoapySDR not found.")
endif ()
endif ()
if (USE_SYSTEM_LIBAO)
find_library (AO_LIBRARIES ao)
pkg_search_module(AO ao)
if (NOT AO_LIBRARIES)
message (WARNING "libao not found. Building from source.")
set (USE_SYSTEM_LIBAO OFF)
endif ()
endif ()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*")
if (USE_NEON)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4")
add_definitions (-DHAVE_NEON)
endif()
endif()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(i[456]|x)86.*")
if (USE_SSE)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -msse3 -mssse3")
add_definitions (-DHAVE_SSE2 -DHAVE_SSE3)
endif()
endif()
set (CMAKE_REQUIRED_FLAGS --std=gnu11)
check_symbol_exists (strndup string.h HAVE_STRNDUP)
check_symbol_exists (CMPLXF complex.h HAVE_CMPLXF)
check_symbol_exists (_Imaginary_I complex.h HAVE_IMAGINARY_I)
check_symbol_exists (_Complex_I complex.h HAVE_COMPLEX_I)
if (NOT USE_SYSTEM_FFTW)
set (FFTW_PREFIX "${CMAKE_BINARY_DIR}/fftw-prefix")
ExternalProject_Add (
fftw_external
URL "http://www.fftw.org/fftw-3.3.8.tar.gz"
URL_HASH SHA256=6113262f6e92c5bd474f2875fa1b01054c4ad5040f6b0da7c03c98821d9ae303
PREFIX ${FFTW_PREFIX}
CONFIGURE_COMMAND ${FFTW_PREFIX}/src/fftw_external/configure ${HOST_TRIPLE_ARG} --prefix=${FFTW_PREFIX} --enable-float --enable-static --disable-shared --enable-sse2 --enable-avx --enable-avx2 --with-our-malloc
)
add_library (fftw3f STATIC IMPORTED)
set_property (TARGET fftw3f PROPERTY IMPORTED_LOCATION "${FFTW_PREFIX}/lib/libfftw3f.a")
add_dependencies (fftw3f fftw_external)
set (FFTW3F_INCLUDE_DIRS "${FFTW_PREFIX}/include")
set (FFTW3F_LIBRARIES fftw3f)
set (FFTW3F_BUILTIN fftw3f)
endif ()
if (SDR_DRIVER STREQUAL rtlsdr AND NOT USE_SYSTEM_LIBUSB)
set (LIBUSB_PREFIX "${CMAKE_BINARY_DIR}/libusb-prefix")
ExternalProject_Add (
libusb_external
TIMEOUT 120
GIT_REPOSITORY "https://github.com/libusb/libusb.git"
GIT_TAG v1.0.22
PREFIX ${LIBUSB_PREFIX}
UPDATE_COMMAND ""
CONFIGURE_COMMAND ${LIBUSB_PREFIX}/src/libusb_external/configure ${HOST_TRIPLE_ARG} --prefix=${LIBUSB_PREFIX}
)
ExternalProject_Add_Step (
libusb_external
bootstrap
COMMAND sh ./bootstrap.sh
DEPENDEES patch
DEPENDERS configure
WORKING_DIRECTORY <SOURCE_DIR>
)
add_library (libusb STATIC IMPORTED)
set_property (TARGET libusb PROPERTY IMPORTED_LOCATION "${LIBUSB_PREFIX}/lib/libusb-1.0.a")
set (LIBUSB_BUILTIN libusb_external)
set (LIBUSB_LIBRARIES libusb)
set (RTLSDR_CMAKE_ARGS
-DLIBUSB_INCLUDE_DIR:STRING=${LIBUSB_PREFIX}/include/libusb-1.0
-DLIBUSB_LIBRARIES:STRING=${LIBUSB_PREFIX}/lib/libusb-1.0.a
)
endif ()
if (SDR_DRIVER STREQUAL rtlsdr AND NOT USE_SYSTEM_RTLSDR)
set (RTLSDR_PREFIX "${CMAKE_BINARY_DIR}/rtlsdr-prefix")
ExternalProject_Add (
rtlsdr_external
TIMEOUT 120
GIT_REPOSITORY "https://github.com/osmocom/rtl-sdr.git"
GIT_TAG f68bb2fa772ad94f58c59babd78353667570630b
PREFIX ${RTLSDR_PREFIX}
UPDATE_COMMAND ""
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:STRING=${RTLSDR_PREFIX}
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DCMAKE_SYSTEM_NAME:STRING=${CMAKE_SYSTEM_NAME}
${RTLSDR_CMAKE_ARGS}
)
if (LIBUSB_BUILTIN)
add_dependencies (rtlsdr_external ${LIBUSB_BUILTIN})
endif ()
add_library (rtlsdr STATIC IMPORTED)
set_property (TARGET rtlsdr PROPERTY IMPORTED_LOCATION "${RTLSDR_PREFIX}/lib/librtlsdr_static.a")
add_dependencies (rtlsdr rtlsdr_external)
set (SDR_DRIVER_INCLUDE_DIRS "${RTLSDR_PREFIX}/include")
set (SDR_DRIVER_LIBRARIES rtlsdr ${LIBUSB_LIBRARIES})
set (SDR_DRIVER_BUILTIN rtlsdr)
endif ()
if (NOT USE_SYSTEM_LIBAO)
if (NOT WIN32)
message (FATAL_ERROR "Built-in libao only supported on Windows.")
endif ()
set (LIBAO_PREFIX "${CMAKE_BINARY_DIR}/libao-prefix")
ExternalProject_Add (
libao_external
TIMEOUT 120
GIT_REPOSITORY "https://gitlab.xiph.org/xiph/libao.git"
GIT_TAG cafce902a73c1050474a62feff83e428bbbee5f4
PREFIX ${LIBAO_PREFIX}
UPDATE_COMMAND ""
CONFIGURE_COMMAND ${LIBAO_PREFIX}/src/libao_external/configure ${HOST_TRIPLE_ARG} --prefix=${LIBAO_PREFIX} --enable-static --disable-shared --disable-pulse
)
ExternalProject_Add_Step (
libao_external
bootstrap
COMMAND sh ./autogen.sh
DEPENDEES patch
DEPENDERS configure
WORKING_DIRECTORY <SOURCE_DIR>
)
add_library (libao STATIC IMPORTED)
set_property (TARGET libao PROPERTY IMPORTED_LOCATION "${LIBAO_PREFIX}/lib/libao.a")
add_dependencies (libao libao_external)
set (AO_INCLUDE_DIRS "${LIBAO_PREFIX}/include")
set (AO_LIBRARIES libao ksuser winmm)
set (AO_BUILTIN libao)
endif ()
if (USE_FAAD2)
set (FAAD2_PREFIX "${CMAKE_BINARY_DIR}/faad2-prefix")
ExternalProject_Add (
faad2_external
TIMEOUT 120
GIT_REPOSITORY "https://github.com/knik0/faad2.git"
GIT_TAG f71b5e81f563d94fa284977a326520d269d8353e
PREFIX ${FAAD2_PREFIX}
UPDATE_COMMAND ""
PATCH_COMMAND patch -p1 -Ni "${CMAKE_SOURCE_DIR}/support/faad2-hdc-support.patch" || exit 0
COMMAND sh ./bootstrap
CONFIGURE_COMMAND ${FAAD2_PREFIX}/src/faad2_external/configure ${HOST_TRIPLE_ARG} ${FAAD2_CONFIGURE_ARGS} --prefix=${FAAD2_PREFIX} "CFLAGS=-O2 -fPIC ${CMAKE_C_FLAGS}"
)
add_library (faad2 STATIC IMPORTED)
set_property (TARGET faad2 PROPERTY IMPORTED_LOCATION "${FAAD2_PREFIX}/lib/libfaad_hdc.a")
add_dependencies (faad2 faad2_external)
set (FAAD2_INCLUDE_DIRS "${FAAD2_PREFIX}/include")
set (FAAD2_LIBRARIES faad2)
add_definitions (-DHAVE_FAAD2)
set (FAAD2_BUILTIN faad2)
else ()
# we only use libao with faad2
unset (AO_INCLUDE_DIRS)
unset (AO_LIBRARIES)
unset (AO_BUILTIN)
endif()
set (BUILTIN_LIBRARIES ${FFTW3F_BUILTIN} ${SDR_DRIVER_BUILTIN} ${FAAD2_BUILTIN} ${AO_BUILTIN})
string(TOUPPER "${SDR_DRIVER}" SDR_DRIVER_UPPERCASE)
add_definitions("-DUSE_${SDR_DRIVER_UPPERCASE}")
if (SDR_DRIVER STREQUAL rtlsdr)
set (SDR_DRIVER_EXTRA_SOURCES rtltcp.c)
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(GIT_COMMIT_HASH "unknown")
endif()
add_definitions("-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"")
add_subdirectory (src)