forked from jvde-github/AIS-catcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
379 lines (289 loc) · 11.9 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# CMake definitions for AIS-catcher
cmake_minimum_required(VERSION 3.0)
project(AIS-catcher)
# Common compiler flags and options.
option(MSVC_VCPKG "For MSVC use VCPKG libraries." OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(OPTIMIZATION_FLAGS "-Ofast")
add_compile_options("-Wno-psabi")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "CLANG")
set(OPTIMIZATION_FLAGS "-Ofast")
elseif(MSVC)
set(OPTIMIZATION_FLAGS "-DWIN32_LEAN_AND_MEAN /EHsc /Oi /Ot /fp:fast")
endif()
set(CMAKE_CXX_FLAGS "${OPTIMIZATION_FLAGS}")
# Use pkg-config
include(FindPkgConfig)
find_package(Threads)
# for MSVC we link to the PothosSDR install
if(MSVC AND NOT MSVC_VCPKG)
SET(POTHOSSDR_BINARY_DIR $ENV{PROGRAMFILES}\\PothosSDR\\bin)
SET(POTHOSSDR_LIBRARY_DIR $ENV{PROGRAMFILES}\\PothosSDR\\lib)
SET(POTHOSSDR_INCLUDE_DIR $ENV{PROGRAMFILES}\\PothosSDR\\include)
endif()
# Define the libraries for inclusion
if(MSVC)
set(ADDITIONAL_LIBRARIES ws2_32.lib)
endif()
# Find libusb, pthread
if(NOT MSVC)
pkg_check_modules(PKG_LIBUSB libusb-1.0)
find_path(LIBUSB_INCLUDE_DIR libusb.h HINT ${PKG_LIBUSB_INCLUDE_DIRS} PATH_SUFFIXES libusb-1.0)
find_library(LIBUSB_LIBRARY usb-1.0 HINT ${PKG_LIBUSB_LIBRARY_DIRS})
elseif(NOT MSVC_VCPKG)
find_file(LIBUSB_DLL libusb-1.0.dll HINTS ${POTHOSSDR_BINARY_DIR})
find_file(PTHREAD_DLL pthreadVC2.dll HINTS ${POTHOSSDR_BINARY_DIR})
else()
set(LIBUSB_INCLUDE_DIR "")
set(LIBUSB_LIBRARY "")
endif()
# Find RTL-SDR library.
if(NOT MSVC)
pkg_check_modules(PKG_RTLSDR librtlsdr)
find_path(RTLSDR_INCLUDE_DIR rtl-sdr.h HINT ${PKG_RTLSDR_INCLUDE_DIRS})
find_library(RTLSDR_LIBRARY rtlsdr HINT ${PKG_RTLSDR_LIBRARY_DIRS})
if(RTLSDR_INCLUDE_DIR AND RTLSDR_LIBRARY)
message(STATUS "RTLSDR: found - ${RTLSDR_INCLUDE_DIR}, ${RTLSDR_LIBRARY}")
add_definitions(-DHASRTLSDR)
set(RTLSDR_INCLUDE_DIRS ${RTLSDR_INCLUDE_DIR} ${LIBUSB_INCLUDE_DIR})
set(RTLSDR_LIBRARIES ${RTLSDR_LIBRARY} ${LIBUSB_LIBRARY})
if(PKG_RTLSDR_VERSION LESS "0.5.4")
Message(STATUS "RTLSDR: no support for biastee")
add_definitions(-DLIBRTLSDR_LEGACY)
endif()
else()
Message(STATUS "RTLSDR: not found.")
endif()
elseif(MSVC_VCPKG)
find_package(rtlsdr)
if(rtlsdr_FOUND)
add_definitions(-DHASRTLSDR)
set(RTLSDR_LIBRARIES rtlsdr::rtlsdr)
Message(STATUS "RTLSDR: found (VCPKG) - " ${RTLSDR_LIBRARIES})
else()
Message(STATUS "RTLSDR: not found (VCPKG).")
endif()
else()
find_path(RTLSDR_INCLUDE_DIR rtl-sdr.h HINTS ${POTHOSSDR_INCLUDE_DIR})
find_library(RTLSDR_LIBRARY rtlsdr.lib HINTS ${POTHOSSDR_LIBRARY_DIR})
find_file(RTLSDR_DLL rtlsdr.dll HINTS ${POTHOSSDR_BINARY_DIR})
if(RTLSDR_INCLUDE_DIR AND RTLSDR_LIBRARY AND RTLSDR_DLL)
Message(STATUS "RTLSDR: found (PothosSDR) - " ${RTLSDR_INCLUDE_DIR}, ${RTLSDR_LIBRARY}, ${RTLSDR_DLL})
set(COPY_RTLSDR_DLL TRUE)
set(COPY_PTHREAD_LIBUSB_DLL TRUE)
add_definitions(-DHASRTLSDR)
set(RTLSDR_INCLUDE_DIRS ${RTLSDR_INCLUDE_DIR})
set(RTLSDR_LIBRARIES ${RTLSDR_LIBRARY})
else()
Message(STATUS "RTLSDR: not found (PothosSDR).")
endif()
endif()
# Find SDRplay library.
if(NOT MSVC)
find_path(SDRPLAY_INCLUDE_DIR sdrplay_api.h)
find_library(SDRPLAY_LIBRARY sdrplay_api)
if(SDRPLAY_INCLUDE_DIR AND SDRPLAY_LIBRARY)
message(STATUS "SDRPLAY: found - ${SDRPLAY_INCLUDE_DIR}, ${SDRPLAY_LIBRARY}")
add_definitions(-DHASSDRPLAY)
set(SDRPLAY_INCLUDE_DIRS ${SDRPLAY_INCLUDE_DIR})
set(SDRPLAY_LIBRARIES ${SDRPLAY_LIBRARY})
else()
message(STATUS "SDRPLAY: not found.")
endif()
else()
set(SDRPLAY_API_DIR $ENV{PROGRAMFILES}\\SDRplay\\API)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(SDRPLAY_API_LIB_DIR ${SDRPLAY_API_DIR}\\x64\\)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(SDRPLAY_API_LIB_DIR ${SDRPLAY_API_DIR}\\x32\\)
endif()
find_path(SDRPLAY_INCLUDE_DIR sdrplay_api.h HINTS ${SDRPLAY_API_DIR}\\inc)
find_library(SDRPLAY_LIBRARY sdrplay_api.lib HINTS ${SDRPLAY_API_LIB_DIR})
find_file(SDRPLAY_DLL sdrplay_api.dll HINTS ${SDRPLAY_API_LIB_DIR})
if(SDRPLAY_INCLUDE_DIR AND SDRPLAY_LIBRARY AND SDRPLAY_DLL)
message(STATUS "SDRPLAY: found - ${SDRPLAY_INCLUDE_DIR}, ${SDRPLAY_LIBRARY}, ${SDRPLAY_DLL}")
add_definitions(-DHASSDRPLAY)
set(COPY_SDRPLAY_DLL TRUE)
set(SDRPLAY_INCLUDE_DIRS ${SDRPLAY_INCLUDE_DIR})
set(SDRPLAY_LIBRARIES ${SDRPLAY_LIBRARY})
else()
message(STATUS "SDRPLAY: not found. Assumed directory ${SDRPLAY_API_LIB_DIR}")
endif()
endif()
# Find Airspy library.
if(NOT MSVC)
pkg_check_modules(PKG_AIRSPY libairspy)
find_path(AIRSPY_INCLUDE_DIR airspy.h HINT ${PKG_AIRSPY_INCLUDE_DIRS})
find_library(AIRSPY_LIBRARY airspy HINT ${PKG_AIRSPY_LIBRARY_DIRS})
if(AIRSPY_INCLUDE_DIR AND AIRSPY_LIBRARY)
message(STATUS "AIRSPY: found ${AIRSPY_INCLUDE_DIR}, ${AIRSPY_LIBRARY}")
add_definitions(-DHASAIRSPY)
set(AIRSPY_INCLUDE_DIRS ${AIRSPY_INCLUDE_DIR} ${LIBUSB_INCLUDE_DIR})
set(AIRSPY_LIBRARIES ${AIRSPY_LIBRARY} ${LIBUSB_LIBRARY})
else()
Message(STATUS "AIRSPY: not found.")
endif()
elseif(MSVC_VCPKG)
Message("AIRSPY: not found (VCPKG)")
else()
find_path(AIRSPY_INCLUDE_DIR airspy.h HINTS ${POTHOSSDR_INCLUDE_DIR}\\libairspy)
find_library(AIRSPY_LIBRARY airspy.lib HINTS ${POTHOSSDR_BINARY_DIR})
find_file(AIRSPY_DLL airspy.dll HINTS ${POTHOSSDR_BINARY_DIR})
if(AIRSPY_INCLUDE_DIR AND AIRSPY_LIBRARY AND AIRSPY_DLL)
Message(STATUS "AIRSPYHF: found (PothosSDR) - " ${AIRSPY_INCLUDE_DIR}, ${AIRSPY_LIBRARY}, ${AIRSPY_DLL})
set(COPY_AIRSPY_DLL TRUE)
set(COPY_PTHREAD_LIBUSB_DLL TRUE)
add_definitions(-DHASAIRSPY)
set(AIRSPY_INCLUDE_DIRS ${AIRSPY_INCLUDE_DIR})
set(AIRSPY_LIBRARIES ${AIRSPY_LIBRARY})
else()
Message(STATUS "AIRSPY: not found.")
endif()
endif()
# Find Airspy library.
if(NOT MSVC)
pkg_check_modules(PKG_AIRSPYHF libairspyhf)
find_path(AIRSPYHF_INCLUDE_DIR airspyhf.h HINT ${PKG_AIRSPYHF_INCLUDE_DIRS})
find_library(AIRSPYHF_LIBRARY airspyhf HINT ${PKG_AIRSPYHF_LIBRARY_DIRS})
if(AIRSPYHF_INCLUDE_DIR AND AIRSPYHF_LIBRARY)
message(STATUS "AIRSPYHF: found - ${AIRSPYHF_INCLUDE_DIR}, ${AIRSPYHF_LIBRARY}")
add_definitions(-DHASAIRSPYHF)
set(AIRSPYHF_INCLUDE_DIRS ${AIRSPYHF_INCLUDE_DIR} ${LIBUSB_INCLUDE_DIR})
set(AIRSPYHF_LIBRARIES ${AIRSPYHF_LIBRARY} ${LIBUSB_LIBRARY})
else()
Message(STATUS "AIRSPYHF: not found.")
endif()
elseif(MSVC_VCPKG)
Message("AIRSPYHF: not found (VCPKG)")
else()
find_path(AIRSPYHF_INCLUDE_DIR AIRSPYHF.h HINTS ${POTHOSSDR_INCLUDE_DIR}\\libairspyhf)
find_library(AIRSPYHF_LIBRARY AIRSPYHF.lib HINTS ${POTHOSSDR_BINARY_DIR})
find_file(AIRSPYHF_DLL AIRSPYHF.dll HINTS ${POTHOSSDR_BINARY_DIR})
if(AIRSPYHF_INCLUDE_DIR AND AIRSPYHF_LIBRARY AND AIRSPYHF_DLL)
Message(STATUS "AIRSPYHF: found (PothosSDR) - " ${AIRSPYHF_INCLUDE_DIR}, ${AIRSPYHF_LIBRARY}, ${AIRSPYHF_DLL})
set(COPY_AIRSPYHF_DLL TRUE)
set(COPY_PTHREAD_LIBUSB_DLL TRUE)
add_definitions(-DHASAIRSPYHF)
set(AIRSPYHF_INCLUDE_DIRS ${AIRSPYHF_INCLUDE_DIR})
set(AIRSPYHF_LIBRARIES ${AIRSPYHF_LIBRARY})
else()
Message(STATUS "AIRSPYHF: not found (PothosSDR).")
endif()
endif()
# Find HACKRF library.
if(NOT MSVC)
pkg_check_modules(PKG_HACKRF libhackrf)
find_path(HACKRF_INCLUDE_DIR hackrf.h HINT ${PKG_HACKRF_INCLUDE_DIRS} /usr/include/libhackrf)
find_library(HACKRF_LIBRARY hackrf HINT ${PKG_HACKRF_LIBRARY_DIRS})
if(HACKRF_INCLUDE_DIR AND HACKRF_LIBRARY)
message(STATUS "HACKRF: found - ${HACKRF_INCLUDE_DIR}, ${HACKRF_LIBRARY}")
add_definitions(-DHASHACKRF)
set(HACKRF_INCLUDE_DIRS ${HACKRF_INCLUDE_DIR} ${LIBUSB_INCLUDE_DIR})
set(HACKRF_LIBRARIES ${HACKRF_LIBRARY} ${LIBUSB_LIBRARY})
else()
Message(STATUS "HACKRF: not found.")
endif()
elseif(MSVC_VCPKG)
Message("HACKRF: not found (VCPKG)")
else()
find_path(HACKRF_INCLUDE_DIR hackrf.h HINTS ${POTHOSSDR_INCLUDE_DIR}\\libhackrf)
find_library(HACKRF_LIBRARY hackrf.lib HINTS ${POTHOSSDR_LIBRARY_DIR})
find_file(HACKRF_DLL hackrf.dll HINTS ${POTHOSSDR_BINARY_DIR})
if(HACKRF_INCLUDE_DIR AND HACKRF_LIBRARY AND HACKRF_DLL)
Message(STATUS "HACKRF: found (PothosSDR) - " ${HACKRF_INCLUDE_DIR}, ${HACKRF_LIBRARY}, ${HACKRF_DLL})
set(COPY_HACKRF_DLL TRUE)
set(COPY_PTHREAD_LIBUSB_DLL TRUE)
add_definitions(-DHASHACKRF)
set(HACKRF_INCLUDE_DIRS ${HACKRF_INCLUDE_DIR})
set(HACKRF_LIBRARIES ${HACKRF_LIBRARY})
else()
Message(STATUS "HACKRF: not found (PothosSDR)")
endif()
endif()
# Find libzmq
if(NOT MSVC)
pkg_check_modules(PKG_LIBZMQ libzmq)
find_path(LIBZMQ_INCLUDE_DIR zmq.h HINT ${PKG_LIBZMQ_INCLUDE_DIRS})
find_library(LIBZMQ_LIBRARY zmq HINT ${PKG_LIBZMQ_LIBRARY_DIRS})
if(LIBZMQ_INCLUDE_DIR AND LIBZMQ_LIBRARY)
message(STATUS "ZMQ: found - ${LIBZMQ_INCLUDE_DIR}, ${LIBZMQ_LIBRARY}")
add_definitions(-DHASZMQ)
set(ZMQ_INCLUDE_DIRS ${LIBZMQ_INCLUDE_DIR})
set(ZMQ_LIBRARIES ${LIBZMQ_LIBRARY})
else()
message(STATUS "ZMQ: not found.")
endif()
elseif(MSVC_VCPKG)
find_package(ZeroMQ)
if(ZeroMQ_FOUND)
add_definitions(-DHASZMQ)
set(ZMQ_LIBRARIES libzmq)
Message(STATUS "ZMQ: found (VCPKG) - " ${ZMQ_LIBRARIES})
else()
Message(STATUS "ZMQ: not found (VCPKG).")
endif()
else()
find_path(ZMQ_INCLUDE_DIR zmq.h HINTS ${POTHOSSDR_INCLUDE_DIR})
find_library(ZMQ_LIBRARY libzmq-v142-mt-4_1_8.lib HINTS ${POTHOSSDR_LIBRARY_DIR})
find_file(ZMQ_DLL libzmq-v142-mt-4_1_8.dll HINTS ${POTHOSSDR_BINARY_DIR})
if(ZMQ_INCLUDE_DIR AND ZMQ_LIBRARY AND ZMQ_DLL)
Message(STATUS "ZMQ: found (PothosSDR) - " ${ZMQ_INCLUDE_DIR}, ${ZMQ_LIBRARY}, ${ZMQ_DLL})
set(COPY_ZMQ_DLL TRUE)
set(COPY_PTHREAD_LIBUSB_DLL TRUE)
add_definitions(-DHASZMQ)
set(ZMQ_INCLUDE_DIRS ${ZMQ_INCLUDE_DIR})
set(ZMQ_LIBRARIES ${ZMQ_LIBRARY})
else()
Message(STATUS "ZMQ: not found (PothosSDR)")
endif()
endif()
set(CPP
Application/Main.cpp
Device/AIRSPYHF.cpp Device/FileWAV.cpp Device/RTLSDR.cpp Device/SDRPLAY.cpp DSP/Demod.cpp DSP/Model.cpp Library/AIS.cpp
Device/FileRAW.cpp Device/HACKRF.cpp Device/RTLTCP.cpp Device/ZMQ.cpp
Library/Utilities.cpp
Device/AIRSPY.cpp
DSP/DSP.cpp
IO/IO.cpp)
set(HEADER
Application/AIS-catcher.h
Device/Device.h Device/FileWAV.h Device/RTLTCP.h DSP/Demod.h DSP/Filters.h Library/AIS.h Library/Signals.h
Device/AIRSPY.h Device/FIFO.h Device/HACKRF.h Device/SDRPLAY.h DSP/DSP.h DSP/Model.h Library/Common.h Library/Stream.h
Device/AIRSPYHF.h Device/FileRAW.h Device/RTLSDR.h Device/ZMQ.h DSP/FFT.h IO/IO.h Library/Utilities.h)
set(APP_INCLUDES . ./Library ./DSP ./Application ./IO)
# Executable
add_executable(AIS-catcher ${CPP} ${HEADER})
include_directories(
${AIRSPYHF_INCLUDE_DIRS} ${AIRSPY_INCLUDE_DIRS} ${HACKRF_INCLUDE_DIRS} ${RTLSDR_INCLUDE_DIRS} ${ZMQ_INCLUDE_DIRS} ${SDRPLAY_INCLUDE_DIRS}
${APP_INCLUDES})
target_link_libraries(AIS-catcher
${AIRSPY_LIBRARIES} ${AIRSPYHF_LIBRARIES} ${RTLSDR_LIBRARIES} ${HACKRF_LIBRARIES} ${ZMQ_LIBRARIES} ${SDRPLAY_LIBRARIES}
${ADDITIONAL_LIBRARIES} Threads::Threads)
# Copying DLLs to final location if needed
if(COPY_SDRPLAY_DLL)
add_custom_command(TARGET AIS-catcher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SDRPLAY_DLL} ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(COPY_RTLSDR_DLL)
add_custom_command(TARGET AIS-catcher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${RTLSDR_DLL} ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(COPY_AIRSPY_DLL)
add_custom_command(TARGET AIS-catcher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${AIRSPY_DLL} ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(COPY_AIRSPYHF_DLL)
add_custom_command(TARGET AIS-catcher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${AIRSPYHF_DLL} ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(COPY_HACKRF_DLL)
add_custom_command(TARGET AIS-catcher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${HACKRF_DLL} ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(COPY_ZMQ_DLL)
add_custom_command(TARGET AIS-catcher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${ZMQ_DLL} ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(COPY_PTHREAD_LIBUSB_DLL)
add_custom_command(TARGET AIS-catcher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${LIBUSB_DLL} ${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(TARGET AIS-catcher POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PTHREAD_DLL} ${CMAKE_CURRENT_BINARY_DIR})
endif()
# Installation
install(TARGETS AIS-catcher DESTINATION bin)
# End of CMakeLists.txt