-
Notifications
You must be signed in to change notification settings - Fork 145
/
CMakeLists.txt
350 lines (299 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
# Copyright 2018 Analog Devices, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
cmake_minimum_required(VERSION 3.13.0)
# needed to use VERSION in 'project()'
cmake_policy(SET CMP0048 NEW)
set(OSC_VERSION_MAJOR 0)
set(OSC_VERSION_MINOR 8)
set(OSC_VERSION "${OSC_VERSION_MAJOR}.${OSC_VERSION_MINOR}")
project(iio-oscilloscope
VERSION ${OSC_VERSION}
LANGUAGES C
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
string(TIMESTAMP BUILD_YEAR "%Y")
endif()
include(GNUInstallDirs)
# Get the GIT hash of the latest commit
include(FindGit OPTIONAL)
if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} show -s --pretty=format:%ct HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_TIMESTAMP
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --abbrev=7 --dirty --always
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(OSC_VERSION "${GIT_BRANCH}-g${GIT_HASH}")
set(GIT_VERSION "-DGIT_VERSION=\"${GIT_VERSION}\"")
set(GIT_COMMIT_TIMESTAMP "-DGIT_COMMIT_TIMESTAMP=${GIT_COMMIT_TIMESTAMP}")
else()
set(OSC_VERSION v${PROJECT_VERSION})
endif()
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_compile_options("-F/Library/Frameworks/")
link_libraries("-F/Library/Frameworks/")
# Fix linking on 10.14+ with Homebrew. See https://stackoverflow.com/questions/54068035
LINK_DIRECTORIES(/usr/local/lib)
endif()
add_definitions(-D_GNU_SOURCE
-DOSC_VERSION="${OSC_VERSION}"
${GIT_VERSION}
${GIT_COMMIT_TIMESTAMP}
-DGTK_DISABLE_DEPRECATED
-D_POSIX_C_SOURCE=200809L
)
add_compile_options(-Wall -Wextra -Werror
-Wno-unused-parameter
-Wno-error=unused-but-set-variable
-Wno-error=unused-function
-Wno-error=deprecated
-Wimplicit-fallthrough
-Wvla
-std=gnu90
-g -O2
)
if(UNIX)
add_definitions(-Dlinux -DFRU_FILES="${CMAKE_PREFIX_PATH}/lib/fmc-tools/")
endif()
set(OSC_SRC osc.c oscplot.c datatypes.c iio_widget.c iio_utils.c
fru.c dialogs.c trigger_dialog.c xml_utils.c libini/libini.c
libini2.c phone_home.c plugins/dac_data_manager.c
plugins/fir_filter.c eeprom.c osc_preferences.c cJSON/cJSON.c)
find_package(PkgConfig)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(GTK REQUIRED gtk+-3.0)
pkg_check_modules(GTHREAD REQUIRED gthread-2.0)
pkg_check_modules(GTKDATABOX REQUIRED gtkdatabox>=1.0.0)
pkg_check_modules(FFTW3 REQUIRED fftw3)
pkg_check_modules(LIBXML2 REQUIRED libxml-2.0)
pkg_check_modules(LIBCURL REQUIRED libcurl)
pkg_check_modules(JANSSON REQUIRED jansson)
pkg_check_modules(MATIO REQUIRED matio)
find_library(LIBIIO_LIBRARIES iio)
find_path(LIBIIO_INCLUDE_DIRS iio.h)
find_library(LIBAD9361_LIBRARIES ad9361)
find_path(LIBAD9361_INCLUDE_DIRS ad9361.h)
if ((NOT LIBAD9361_LIBRARIES) AND (NOT LIBAD9361_INCLUDE_DIRS))
set(LIBAD9361_LIBRARIES "")
set(LIBAD9361_INCLUDE_DIRS "")
endif()
find_library(LIBAD9166_LIBRARIES ad9166)
find_path(LIBAD9166_INCLUDE_DIRS ad9166.h)
if ((NOT LIBAD9166_LIBRARIES) AND (NOT LIBAD9166_INCLUDE_DIRS))
set(LIBAD9166_LIBRARIES "")
set(LIBAD9166_INCLUDE_DIRS "")
endif()
find_library(LIBSERIALPORT_LIBRARIES serialport)
find_path(LIBSERIALPORT_INCLUDE_DIR libserialport.h)
if (LIBSERIALPORT_LIBRARIES AND LIBSERIALPORT_INCLUDE_DIR)
option(WITH_SERIAL_BACKEND "Enable the serial backend" ON)
add_definitions(-DSERIAL_BACKEND=1)
else()
set(LIBSERIALPORT_LIBRARIES "")
set(LIBSERIALPORT_INCLUDE_DIR "")
endif()
# On some newer systems (Ubuntu) it tries to link with libhdf5.so,
# which doesn't seem to exist; but we only need -lmatio, so force it here
set(MATIO_LIBRARIES -lmatio)
set(LIBOSC_LIBS
${GLIB_LIBRARIES}
${GLIBCONFIG_LIBRARIES}
${GTK_LIBRARIES}
${GTHREAD_LIBRARIES}
${GTKDATABOX_LIBRARIES}
${FFTW3_LIBRARIES}
${LIBIIO_LIBRARIES}
${LIBXML2_LIBRARIES}
${LIBCURL_LIBRARIES}
${LIBSERIALPORT_LIBRARIES}
${JANSSON_LIBRARIES}
${MATIO_LIBRARIES}
${LIBAD9361_LIBRARIES}
${LIBAD9166_LIBRARIES}
dl
)
configure_file(config.h.cmakein ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)
if(CMAKE_COMPILER_IS_GNUCC)
# TO DO: remove -Wno-deprecated-declarations -Wno-unused-function -Wno-unused-variable
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -Wno-unused-parameter -Wno-deprecated-declarations -Wno-unused-function -Wno-unused-variable")
endif()
# Override on distributions that do not use a global polkit prefix (e.g. NixOS)
if(NOT DEFINED CMAKE_POLKIT_PREFIX)
set(CMAKE_POLKIT_PREFIX /usr)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# This is a bit hacky but looks to be the less intrusive way I could think of
# to handle this. This is only useful when creating the windows installer together
# with the CI script. In that case, we have a sysroot with all dependecies where
# we want to install our artifacts. Hence, the first feeling is to just point
# CMAKE_INSTALL_PREFIX to that sysroot and we should fine. Well, that will
# break auto genarated files as config.h since the sysroot path won't exist in
# the target machine. Cpack gives us an easy way to package our artifacts in a tar.z
# archive with all the installation paths being relative (GNU DIR paths. The only
# full paths used are specific to linux builds). Hence, the CI script can just call
# 'make package' and untar it to the right place in the sysroot path. On top of
# this, it also gives us more flexibility to set CMAKE_INSTALL_PREFIX to a value
# that will be valid for the auto genarated files (there are some subtleties with
# this for windows). To finish it up, this also leaves the door open to just use
# cmake to package our windows installer (together with nsis).
add_definitions(-D__MINGW__)
set(CPACK_BINARY_NSIS OFF)
set(CPACK_GENERATOR TZ)
include(CPack)
list(APPEND LIBOSC_LIBS winpthread)
list(REMOVE_ITEM OSC_SRC eeprom.c)
set(OSCMAIN_RC oscicon.rc)
set_source_files_properties(${OSCMAIN_RC} PROPERTIES LANGUAGE RC)
add_compile_options(-mwindows)
set(WIN_LINK_FLAGS "-Wl,--export-all-symbols -Wl,--subsystem,windows")
else()
add_link_options(-rdynamic)
endif()
add_library(osc ${OSC_SRC})
target_include_directories(osc PRIVATE
${GLIB_INCLUDE_DIRS}
${GLIBCONFIG_INCLUDE_DIRS}
${GTK_INCLUDE_DIRS}
${GTHREAD_INCLUDE_DIRS}
${GTKDATABOX_INCLUDE_DIRS}
${FFTW3_INCLUDE_DIRS}
${LIBIIO_INCLUDE_DIRS}
${LIBXML2_INCLUDE_DIRS}
${LIBCURL_INCLUDE_DIRS}
${LIBSERIALPORT_INCLUDE_DIR}
${JANSSON_INCLUDE_DIRS}
${MATIO_INCLUDE_DIRS}
${HDF5_INCLUDE_DIRS}
${LIBAD9361_INCLUDE_DIRS}
${LIBAD9166_INCLUDE_DIRS}
)
target_link_libraries(osc PRIVATE ${LIBOSC_LIBS})
set_target_properties(osc PROPERTIES
LINK_FLAGS "${WIN_LINK_FLAGS}"
VERSION ${PROJECT_VERSION}
SOVERSION ${OSC_VERSION_MAJOR}
)
add_executable(oscmain WIN32 oscmain.c ${OSCMAIN_RC})
target_include_directories(oscmain PRIVATE
${GTK_INCLUDE_DIRS}
${LIBIIO_INCLUDE_DIRS}
)
target_link_libraries(oscmain PRIVATE
${GTK_LIBRARIES}
${LIBIIO_LIBRARIES}
osc
)
set_target_properties(oscmain PROPERTIES OUTPUT_NAME osc)
install(TARGETS osc
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(TARGETS oscmain RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
# Set default CMAKE_PREFIX_PATH to CMAKE_SYSTEM_PREFIX_PATH
set(CMAKE_PREFIX_PATH ${CMAKE_SYSTEM_PREFIX_PATH})
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
configure_file(org.adi.pkexec.osc.policy.cmakein ${CMAKE_CURRENT_BINARY_DIR}/org.adi.pkexec.osc.policy @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.adi.pkexec.osc.policy
DESTINATION ${CMAKE_POLKIT_PREFIX}/${CMAKE_INSTALL_DATADIR}/polkit-1/actions/)
# setup exec script
configure_file(osc-wrapper.cmakein ${CMAKE_CURRENT_BINARY_DIR}/osc-wrapper @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/osc-wrapper
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION bin)
endif()
set(PLIB_DEST ${CMAKE_INSTALL_LIBDIR}/osc)
set(SHARE_DEST ${CMAKE_INSTALL_DATADIR}/osc)
set(GLADE_FILES_DEST ${SHARE_DEST}/glade)
file(GLOB GLADE_FILES glade/*.glade)
file(GLOB ICON_FILES icons/*)
install(FILES ${GLADE_FILES} ${ICON_FILES} DESTINATION ${GLADE_FILES_DEST})
set(GLADE_FILES_DEST ${CMAKE_CURRENT_BINARY_DIR}/glade)
file(COPY ${GLADE_FILES} DESTINATION ${GLADE_FILES_DEST})
file(COPY ${ICON_FILES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/icons")
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
configure_file(adi-osc.desktop.cmakein ${CMAKE_CURRENT_BINARY_DIR}/adi-osc.desktop @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/adi-osc.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications/)
# install theme icons
install(FILES icons/osc16.png RENAME adi-osc.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/16x16/apps)
install(FILES icons/osc32.png RENAME adi-osc.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/32x32/apps)
install(FILES icons/osc64.png RENAME adi-osc.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/64x64/apps)
install(FILES icons/osc128.png RENAME adi-osc.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/128x128/apps)
install(FILES icons/osc256.png RENAME adi-osc.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/256x256/apps)
install(FILES icons/osc.svg RENAME adi-osc.svg
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
install(FILES ./styles.css DESTINATION ${SHARE_DEST})
# This is a bit "ugly". It makes sure that the hicolor theme directory updates
# it's modification date. This makes sure that osc icons are loaded right away.
# We can also just remove this and assume the user has do this manually or run
# something like `gtk-update-icon-cache -f /usr/share/icons/hicolor`.
install(CODE "EXECUTE_PROCESS(COMMAND sh -c \"touch ${CMAKE_INSTALL_FULL_DATADIR}/icons/hicolor\")")
endif()
install(DIRECTORY icons DESTINATION ${SHARE_DEST})
file(GLOB PROFILES profiles/*.cmakein)
foreach(PROFILE IN LISTS PROFILES)
string(REPLACE ".cmakein" "" PROFILE_TARGET ${PROFILE})
get_filename_component(FROFILE_TARGET_BASENAME ${PROFILE_TARGET} NAME)
configure_file(${PROFILE} ${CMAKE_CURRENT_BINARY_DIR}/profiles/${FROFILE_TARGET_BASENAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/profiles/${FROFILE_TARGET_BASENAME}
DESTINATION ${PLIB_DEST}/profiles/
)
endforeach()
file(GLOB PROFILES profiles/*.ini)
install(FILES ${PROFILES} DESTINATION ${PLIB_DEST}/profiles/)
foreach(plib_dest xmls filters waveforms block_diagrams)
install(DIRECTORY ${plib_dest} DESTINATION ${PLIB_DEST})
endforeach()
set(MODEL_FILE "styles.css")
set(TARGET_PATH "${CMAKE_CURRENT_BINARY_DIR}/${MODEL_FILE}")
set(MODEL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${MODEL_FILE}")
if(NOT EXISTS "${TARGET_PATH}")
file(COPY "${MODEL_FILE}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
endif()
add_subdirectory(plugins)
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()