]> sigrok.org Git - pulseview.git/blame - CMakeLists.txt
Session: Fix issue #67 by improving error handling
[pulseview.git] / CMakeLists.txt
CommitLineData
0aad432c 1##
190fc91a 2## This file is part of the PulseView project.
68c4a3b3
JH
3##
4## Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
3933e8a9 5## Copyright (C) 2012-2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
c3660d7d 6## Copyright (C) 2020 Soeren Apel <soeren@apelpie.net>
68c4a3b3
JH
7##
8## This program is free software: you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation, either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program. If not, see <http://www.gnu.org/licenses/>.
20##
21
e222f01e 22cmake_minimum_required(VERSION 2.8.12)
0cf9fb24 23
d1125d7d 24project(pulseview C CXX)
df944399 25
d1125d7d 26include(GNUInstallDirs)
df944399 27
1c4ec8d0
UH
28# Let AUTOMOC and AUTOUIC process GENERATED files.
29if(POLICY CMP0071)
30 cmake_policy(SET CMP0071 NEW)
31endif()
32
2944860f
UH
33# Only interpret if() arguments as variables or keywords when unquoted.
34if(POLICY CMP0054)
35 cmake_policy(SET CMP0054 NEW)
36endif()
37
cf2b5b64
UH
38list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
39
30588653 40#===============================================================================
506523c1
JH
41#= User Options
42#-------------------------------------------------------------------------------
43
5c3c8c1e 44option(DISABLE_WERROR "Build without -Werror" TRUE)
140181a4 45option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
c1a688de 46option(ENABLE_STACKTRACE "Enable stack trace when crashing" FALSE)
19f511a4 47option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
f058e273 48option(ENABLE_FLOW "Build with libsigrokflow" FALSE)
b2d9be03 49option(ENABLE_TESTS "Enable unit tests" FALSE)
61e1e13e 50option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
3903edbd 51option(ENABLE_TS_UPDATE "Update .ts source files (Qt l10n)" FALSE)
b04e278d
AG
52
53if(WIN32)
7d297a01
UH
54 # On Windows/MinGW we need to statically link to libraries.
55 # This option is user configurable, but enable it by default on win32.
b04e278d 56 set(STATIC_PKGDEPS_LIBS TRUE)
6987ceeb 57
0aad432c 58 # Windows does not support UNIX signals.
140181a4 59 set(ENABLE_SIGNALS FALSE)
b04e278d 60endif()
506523c1 61
552f686e 62if(NOT CMAKE_BUILD_TYPE)
7591fe23
UH
63 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
64 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
65 FORCE)
552f686e
JH
66endif()
67
506523c1 68#===============================================================================
f2f536aa
GS
69#= Documentation
70#-------------------------------------------------------------------------------
71
72add_subdirectory(manual)
73
74#===============================================================================
30588653
AG
75#= Dependencies
76#-------------------------------------------------------------------------------
77
723ac3f8 78include(CheckCSourceCompiles)
c303f96d 79include(CheckCXXCompilerFlag)
723ac3f8
GS
80include(CheckCXXSourceCompiles)
81include(CMakePushCheckState)
82include(memaccess)
83
84find_package(PkgConfig)
85
a9bead72 86if(CMAKE_VERSION VERSION_EQUAL "3.8.0" OR CMAKE_VERSION VERSION_GREATER "3.8.0")
cb40d40c
SA
87 check_cxx_compiler_flag("-std=c++17" HAVE_STD_CXX_17)
88 check_cxx_compiler_flag("-std=c++14" HAVE_STD_CXX_14)
89 check_cxx_compiler_flag("-std=c++11" HAVE_STD_CXX_11)
90 if(HAVE_STD_CXX_17)
91 message(STATUS "Using C++17 for the application build")
92 set(CMAKE_CXX_STANDARD 17)
93 set(REQUIRED_STD_CXX_FLAGS "-std=c++17")
94 elseif(HAVE_STD_CXX_14)
95 message(STATUS "Using C++14 for the application build")
96 set(CMAKE_CXX_STANDARD 14)
97 set(REQUIRED_STD_CXX_FLAGS "-std=c++14")
98 elseif(HAVE_STD_CXX_11)
99 message(STATUS "Using C++11 for the application build")
100 set(CMAKE_CXX_STANDARD 11)
101 set(REQUIRED_STD_CXX_FLAGS "-std=c++11")
102 else()
103 message(FATAL_ERROR "Need modern C++, at least language standard 11")
104 endif()
fa8d0fcb 105else()
cb40d40c
SA
106 check_cxx_compiler_flag("-std=c++14" HAVE_STD_CXX_14)
107 check_cxx_compiler_flag("-std=c++11" HAVE_STD_CXX_11)
108 if(HAVE_STD_CXX_14)
109 message(STATUS "Using C++14 for the application build")
110 set(CMAKE_CXX_STANDARD 14)
111 set(REQUIRED_STD_CXX_FLAGS "-std=c++14")
112 elseif(HAVE_STD_CXX_11)
113 message(STATUS "Using C++11 for the application build")
114 set(CMAKE_CXX_STANDARD 11)
115 set(REQUIRED_STD_CXX_FLAGS "-std=c++11")
116 else()
117 message(FATAL_ERROR "Need modern C++, at least language standard 11")
118 endif()
fa8d0fcb 119endif()
c303f96d 120
e1e2666e 121list(APPEND PKGDEPS glib-2.0>=2.28.0)
33c5ac28
VPP
122
123# Try to find the prefered glibmm-2.4. If not found then add glibmm-2.68
124# to the dependency list.
e0a90b4c 125pkg_check_modules(GLIBMM_2_4 glibmm-2.4>=2.28.0)
33c5ac28
VPP
126if(GLIBMM_2_4_FOUND)
127 list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
128else()
129 list(APPEND PKGDEPS glibmm-2.68>=2.68.0)
130endif()
5252f438 131
696c7eac 132if(ENABLE_FLOW)
5252f438 133 list(APPEND PKGDEPS gstreamermm-1.0>=1.8.0)
045d8116 134 list(APPEND PKGDEPS libsigrokflow>=0.1.0)
5252f438 135endif()
d93ac5e8 136
1db57c03 137set(LIBSR_CXX_BINDING "libsigrokcxx>=0.5.2")
844c4619 138list(APPEND PKGDEPS "${LIBSR_CXX_BINDING}")
df944399 139
269528f5 140if(ENABLE_DECODE)
a2d1e7a8 141 list(APPEND PKGDEPS libsigrokdecode>=0.5.2)
269528f5
JH
142endif()
143
aff51746
MC
144if(ANDROID)
145 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
146endif()
147
7bcd627e 148pkg_check_modules(LIBSRCXX ${LIBSR_CXX_BINDING})
844c4619
GS
149if(NOT LIBSRCXX_FOUND OR NOT LIBSRCXX_VERSION)
150 message(FATAL_ERROR "libsigrok C++ bindings missing, check libsigrok's 'configure' output (missing dependencies?)")
151endif()
d52d8455
JH
152pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
153
e222f01e 154set(CMAKE_AUTOMOC TRUE)
e222f01e 155
136995b8
VPP
156# Check for Qt5, and check for Qt6 if Qt5 is not found.
157set(QT_COMPONENTS Core Gui LinguistTools Widgets Svg)
158find_package(Qt5 5.3 QUIET COMPONENTS Core)
159if(Qt5_FOUND)
160 find_package(Qt5 5.3 COMPONENTS ${QT_COMPONENTS} REQUIRED)
161 message(STATUS "Qt version: ${Qt5_VERSION}")
162else()
163 find_package(Qt6 6.2 COMPONENTS ${QT_COMPONENTS} REQUIRED)
164 message(STATUS "Qt version: ${Qt6_VERSION}")
165endif()
e08e8cc8 166
09f55d96 167if(WIN32)
136995b8 168 # MXE workaround: Use pkg-config to find Qt5 and Qt6 libs.
09f55d96 169 # https://github.com/mxe/mxe/issues/1642
929b9b19
UH
170 # Not required (and doesn't work) on MSYS2.
171 if(NOT DEFINED ENV{MSYSTEM})
136995b8
VPP
172 if(Qt5_FOUND)
173 pkg_check_modules(QT5ALL REQUIRED Qt5Widgets>=5.3 Qt5Gui>=5.3 Qt5Svg>=5.3)
174 else()
175 pkg_check_modules(QT6ALL REQUIRED Qt6Widgets>=6.2 Qt6Gui>=6.2 Qt6Svg>=6.2)
176 endif()
929b9b19 177 endif()
09f55d96 178endif()
9e8e84fc 179
136995b8
VPP
180if(Qt5_FOUND)
181 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
182else()
183 set(QT_LIBRARIES Qt6::Gui Qt6::Widgets Qt6::Svg)
184endif()
2e2946fe 185
b8f1cdeb 186set(BOOSTCOMPS filesystem serialization system)
226a1527 187if(ENABLE_TESTS)
d68d75c2 188 list(APPEND BOOSTCOMPS unit_test_framework)
2a21747e 189endif()
c1a688de
SA
190
191if(ENABLE_STACKTRACE)
b409dfdc
WS
192 include(FindBacktrace)
193 if (Backtrace_FOUND)
194 set(_Boost_STACKTRACE_BACKTRACE_HEADERS "boost/stacktrace.hpp")
195 list(APPEND BOOSTCOMPS stacktrace_backtrace)
196 else()
197 set(_Boost_STACKTRACE_BASIC_HEADERS "boost/stacktrace.hpp")
198 list(APPEND BOOSTCOMPS stacktrace_basic)
199 endif()
c1a688de
SA
200 find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
201else()
202 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
203endif()
df944399 204
858ae630
UH
205# Find the platform's thread library (needed for C++11 threads).
206# This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
2b76309a
AJ
207find_package(Threads REQUIRED)
208
4da54b6b
SM
209# Check for explicit link against libatomic
210#
211# Depending on the toolchain, linking a program using atomic functions may need
212# "-latomic" explicitly passed to the linker
213#
214# This check first tests if atomics are available in the C-library, if not and
215# libatomic exists, then it runs the same test with -latomic added to the
216# linker flags.
217
218# Helper for checking for atomics
219function(check_working_cxx_atomics varname additional_lib)
d56edfc6 220 cmake_push_check_state()
fa8d0fcb 221 set(CMAKE_REQUIRED_FLAGS "${REQUIRED_STD_CXX_FLAGS}")
d56edfc6
VPP
222 set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
223 set(CMAKE_REQUIRED_QUIET 1)
224 CHECK_CXX_SOURCE_COMPILES("
4da54b6b
SM
225#include <atomic>
226std::atomic<int> x;
227int main() {
d56edfc6 228 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
4da54b6b
SM
229}
230" ${varname})
d56edfc6 231 cmake_pop_check_state()
4da54b6b
SM
232endfunction(check_working_cxx_atomics)
233
234# First check if atomics work without the library.
235# If not, check if the library exists, and atomics work with it.
236check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
237if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
d56edfc6 238 message(STATUS "Atomics provided by the C-library - yes")
4da54b6b 239else()
d56edfc6
VPP
240 message(STATUS "Atomics provided by the C-library - no")
241 find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
242 if(LIBATOMIC_LIBRARY)
243 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
244 if (HAVE_CXX_ATOMICS_WITH_LIB)
245 message(STATUS "Atomics provided by libatomic - yes")
246 else()
247 message(STATUS "Atomics provided by libatomic - no")
248 message(FATAL_ERROR "Compiler must support std::atomic!")
249 endif()
250 else()
251 message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
252 endif()
4da54b6b
SM
253endif()
254
fe94bf82
GS
255# Check availability of features which depend on library versions.
256# TODO Ideally use check_symbol_exists() instead, reduce boilerplate.
257if(ENABLE_DECODE)
fe94bf82
GS
258 cmake_push_check_state()
259 set(CMAKE_REQUIRED_INCLUDES "${PKGDEPS_INCLUDE_DIRS}")
260 set(CMAKE_REQUIRED_LIBRARIES "sigrokdecode")
261 foreach (LPATH ${PKGDEPS_LIBRARY_DIRS})
262 list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "-L${LPATH}")
263 endforeach ()
264 check_c_source_compiles("
265 #include <libsigrokdecode/libsigrokdecode.h>
266 int main(int argc, char *argv[])
267 {
268 (void)argc;
269 (void)argv;
270 return srd_session_send_eof(NULL);
271 }
272 " HAVE_SRD_SESSION_SEND_EOF)
273 cmake_pop_check_state()
274endif()
275
9df8453f
MC
276#===============================================================================
277#= System Introspection
278#-------------------------------------------------------------------------------
279
9df8453f
MC
280memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
281
075fb499
AG
282#===============================================================================
283#= Config Header
284#-------------------------------------------------------------------------------
285
f7951df4 286set(PV_TITLE PulseView)
e2649143 287set(PV_VERSION_STRING "0.5.0")
f7951df4 288
33c5ac28
VPP
289if(GLIBMM_2_4_FOUND)
290 set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
291else()
292 set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.68_VERSION})
293endif()
d93ac5e8 294
1e8c82e9 295include(GetGitRevisionDescription)
1e8c82e9 296
812c0e35
DE
297# Append the revision hash unless we are exactly on a tagged release.
298git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
299if(NOT PV_TAG_VERSION_STRING)
300 get_git_head_revision(PV_REVSPEC PV_HASH)
301 if(PV_HASH)
302 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
303 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
d69b3c31 304 endif()
a53b8efe
SA
305
306 # Non-tagged releases use the unstable manual
307 set(PV_MANUAL_VERSION "unstable")
308else()
309 # Tagged releases use a fixed manual version
310 set(PV_MANUAL_VERSION ${PV_VERSION_STRING})
d69b3c31
DE
311endif()
312
313if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
1e8c82e9
DE
314 set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
315 set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
316 set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
317 set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
1e8c82e9
DE
318endif()
319
1e3a52e3 320message(STATUS "${PV_TITLE} version: ${PV_VERSION_STRING}")
075fb499
AG
321
322configure_file (
323 ${PROJECT_SOURCE_DIR}/config.h.in
324 ${PROJECT_BINARY_DIR}/config.h
325)
df944399 326
30588653
AG
327#===============================================================================
328#= Sources
329#-------------------------------------------------------------------------------
330
a8d3fb2d 331set(pulseview_SOURCES
df944399 332 main.cpp
dac1bb97 333 pv/application.cpp
107ca6d3 334 pv/devicemanager.cpp
bf9f1268 335 pv/globalsettings.cpp
bcb4c327 336 pv/logging.cpp
51e77110 337 pv/mainwindow.cpp
f2739bae 338 pv/metadata_obj.cpp
f65cd27b 339 pv/session.cpp
0fbda3c2 340 pv/storesession.cpp
f0c9f81c 341 pv/util.cpp
61703a01 342 pv/binding/binding.cpp
0c913637 343 pv/binding/inputoutput.cpp
3cc9ad7b 344 pv/binding/device.cpp
1b1ec774 345 pv/data/analog.cpp
f3d66e52 346 pv/data/analogsegment.cpp
1b1ec774 347 pv/data/logic.cpp
f3d66e52 348 pv/data/logicsegment.cpp
b0773a8a 349 pv/data/mathsignal.cpp
bf0edd2b 350 pv/data/signalbase.cpp
1b1ec774 351 pv/data/signaldata.cpp
f3d66e52 352 pv/data/segment.cpp
da30ecb7 353 pv/devices/device.cpp
474e817a 354 pv/devices/file.cpp
da30ecb7 355 pv/devices/hardwaredevice.cpp
5237f0c5 356 pv/devices/inputfile.cpp
da30ecb7 357 pv/devices/sessionfile.cpp
9663c82b 358 pv/dialogs/connect.cpp
e93f5538 359 pv/dialogs/inputoutputoptions.cpp
bf9f1268 360 pv/dialogs/settings.cpp
0fbda3c2 361 pv/dialogs/storeprogress.cpp
51d4a9ab 362 pv/popups/deviceoptions.cpp
6ac6242b 363 pv/popups/channels.cpp
de1d99bb 364 pv/prop/bool.cpp
b912c99c 365 pv/prop/double.cpp
820c3dea 366 pv/prop/enum.cpp
a2b92157 367 pv/prop/int.cpp
c8df6005 368 pv/prop/property.cpp
7112a458 369 pv/prop/string.cpp
97378470 370 pv/subwindows/subwindowbase.cpp
7c657094 371 pv/toolbars/mainbar.cpp
1573bf16
SA
372 pv/views/trace/analogsignal.cpp
373 pv/views/trace/cursor.cpp
374 pv/views/trace/cursorpair.cpp
375 pv/views/trace/flag.cpp
376 pv/views/trace/header.cpp
4640a84e 377 pv/views/trace/mathsignal.cpp
1573bf16
SA
378 pv/views/trace/marginwidget.cpp
379 pv/views/trace/logicsignal.cpp
1573bf16
SA
380 pv/views/trace/ruler.cpp
381 pv/views/trace/signal.cpp
1573bf16
SA
382 pv/views/trace/timeitem.cpp
383 pv/views/trace/timemarker.cpp
384 pv/views/trace/trace.cpp
385 pv/views/trace/tracegroup.cpp
386 pv/views/trace/tracepalette.cpp
387 pv/views/trace/tracetreeitem.cpp
388 pv/views/trace/tracetreeitemowner.cpp
389 pv/views/trace/triggermarker.cpp
390 pv/views/trace/view.cpp
391 pv/views/trace/viewitem.cpp
392 pv/views/trace/viewitemowner.cpp
393 pv/views/trace/viewitempaintparams.cpp
394 pv/views/trace/viewport.cpp
395 pv/views/trace/viewwidget.cpp
f4e57597 396 pv/views/viewbase.cpp
e0ba4f6f 397 pv/views/trace/standardbar.cpp
641574bc
SA
398 pv/widgets/colorbutton.cpp
399 pv/widgets/colorpopup.cpp
079d39ea 400 pv/widgets/devicetoolbutton.cpp
ce6001b8 401 pv/widgets/exportmenu.cpp
adf9e022 402 pv/widgets/flowlayout.cpp
56b6fc88 403 pv/widgets/importmenu.cpp
6e3f046e 404 pv/widgets/popup.cpp
6a91973f 405 pv/widgets/popuptoolbutton.cpp
1198b887 406 pv/widgets/sweeptimingwidget.cpp
806d3e1e 407 pv/widgets/timestampspinbox.cpp
0c0e1888 408 pv/widgets/wellarray.cpp
df944399
JH
409)
410
0aad432c 411# This list includes only QObject derived class headers.
a8d3fb2d 412set(pulseview_HEADERS
4640a84e 413 pv/exprtk.hpp
bcb4c327 414 pv/logging.hpp
bf9f1268 415 pv/globalsettings.hpp
2acdb232 416 pv/mainwindow.hpp
f2739bae 417 pv/metadata_obj.hpp
f65cd27b 418 pv/session.hpp
2acdb232 419 pv/storesession.hpp
3cc9ad7b 420 pv/binding/device.hpp
7db61e77
SA
421 pv/data/analog.hpp
422 pv/data/analogsegment.hpp
423 pv/data/logic.hpp
424 pv/data/logicsegment.hpp
b0773a8a 425 pv/data/mathsignal.hpp
bf0edd2b 426 pv/data/signalbase.hpp
2acdb232 427 pv/dialogs/connect.hpp
e93f5538 428 pv/dialogs/inputoutputoptions.hpp
bf9f1268 429 pv/dialogs/settings.hpp
2acdb232
JH
430 pv/dialogs/storeprogress.hpp
431 pv/popups/channels.hpp
432 pv/popups/deviceoptions.hpp
433 pv/prop/bool.hpp
434 pv/prop/double.hpp
435 pv/prop/enum.hpp
436 pv/prop/int.hpp
437 pv/prop/property.hpp
438 pv/prop/string.hpp
97378470 439 pv/subwindows/subwindowbase.hpp
7c657094 440 pv/toolbars/mainbar.hpp
1573bf16
SA
441 pv/views/trace/analogsignal.hpp
442 pv/views/trace/cursor.hpp
443 pv/views/trace/flag.hpp
444 pv/views/trace/header.hpp
445 pv/views/trace/logicsignal.hpp
4640a84e 446 pv/views/trace/mathsignal.hpp
1573bf16 447 pv/views/trace/marginwidget.hpp
1573bf16
SA
448 pv/views/trace/ruler.hpp
449 pv/views/trace/signal.hpp
1573bf16
SA
450 pv/views/trace/timeitem.hpp
451 pv/views/trace/timemarker.hpp
452 pv/views/trace/trace.hpp
453 pv/views/trace/tracegroup.hpp
454 pv/views/trace/tracetreeitem.hpp
455 pv/views/trace/triggermarker.hpp
456 pv/views/trace/view.hpp
457 pv/views/trace/viewitem.hpp
458 pv/views/trace/viewport.hpp
459 pv/views/trace/viewwidget.hpp
f4e57597 460 pv/views/viewbase.hpp
e0ba4f6f 461 pv/views/trace/standardbar.hpp
641574bc
SA
462 pv/widgets/colorbutton.hpp
463 pv/widgets/colorpopup.hpp
079d39ea 464 pv/widgets/devicetoolbutton.hpp
ce6001b8 465 pv/widgets/exportmenu.hpp
adf9e022 466 pv/widgets/flowlayout.hpp
56b6fc88 467 pv/widgets/importmenu.hpp
2acdb232
JH
468 pv/widgets/popup.hpp
469 pv/widgets/popuptoolbutton.hpp
470 pv/widgets/sweeptimingwidget.hpp
806d3e1e 471 pv/widgets/timestampspinbox.hpp
2acdb232 472 pv/widgets/wellarray.hpp
df944399
JH
473)
474
8b9056d4
UH
475set(pulseview_RESOURCES
476 pulseview.qrc
477)
478
140181a4
JH
479if(ENABLE_SIGNALS)
480 list(APPEND pulseview_SOURCES signalhandler.cpp)
2acdb232 481 list(APPEND pulseview_HEADERS signalhandler.hpp)
140181a4
JH
482endif()
483
269528f5
JH
484if(ENABLE_DECODE)
485 list(APPEND pulseview_SOURCES
3cc9ad7b 486 pv/binding/decoder.cpp
ad908057 487 pv/data/decodesignal.cpp
269528f5
JH
488 pv/data/decode/annotation.cpp
489 pv/data/decode/decoder.cpp
f9101a91
JH
490 pv/data/decode/row.cpp
491 pv/data/decode/rowdata.cpp
97378470
SA
492 pv/subwindows/decoder_selector/item.cpp
493 pv/subwindows/decoder_selector/model.cpp
494 pv/subwindows/decoder_selector/subwindow.cpp
121307b3
SA
495 pv/views/decoder_binary/view.cpp
496 pv/views/decoder_binary/QHexView.cpp
24d69d27
SA
497 pv/views/tabular_decoder/model.cpp
498 pv/views/tabular_decoder/view.cpp
1573bf16 499 pv/views/trace/decodetrace.cpp
269528f5
JH
500 pv/widgets/decodergroupbox.cpp
501 pv/widgets/decodermenu.cpp
269528f5
JH
502 )
503
504 list(APPEND pulseview_HEADERS
ad908057 505 pv/data/decodesignal.hpp
97378470 506 pv/subwindows/decoder_selector/subwindow.hpp
121307b3
SA
507 pv/views/decoder_binary/view.hpp
508 pv/views/decoder_binary/QHexView.hpp
24d69d27 509 pv/views/tabular_decoder/view.hpp
1573bf16 510 pv/views/trace/decodetrace.hpp
2acdb232
JH
511 pv/widgets/decodergroupbox.hpp
512 pv/widgets/decodermenu.hpp
269528f5
JH
513 )
514endif()
515
fe15e0bc
UH
516if(WIN32)
517 # Use the sigrok icon for the pulseview.exe executable.
518 set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
519 enable_language(RC)
61e1e13e 520 list(APPEND pulseview_SOURCES pulseviewico.rc)
fe15e0bc
UH
521endif()
522
9137928c 523if(ANDROID)
dddff2e7
DE
524 list(APPEND pulseview_SOURCES
525 android/assetreader.cpp
526 android/loghandler.cpp
527 )
9137928c
MC
528endif()
529
136995b8
VPP
530if(Qt5_FOUND)
531 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
532else()
533 qt6_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
534endif()
8b9056d4 535
0466001b
SA
536#===============================================================================
537#= Translations
538#-------------------------------------------------------------------------------
539
c3660d7d
SA
540file(GLOB TS_FILES ${CMAKE_SOURCE_DIR}/l10n/*.ts)
541set_property(SOURCE ${TS_FILES} PROPERTY OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/l10n)
989d50ad 542if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
543 configure_file("translations.qrc" "translations.qrc" COPYONLY)
544endif ()
0466001b 545
136995b8
VPP
546if(Qt5_FOUND)
547 qt5_add_translation(QM_FILES ${TS_FILES})
136995b8 548 qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
3903edbd
GS
549 if (ENABLE_TS_UPDATE)
550 qt5_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
551 endif ()
136995b8
VPP
552else()
553 qt6_add_translation(QM_FILES ${TS_FILES})
136995b8 554 qt6_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
3903edbd
GS
555 if (ENABLE_TS_UPDATE)
556 qt6_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
557 endif ()
136995b8 558endif()
0466001b 559
30588653
AG
560#===============================================================================
561#= Global Definitions
562#-------------------------------------------------------------------------------
563
e222f01e 564add_definitions(-DQT_NO_KEYWORDS)
ac223c1e 565add_definitions(-D__STDC_LIMIT_MACROS)
a9974171 566add_definitions(-Wall -Wextra)
fa8d0fcb 567add_definitions(${REQUIRED_STD_CXX_FLAGS})
c303f96d 568
a838ed7b 569add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
d8cdab78
UH
570if(WIN32)
571 add_definitions(-Wa,-mbig-obj -O3)
572endif()
5f606159 573
696c7eac
UH
574if(ENABLE_FLOW)
575 add_definitions(-DENABLE_FLOW)
5252f438
UH
576endif()
577
269528f5
JH
578if(ENABLE_DECODE)
579 add_definitions(-DENABLE_DECODE)
580endif()
581
5f606159
JH
582if(NOT DISABLE_WERROR)
583 add_definitions(-Werror)
584endif()
df944399 585
9632990d
UH
586if(ENABLE_SIGNALS)
587 add_definitions(-DENABLE_SIGNALS)
588endif()
589
c1a688de 590if(ENABLE_STACKTRACE)
b409dfdc
WS
591 add_definitions(-DENABLE_STACKTRACE -no-pie -fno-pie)
592 if (Backtrace_FOUND)
593 add_definitions(-DBOOST_STACKTRACE_USE_BACKTRACE)
594 endif()
c1a688de
SA
595endif()
596
30588653
AG
597#===============================================================================
598#= Global Include Directories
599#-------------------------------------------------------------------------------
600
b04e278d
AG
601include_directories(
602 ${CMAKE_CURRENT_BINARY_DIR}
cef18fc6 603 ${CMAKE_CURRENT_SOURCE_DIR}
b04e278d
AG
604 ${Boost_INCLUDE_DIRS}
605)
606
607if(STATIC_PKGDEPS_LIBS)
608 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
609else()
610 include_directories(${PKGDEPS_INCLUDE_DIRS})
611endif()
df944399 612
30588653
AG
613#===============================================================================
614#= Linker Configuration
615#-------------------------------------------------------------------------------
616
b04e278d
AG
617link_directories(${Boost_LIBRARY_DIRS})
618
619set(PULSEVIEW_LINK_LIBS
620 ${Boost_LIBRARIES}
621 ${QT_LIBRARIES}
2b76309a 622 ${CMAKE_THREAD_LIBS_INIT}
4da54b6b 623 ${LIBATOMIC_LIBRARY}
b04e278d
AG
624)
625
626if(STATIC_PKGDEPS_LIBS)
cddf172d 627 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
09f55d96 628 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
b04e278d 629else()
cddf172d
UH
630 link_directories(${PKGDEPS_LIBRARY_DIRS})
631 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
b04e278d 632endif()
df944399 633
11a04e2a
UH
634if(WIN32)
635 # On Windows we need to statically link the libqsvg imageformat
636 # plugin (and the QtSvg component) for SVG graphics/icons to work.
356fb5c0
UH
637 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport (only for
638 # Qt < 5.8.0), and all Qt libs and their dependencies.
11a04e2a 639 add_definitions(-DQT_STATICPLUGIN)
136995b8
VPP
640 if(Qt5_FOUND)
641 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
642 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
643 if(Qt5Gui_VERSION VERSION_LESS 5.8.0)
644 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport)
645 endif()
646 list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
647 else()
648 list(APPEND PULSEVIEW_LINK_LIBS Qt6::QSvgPlugin)
649 list(APPEND PULSEVIEW_LINK_LIBS Qt6::QWindowsIntegrationPlugin)
650 list(APPEND PULSEVIEW_LINK_LIBS ${QT6ALL_LDFLAGS})
356fb5c0 651 endif()
11a04e2a
UH
652endif()
653
c1a688de 654if(ENABLE_STACKTRACE)
b409dfdc
WS
655 list(APPEND PULSEVIEW_LINK_LIBS ${CMAKE_DL_LIBS} ${Backtrace_LIBRARIES})
656 link_libraries("-no-pie -fno-pie")
c1a688de
SA
657endif()
658
9137928c
MC
659if(ANDROID)
660 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
661endif()
662
c243364c 663set(INPUT_FILES_LIST ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC} ${QM_FILES})
26807061 664if(ANDROID)
c243364c 665 add_library(${PROJECT_NAME} SHARED ${INPUT_FILES_LIST})
26807061 666else()
c243364c 667 add_executable(${PROJECT_NAME} ${INPUT_FILES_LIST})
26807061 668endif()
df944399 669
5a13850b 670target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
f0fa92c6 671
b732b48f 672if(WIN32 AND NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
61e1e13e
UH
673 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
674 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
b0d8c0dc
UH
675endif()
676
30588653
AG
677#===============================================================================
678#= Installation
679#-------------------------------------------------------------------------------
680
52bbe600 681# Install the executable.
cd6606c2
AG
682install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
683
52bbe600
UH
684# Install the manpage.
685install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
686
96e282c4
UH
687# Install the desktop file.
688install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
689
22fc985b
UH
690# Install the AppData/AppStream file.
691install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
692
09594425
UH
693# Install the PulseView icons.
694install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
695install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
696
f9cb49cc 697# Generate Windows installer script.
baef263a 698configure_file(contrib/pulseview_cross.nsi.in ${CMAKE_CURRENT_BINARY_DIR}/contrib/pulseview_cross.nsi @ONLY)
f9cb49cc 699
cd6606c2
AG
700#===============================================================================
701#= Packaging (handled by CPack)
702#-------------------------------------------------------------------------------
703
b02a8cbf
JH
704set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
705set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
706set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
cd6606c2
AG
707set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
708set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
709set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
1e8c82e9 710set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
1d2fb87d 711set(CPACK_SOURCE_GENERATOR "TGZ")
cd6606c2
AG
712
713include(CPack)
bc1c1462 714
30588653
AG
715#===============================================================================
716#= Tests
717#-------------------------------------------------------------------------------
718
77e8ac52 719if(ENABLE_TESTS)
fb746bcc 720 add_subdirectory(test)
951c583c 721 enable_testing()
fb746bcc 722 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
0aad432c 723endif()