]> sigrok.org Git - pulseview.git/blame_incremental - CMakeLists.txt
Session: Fix issue #67 by improving error handling
[pulseview.git] / CMakeLists.txt
... / ...
CommitLineData
1##
2## This file is part of the PulseView project.
3##
4## Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5## Copyright (C) 2012-2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
6## Copyright (C) 2020 Soeren Apel <soeren@apelpie.net>
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
22cmake_minimum_required(VERSION 2.8.12)
23
24project(pulseview C CXX)
25
26include(GNUInstallDirs)
27
28# Let AUTOMOC and AUTOUIC process GENERATED files.
29if(POLICY CMP0071)
30 cmake_policy(SET CMP0071 NEW)
31endif()
32
33# Only interpret if() arguments as variables or keywords when unquoted.
34if(POLICY CMP0054)
35 cmake_policy(SET CMP0054 NEW)
36endif()
37
38list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
39
40#===============================================================================
41#= User Options
42#-------------------------------------------------------------------------------
43
44option(DISABLE_WERROR "Build without -Werror" TRUE)
45option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
46option(ENABLE_STACKTRACE "Enable stack trace when crashing" FALSE)
47option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
48option(ENABLE_FLOW "Build with libsigrokflow" FALSE)
49option(ENABLE_TESTS "Enable unit tests" FALSE)
50option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
51option(ENABLE_TS_UPDATE "Update .ts source files (Qt l10n)" FALSE)
52
53if(WIN32)
54 # On Windows/MinGW we need to statically link to libraries.
55 # This option is user configurable, but enable it by default on win32.
56 set(STATIC_PKGDEPS_LIBS TRUE)
57
58 # Windows does not support UNIX signals.
59 set(ENABLE_SIGNALS FALSE)
60endif()
61
62if(NOT CMAKE_BUILD_TYPE)
63 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
64 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
65 FORCE)
66endif()
67
68#===============================================================================
69#= Documentation
70#-------------------------------------------------------------------------------
71
72add_subdirectory(manual)
73
74#===============================================================================
75#= Dependencies
76#-------------------------------------------------------------------------------
77
78include(CheckCSourceCompiles)
79include(CheckCXXCompilerFlag)
80include(CheckCXXSourceCompiles)
81include(CMakePushCheckState)
82include(memaccess)
83
84find_package(PkgConfig)
85
86if(CMAKE_VERSION VERSION_EQUAL "3.8.0" OR CMAKE_VERSION VERSION_GREATER "3.8.0")
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()
105else()
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()
119endif()
120
121list(APPEND PKGDEPS glib-2.0>=2.28.0)
122
123# Try to find the prefered glibmm-2.4. If not found then add glibmm-2.68
124# to the dependency list.
125pkg_check_modules(GLIBMM_2_4 glibmm-2.4>=2.28.0)
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()
131
132if(ENABLE_FLOW)
133 list(APPEND PKGDEPS gstreamermm-1.0>=1.8.0)
134 list(APPEND PKGDEPS libsigrokflow>=0.1.0)
135endif()
136
137set(LIBSR_CXX_BINDING "libsigrokcxx>=0.5.2")
138list(APPEND PKGDEPS "${LIBSR_CXX_BINDING}")
139
140if(ENABLE_DECODE)
141 list(APPEND PKGDEPS libsigrokdecode>=0.5.2)
142endif()
143
144if(ANDROID)
145 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
146endif()
147
148pkg_check_modules(LIBSRCXX ${LIBSR_CXX_BINDING})
149if(NOT LIBSRCXX_FOUND OR NOT LIBSRCXX_VERSION)
150 message(FATAL_ERROR "libsigrok C++ bindings missing, check libsigrok's 'configure' output (missing dependencies?)")
151endif()
152pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
153
154set(CMAKE_AUTOMOC TRUE)
155
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()
166
167if(WIN32)
168 # MXE workaround: Use pkg-config to find Qt5 and Qt6 libs.
169 # https://github.com/mxe/mxe/issues/1642
170 # Not required (and doesn't work) on MSYS2.
171 if(NOT DEFINED ENV{MSYSTEM})
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()
177 endif()
178endif()
179
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()
185
186set(BOOSTCOMPS filesystem serialization system)
187if(ENABLE_TESTS)
188 list(APPEND BOOSTCOMPS unit_test_framework)
189endif()
190
191if(ENABLE_STACKTRACE)
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()
200 find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
201else()
202 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
203endif()
204
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.
207find_package(Threads REQUIRED)
208
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)
220 cmake_push_check_state()
221 set(CMAKE_REQUIRED_FLAGS "${REQUIRED_STD_CXX_FLAGS}")
222 set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
223 set(CMAKE_REQUIRED_QUIET 1)
224 CHECK_CXX_SOURCE_COMPILES("
225#include <atomic>
226std::atomic<int> x;
227int main() {
228 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
229}
230" ${varname})
231 cmake_pop_check_state()
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)
238 message(STATUS "Atomics provided by the C-library - yes")
239else()
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()
253endif()
254
255# Check availability of features which depend on library versions.
256# TODO Ideally use check_symbol_exists() instead, reduce boilerplate.
257if(ENABLE_DECODE)
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
276#===============================================================================
277#= System Introspection
278#-------------------------------------------------------------------------------
279
280memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
281
282#===============================================================================
283#= Config Header
284#-------------------------------------------------------------------------------
285
286set(PV_TITLE PulseView)
287set(PV_VERSION_STRING "0.5.0")
288
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()
294
295include(GetGitRevisionDescription)
296
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}")
304 endif()
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})
311endif()
312
313if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
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})
318endif()
319
320message(STATUS "${PV_TITLE} version: ${PV_VERSION_STRING}")
321
322configure_file (
323 ${PROJECT_SOURCE_DIR}/config.h.in
324 ${PROJECT_BINARY_DIR}/config.h
325)
326
327#===============================================================================
328#= Sources
329#-------------------------------------------------------------------------------
330
331set(pulseview_SOURCES
332 main.cpp
333 pv/application.cpp
334 pv/devicemanager.cpp
335 pv/globalsettings.cpp
336 pv/logging.cpp
337 pv/mainwindow.cpp
338 pv/metadata_obj.cpp
339 pv/session.cpp
340 pv/storesession.cpp
341 pv/util.cpp
342 pv/binding/binding.cpp
343 pv/binding/inputoutput.cpp
344 pv/binding/device.cpp
345 pv/data/analog.cpp
346 pv/data/analogsegment.cpp
347 pv/data/logic.cpp
348 pv/data/logicsegment.cpp
349 pv/data/mathsignal.cpp
350 pv/data/signalbase.cpp
351 pv/data/signaldata.cpp
352 pv/data/segment.cpp
353 pv/devices/device.cpp
354 pv/devices/file.cpp
355 pv/devices/hardwaredevice.cpp
356 pv/devices/inputfile.cpp
357 pv/devices/sessionfile.cpp
358 pv/dialogs/connect.cpp
359 pv/dialogs/inputoutputoptions.cpp
360 pv/dialogs/settings.cpp
361 pv/dialogs/storeprogress.cpp
362 pv/popups/deviceoptions.cpp
363 pv/popups/channels.cpp
364 pv/prop/bool.cpp
365 pv/prop/double.cpp
366 pv/prop/enum.cpp
367 pv/prop/int.cpp
368 pv/prop/property.cpp
369 pv/prop/string.cpp
370 pv/subwindows/subwindowbase.cpp
371 pv/toolbars/mainbar.cpp
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
377 pv/views/trace/mathsignal.cpp
378 pv/views/trace/marginwidget.cpp
379 pv/views/trace/logicsignal.cpp
380 pv/views/trace/ruler.cpp
381 pv/views/trace/signal.cpp
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
396 pv/views/viewbase.cpp
397 pv/views/trace/standardbar.cpp
398 pv/widgets/colorbutton.cpp
399 pv/widgets/colorpopup.cpp
400 pv/widgets/devicetoolbutton.cpp
401 pv/widgets/exportmenu.cpp
402 pv/widgets/flowlayout.cpp
403 pv/widgets/importmenu.cpp
404 pv/widgets/popup.cpp
405 pv/widgets/popuptoolbutton.cpp
406 pv/widgets/sweeptimingwidget.cpp
407 pv/widgets/timestampspinbox.cpp
408 pv/widgets/wellarray.cpp
409)
410
411# This list includes only QObject derived class headers.
412set(pulseview_HEADERS
413 pv/exprtk.hpp
414 pv/logging.hpp
415 pv/globalsettings.hpp
416 pv/mainwindow.hpp
417 pv/metadata_obj.hpp
418 pv/session.hpp
419 pv/storesession.hpp
420 pv/binding/device.hpp
421 pv/data/analog.hpp
422 pv/data/analogsegment.hpp
423 pv/data/logic.hpp
424 pv/data/logicsegment.hpp
425 pv/data/mathsignal.hpp
426 pv/data/signalbase.hpp
427 pv/dialogs/connect.hpp
428 pv/dialogs/inputoutputoptions.hpp
429 pv/dialogs/settings.hpp
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
439 pv/subwindows/subwindowbase.hpp
440 pv/toolbars/mainbar.hpp
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
446 pv/views/trace/mathsignal.hpp
447 pv/views/trace/marginwidget.hpp
448 pv/views/trace/ruler.hpp
449 pv/views/trace/signal.hpp
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
460 pv/views/viewbase.hpp
461 pv/views/trace/standardbar.hpp
462 pv/widgets/colorbutton.hpp
463 pv/widgets/colorpopup.hpp
464 pv/widgets/devicetoolbutton.hpp
465 pv/widgets/exportmenu.hpp
466 pv/widgets/flowlayout.hpp
467 pv/widgets/importmenu.hpp
468 pv/widgets/popup.hpp
469 pv/widgets/popuptoolbutton.hpp
470 pv/widgets/sweeptimingwidget.hpp
471 pv/widgets/timestampspinbox.hpp
472 pv/widgets/wellarray.hpp
473)
474
475set(pulseview_RESOURCES
476 pulseview.qrc
477)
478
479if(ENABLE_SIGNALS)
480 list(APPEND pulseview_SOURCES signalhandler.cpp)
481 list(APPEND pulseview_HEADERS signalhandler.hpp)
482endif()
483
484if(ENABLE_DECODE)
485 list(APPEND pulseview_SOURCES
486 pv/binding/decoder.cpp
487 pv/data/decodesignal.cpp
488 pv/data/decode/annotation.cpp
489 pv/data/decode/decoder.cpp
490 pv/data/decode/row.cpp
491 pv/data/decode/rowdata.cpp
492 pv/subwindows/decoder_selector/item.cpp
493 pv/subwindows/decoder_selector/model.cpp
494 pv/subwindows/decoder_selector/subwindow.cpp
495 pv/views/decoder_binary/view.cpp
496 pv/views/decoder_binary/QHexView.cpp
497 pv/views/tabular_decoder/model.cpp
498 pv/views/tabular_decoder/view.cpp
499 pv/views/trace/decodetrace.cpp
500 pv/widgets/decodergroupbox.cpp
501 pv/widgets/decodermenu.cpp
502 )
503
504 list(APPEND pulseview_HEADERS
505 pv/data/decodesignal.hpp
506 pv/subwindows/decoder_selector/subwindow.hpp
507 pv/views/decoder_binary/view.hpp
508 pv/views/decoder_binary/QHexView.hpp
509 pv/views/tabular_decoder/view.hpp
510 pv/views/trace/decodetrace.hpp
511 pv/widgets/decodergroupbox.hpp
512 pv/widgets/decodermenu.hpp
513 )
514endif()
515
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)
520 list(APPEND pulseview_SOURCES pulseviewico.rc)
521endif()
522
523if(ANDROID)
524 list(APPEND pulseview_SOURCES
525 android/assetreader.cpp
526 android/loghandler.cpp
527 )
528endif()
529
530if(Qt5_FOUND)
531 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
532else()
533 qt6_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
534endif()
535
536#===============================================================================
537#= Translations
538#-------------------------------------------------------------------------------
539
540file(GLOB TS_FILES ${CMAKE_SOURCE_DIR}/l10n/*.ts)
541set_property(SOURCE ${TS_FILES} PROPERTY OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/l10n)
542if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
543 configure_file("translations.qrc" "translations.qrc" COPYONLY)
544endif ()
545
546if(Qt5_FOUND)
547 qt5_add_translation(QM_FILES ${TS_FILES})
548 qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
549 if (ENABLE_TS_UPDATE)
550 qt5_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
551 endif ()
552else()
553 qt6_add_translation(QM_FILES ${TS_FILES})
554 qt6_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
555 if (ENABLE_TS_UPDATE)
556 qt6_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
557 endif ()
558endif()
559
560#===============================================================================
561#= Global Definitions
562#-------------------------------------------------------------------------------
563
564add_definitions(-DQT_NO_KEYWORDS)
565add_definitions(-D__STDC_LIMIT_MACROS)
566add_definitions(-Wall -Wextra)
567add_definitions(${REQUIRED_STD_CXX_FLAGS})
568
569add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
570if(WIN32)
571 add_definitions(-Wa,-mbig-obj -O3)
572endif()
573
574if(ENABLE_FLOW)
575 add_definitions(-DENABLE_FLOW)
576endif()
577
578if(ENABLE_DECODE)
579 add_definitions(-DENABLE_DECODE)
580endif()
581
582if(NOT DISABLE_WERROR)
583 add_definitions(-Werror)
584endif()
585
586if(ENABLE_SIGNALS)
587 add_definitions(-DENABLE_SIGNALS)
588endif()
589
590if(ENABLE_STACKTRACE)
591 add_definitions(-DENABLE_STACKTRACE -no-pie -fno-pie)
592 if (Backtrace_FOUND)
593 add_definitions(-DBOOST_STACKTRACE_USE_BACKTRACE)
594 endif()
595endif()
596
597#===============================================================================
598#= Global Include Directories
599#-------------------------------------------------------------------------------
600
601include_directories(
602 ${CMAKE_CURRENT_BINARY_DIR}
603 ${CMAKE_CURRENT_SOURCE_DIR}
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()
612
613#===============================================================================
614#= Linker Configuration
615#-------------------------------------------------------------------------------
616
617link_directories(${Boost_LIBRARY_DIRS})
618
619set(PULSEVIEW_LINK_LIBS
620 ${Boost_LIBRARIES}
621 ${QT_LIBRARIES}
622 ${CMAKE_THREAD_LIBS_INIT}
623 ${LIBATOMIC_LIBRARY}
624)
625
626if(STATIC_PKGDEPS_LIBS)
627 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
628 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
629else()
630 link_directories(${PKGDEPS_LIBRARY_DIRS})
631 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
632endif()
633
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.
637 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport (only for
638 # Qt < 5.8.0), and all Qt libs and their dependencies.
639 add_definitions(-DQT_STATICPLUGIN)
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})
651 endif()
652endif()
653
654if(ENABLE_STACKTRACE)
655 list(APPEND PULSEVIEW_LINK_LIBS ${CMAKE_DL_LIBS} ${Backtrace_LIBRARIES})
656 link_libraries("-no-pie -fno-pie")
657endif()
658
659if(ANDROID)
660 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
661endif()
662
663set(INPUT_FILES_LIST ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC} ${QM_FILES})
664if(ANDROID)
665 add_library(${PROJECT_NAME} SHARED ${INPUT_FILES_LIST})
666else()
667 add_executable(${PROJECT_NAME} ${INPUT_FILES_LIST})
668endif()
669
670target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
671
672if(WIN32 AND NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
673 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
674 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
675endif()
676
677#===============================================================================
678#= Installation
679#-------------------------------------------------------------------------------
680
681# Install the executable.
682install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
683
684# Install the manpage.
685install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
686
687# Install the desktop file.
688install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
689
690# Install the AppData/AppStream file.
691install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
692
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
697# Generate Windows installer script.
698configure_file(contrib/pulseview_cross.nsi.in ${CMAKE_CURRENT_BINARY_DIR}/contrib/pulseview_cross.nsi @ONLY)
699
700#===============================================================================
701#= Packaging (handled by CPack)
702#-------------------------------------------------------------------------------
703
704set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
705set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
706set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
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")
710set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
711set(CPACK_SOURCE_GENERATOR "TGZ")
712
713include(CPack)
714
715#===============================================================================
716#= Tests
717#-------------------------------------------------------------------------------
718
719if(ENABLE_TESTS)
720 add_subdirectory(test)
721 enable_testing()
722 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
723endif()