forked from gqrx-sdr/gqrx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
267 lines (228 loc) · 8.91 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
cmake_minimum_required(VERSION 3.2)
# Project name
project(gqrx)
set(${PROJECT_NAME}_MAJOR "2")
set(${PROJECT_NAME}_MINOR "16")
set(${PROJECT_NAME}_PATCH "0")
set(IS_RELEASE FALSE)
if(IS_RELEASE)
if(${PROJECT_NAME}_PATCH EQUAL 0)
set(VERSION "${${PROJECT_NAME}_MAJOR}.${${PROJECT_NAME}_MINOR}")
else()
set(VERSION "${${PROJECT_NAME}_MAJOR}.${${PROJECT_NAME}_MINOR}.${${PROJECT_NAME}_PATCH}")
endif()
else()
execute_process(
COMMAND git describe --long --dirty
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
add_definitions(-DVERSION="${VERSION}")
file(WRITE version.txt ${VERSION})
set(PACKAGE ${PROJECT_NAME})
########### Main global variables ###########
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug GProf Valgrind Release" FORCE)
endif()
set(BUILDTYPE ${CMAKE_BUILD_TYPE})
string(TOUPPER ${BUILDTYPE} BUILDTYPE)
add_definitions(-D${BUILDTYPE})
# We have some custom .cmake scripts not in the official distribution.
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
# Add valgrind build options if necessary
if(${CMAKE_BUILD_TYPE} MATCHES "Valgrind")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
endif()
# Workaround for naming collision with log4cpp for Debug builds
add_definitions(-DLOG4CPP_FIX_ERROR_COLLISION=1)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# using regular Clang or AppleClang
set(CMAKE_COMPILER_IS_CLANGXX 1)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
add_definitions(-Wall)
add_definitions(-Wextra)
add_definitions(-Wno-unused-parameter)
add_definitions(-Wsign-compare)
endif()
if(MSVC)
#get math definitions like M_PI
add_definitions(-D_USE_MATH_DEFINES)
#use std::min()/std::max()
add_definitions(-DNOMINMAX)
#needed to dynamically link boost
add_definitions(-DBOOST_ALL_DYN_LINK)
#export gr-rds symbols
add_definitions(-Dgnuradio_RDS_EXPORTS)
if ("${MSVC_VERSION}" VERSION_LESS "1900")
add_definitions(-D__func__=__FUNCTION__)
endif()
endif()
# Functions & macros. These must be defined before including subdirectories.
# function to collect all the sources from sub-directories
# into a single list
function(add_source_files list)
get_property(is_defined GLOBAL PROPERTY SRCS_LIST DEFINED)
if(NOT is_defined)
define_property(GLOBAL PROPERTY ${list}
BRIEF_DOCS "List of source files"
FULL_DOCS "List of source files to be compiled in one library")
endif()
# make absolute paths
set(SRCS)
foreach(s IN LISTS ARGN)
if(NOT IS_ABSOLUTE "${s}")
get_filename_component(s "${s}" ABSOLUTE)
endif()
list(APPEND SRCS "${s}")
endforeach()
# append to global list
set_property(GLOBAL APPEND PROPERTY ${list} "${SRCS}")
endfunction(add_source_files)
if(APPLE AND EXISTS /usr/local/opt/qt5)
# Homebrew installs Qt5 (up to at least 5.9.1) in
# /usr/local/opt/qt5, ensure it can be found by CMake since
# it is not in the default /usr/local prefix.
list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/qt5")
endif()
if(APPLE AND EXISTS /usr/local/opt/qt6)
list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/qt6")
endif()
if(APPLE AND EXISTS /usr/local/opt/icu4c/lib)
# With Homebrew icu4c, `-licudata -licui18n -licuuc`
# are required, which reside in /usr/local/opt/icu4c/lib.
# See src/CMakeFiles/gqrx.dir/link.txt in the build directory.
set(ICU4C_LIBRARY_DIRS "/usr/local/opt/icu4c/lib")
else()
set(ICU4C_LIBRARY_DIRS "")
endif()
# 3rd Party Dependency Stuff
find_package(Qt6 QUIET COMPONENTS Core Network Widgets Svg SvgWidgets)
if(NOT Qt6_FOUND)
find_package(Qt5 REQUIRED COMPONENTS Core Network Widgets Svg)
endif()
include(FindPkgConfig)
find_package(Gnuradio-osmosdr REQUIRED)
set(GR_REQUIRED_COMPONENTS RUNTIME ANALOG AUDIO BLOCKS DIGITAL FILTER FFT PMT)
find_package(Gnuradio REQUIRED COMPONENTS analog audio blocks digital filter fft network)
if(NOT Gnuradio_FOUND)
message(FATAL_ERROR "GnuRadio Runtime required to compile gqrx")
endif()
find_package(Volk)
# Pass the GNU Radio version as 0xMMNNPP BCD.
math(EXPR GNURADIO_BCD_VERSION
"(${Gnuradio_VERSION_MAJOR} / 10) << 20 |
(${Gnuradio_VERSION_MAJOR} % 10) << 16 |
(${Gnuradio_VERSION_MINOR} / 10) << 12 |
(${Gnuradio_VERSION_MINOR} % 10) << 8 |
(${Gnuradio_VERSION_PATCH} / 10) << 4 |
(${Gnuradio_VERSION_PATCH} % 10) << 0
"
)
add_definitions(-DGNURADIO_VERSION=${GNURADIO_BCD_VERSION})
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD")
if(NOT LINUX_AUDIO_BACKEND)
set(LINUX_AUDIO_BACKEND Pulseaudio CACHE STRING "Choose the audio backend, options are: Pulseaudio, Portaudio, Gr-audio" FORCE)
endif()
if(${LINUX_AUDIO_BACKEND} MATCHES "Pulseaudio")
message(STATUS "Pulseaudio backend enabled")
find_package(PulseAudio REQUIRED)
# there is a defect in the pulse audio cmake file that does not include this library. So we add it here.
find_library(PULSE-SIMPLE NAMES pulse-simple REQUIRED)
add_definitions(-DWITH_PULSEAUDIO)
unset(PORTAUDIO_INCLUDE_DIRS CACHE)
unset(PORTAUDIO_LIBRARIES CACHE)
elseif(${LINUX_AUDIO_BACKEND} MATCHES "Portaudio")
message(STATUS "Portaudio backend enabled")
find_package(PORTAUDIO REQUIRED)
add_definitions(-DWITH_PORTAUDIO)
unset(PULSEAUDIO_FOUND CACHE)
unset(PULSEAUDIO_INCLUDE_DIR CACHE)
unset(PULSEAUDIO_LIBRARY CACHE)
unset(PulseAudio_DIR CACHE)
unset(PULSE-SIMPLE CACHE)
unset(PULSEAUDIO_INCLUDE_DIR CACHE)
unset(PULSEAUDIO_MAINLOOP_LIBRARY CACHE)
elseif(${LINUX_AUDIO_BACKEND} MATCHES "Gr-audio")
message(STATUS "Gr-audio backend enabled")
unset(PULSEAUDIO_FOUND CACHE)
unset(PULSEAUDIO_INCLUDE_DIR CACHE)
unset(PULSEAUDIO_LIBRARY CACHE)
unset(PulseAudio_DIR CACHE)
unset(PULSE-SIMPLE CACHE)
unset(PULSEAUDIO_INCLUDE_DIR CACHE)
unset(PULSEAUDIO_MAINLOOP_LIBRARY CACHE)
unset(PORTAUDIO_INCLUDE_DIRS CACHE)
unset(PORTAUDIO_LIBRARIES CACHE)
else()
message(FATAL_ERROR "Invalid audio backend: should be either Pulseaudio, Portaudio or Gr-audio")
endif()
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(NOT OSX_AUDIO_BACKEND)
set(OSX_AUDIO_BACKEND Portaudio CACHE STRING "Choose the audio backend, options are: Portaudio and Gr-audio" FORCE)
endif()
if(${OSX_AUDIO_BACKEND} MATCHES "Portaudio")
message(STATUS "Portaudio backend enabled")
find_package(PORTAUDIO REQUIRED)
add_definitions(-DWITH_PORTAUDIO)
unset(PULSEAUDIO_FOUND CACHE)
unset(PULSEAUDIO_INCLUDE_DIR CACHE)
unset(PULSEAUDIO_LIBRARY CACHE)
unset(PulseAudio_DIR CACHE)
unset(PULSE-SIMPLE CACHE)
unset(PULSEAUDIO_INCLUDE_DIR CACHE)
unset(PULSEAUDIO_MAINLOOP_LIBRARY CACHE)
elseif(${OSX_AUDIO_BACKEND} MATCHES "Gr-audio")
message(STATUS "Gr-audio backend enabled")
unset(PULSEAUDIO_FOUND CACHE)
unset(PULSEAUDIO_INCLUDE_DIR CACHE)
unset(PULSEAUDIO_LIBRARY CACHE)
unset(PulseAudio_DIR CACHE)
unset(PULSE-SIMPLE CACHE)
unset(PULSEAUDIO_INCLUDE_DIR CACHE)
unset(PULSEAUDIO_MAINLOOP_LIBRARY CACHE)
unset(PORTAUDIO_INCLUDE_DIRS CACHE)
unset(PORTAUDIO_LIBRARIES CACHE)
else()
message(FATAL_ERROR "Invalid audio backend: should be either Portaudio or Gr-audio")
endif()
endif()
# Airspy optimizations that require modified gr-osmosdr
option(CUSTOM_AIRSPY_KERNELS "Enable non-standard Airspy optimizations" ON)
if(CUSTOM_AIRSPY_KERNELS)
add_definitions(-DCUSTOM_AIRSPY_KERNELS)
endif(CUSTOM_AIRSPY_KERNELS)
# Tell CMake to run moc when necessary:
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Finish configuring compiler / linker settings & flags
include_directories(
${CMAKE_SOURCE_DIR}/include
${GNURADIO_OSMOSDR_INCLUDE_DIRS}
)
link_directories(
${GNURADIO_RUNTIME_LIBRARY_DIRS}
${ICU4C_LIBRARY_DIRS}
)
# Install desktop
install(FILES dk.gqrx.gqrx.desktop DESTINATION share/applications)
# Install appstream / metainfo file
install(FILES dk.gqrx.gqrx.appdata.xml DESTINATION share/metainfo)
# Install icon
install(FILES resources/icons/gqrx.svg DESTINATION share/icons/hicolor/scalable/apps)
# Add subdirectories
add_subdirectory(src)
# uninstall target
# https://cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)