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