]> 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 option(ENABLE_TS_UPDATE "Update .ts source files (Qt l10n)" FALSE)
52
53 if(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)
60 endif()
61
62 if(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)
66 endif()
67
68 #===============================================================================
69 #= Documentation
70 #-------------------------------------------------------------------------------
71
72 add_subdirectory(manual)
73
74 #===============================================================================
75 #= Dependencies
76 #-------------------------------------------------------------------------------
77
78 include(CheckCSourceCompiles)
79 include(CheckCXXCompilerFlag)
80 include(CheckCXXSourceCompiles)
81 include(CMakePushCheckState)
82 include(memaccess)
83
84 find_package(PkgConfig)
85
86 if(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()
105 else()
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()
119 endif()
120
121 list(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.
125 pkg_check_modules(GLIBMM_2_4 glibmm-2.4>=2.28.0)
126 if(GLIBMM_2_4_FOUND)
127         list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
128 else()
129         list(APPEND PKGDEPS glibmm-2.68>=2.68.0)
130 endif()
131
132 if(ENABLE_FLOW)
133         list(APPEND PKGDEPS gstreamermm-1.0>=1.8.0)
134         list(APPEND PKGDEPS libsigrokflow>=0.1.0)
135 endif()
136
137 set(LIBSR_CXX_BINDING "libsigrokcxx>=0.5.2")
138 list(APPEND PKGDEPS "${LIBSR_CXX_BINDING}")
139
140 if(ENABLE_DECODE)
141         list(APPEND PKGDEPS libsigrokdecode>=0.5.2)
142 endif()
143
144 if(ANDROID)
145         list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
146 endif()
147
148 pkg_check_modules(LIBSRCXX ${LIBSR_CXX_BINDING})
149 if(NOT LIBSRCXX_FOUND OR NOT LIBSRCXX_VERSION)
150         message(FATAL_ERROR "libsigrok C++ bindings missing, check libsigrok's 'configure' output (missing dependencies?)")
151 endif()
152 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
153
154 set(CMAKE_AUTOMOC TRUE)
155
156 # Check for Qt5, and check for Qt6 if Qt5 is not found.
157 set(QT_COMPONENTS Core Gui LinguistTools Widgets Svg)
158 find_package(Qt5 5.3 QUIET COMPONENTS Core)
159 if(Qt5_FOUND)
160         find_package(Qt5 5.3 COMPONENTS ${QT_COMPONENTS} REQUIRED)
161         message(STATUS "Qt version: ${Qt5_VERSION}")
162 else()
163         find_package(Qt6 6.2 COMPONENTS ${QT_COMPONENTS} REQUIRED)
164         message(STATUS "Qt version: ${Qt6_VERSION}")
165 endif()
166
167 if(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()
178 endif()
179
180 if(Qt5_FOUND)
181         set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
182 else()
183         set(QT_LIBRARIES Qt6::Gui Qt6::Widgets Qt6::Svg)
184 endif()
185
186 set(BOOSTCOMPS filesystem serialization system)
187 if(ENABLE_TESTS)
188         list(APPEND BOOSTCOMPS unit_test_framework)
189 endif()
190
191 if(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)
201 else()
202         find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
203 endif()
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.
207 find_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
219 function(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>
226 std::atomic<int> x;
227 int main() {
228         return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
229 }
230 " ${varname})
231         cmake_pop_check_state()
232 endfunction(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.
236 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
237 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
238         message(STATUS "Atomics provided by the C-library - yes")
239 else()
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()
253 endif()
254
255 # Check availability of features which depend on library versions.
256 # TODO Ideally use check_symbol_exists() instead, reduce boilerplate.
257 if(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()
274 endif()
275
276 #===============================================================================
277 #= System Introspection
278 #-------------------------------------------------------------------------------
279
280 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
281
282 #===============================================================================
283 #= Config Header
284 #-------------------------------------------------------------------------------
285
286 set(PV_TITLE PulseView)
287 set(PV_VERSION_STRING "0.5.0")
288
289 if(GLIBMM_2_4_FOUND)
290         set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
291 else()
292         set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.68_VERSION})
293 endif()
294
295 include(GetGitRevisionDescription)
296
297 # Append the revision hash unless we are exactly on a tagged release.
298 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
299 if(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")
308 else()
309         # Tagged releases use a fixed manual version
310         set(PV_MANUAL_VERSION ${PV_VERSION_STRING})
311 endif()
312
313 if(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})
318 endif()
319
320 message(STATUS "${PV_TITLE} version: ${PV_VERSION_STRING}")
321
322 configure_file (
323         ${PROJECT_SOURCE_DIR}/config.h.in
324         ${PROJECT_BINARY_DIR}/config.h
325 )
326
327 #===============================================================================
328 #= Sources
329 #-------------------------------------------------------------------------------
330
331 set(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.
412 set(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
475 set(pulseview_RESOURCES
476         pulseview.qrc
477 )
478
479 if(ENABLE_SIGNALS)
480         list(APPEND pulseview_SOURCES signalhandler.cpp)
481         list(APPEND pulseview_HEADERS signalhandler.hpp)
482 endif()
483
484 if(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         )
514 endif()
515
516 if(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)
521 endif()
522
523 if(ANDROID)
524         list(APPEND pulseview_SOURCES
525                 android/assetreader.cpp
526                 android/loghandler.cpp
527         )
528 endif()
529
530 if(Qt5_FOUND)
531         qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
532 else()
533         qt6_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
534 endif()
535
536 #===============================================================================
537 #= Translations
538 #-------------------------------------------------------------------------------
539
540 file(GLOB TS_FILES ${CMAKE_SOURCE_DIR}/l10n/*.ts)
541 set_property(SOURCE ${TS_FILES} PROPERTY OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/l10n)
542 if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
543         configure_file("translations.qrc" "translations.qrc" COPYONLY)
544 endif ()
545
546 if(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 ()
552 else()
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 ()
558 endif()
559
560 #===============================================================================
561 #= Global Definitions
562 #-------------------------------------------------------------------------------
563
564 add_definitions(-DQT_NO_KEYWORDS)
565 add_definitions(-D__STDC_LIMIT_MACROS)
566 add_definitions(-Wall -Wextra)
567 add_definitions(${REQUIRED_STD_CXX_FLAGS})
568
569 add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
570 if(WIN32)
571         add_definitions(-Wa,-mbig-obj -O3)
572 endif()
573
574 if(ENABLE_FLOW)
575         add_definitions(-DENABLE_FLOW)
576 endif()
577
578 if(ENABLE_DECODE)
579         add_definitions(-DENABLE_DECODE)
580 endif()
581
582 if(NOT DISABLE_WERROR)
583         add_definitions(-Werror)
584 endif()
585
586 if(ENABLE_SIGNALS)
587         add_definitions(-DENABLE_SIGNALS)
588 endif()
589
590 if(ENABLE_STACKTRACE)
591         add_definitions(-DENABLE_STACKTRACE -no-pie -fno-pie)
592         if (Backtrace_FOUND)
593                 add_definitions(-DBOOST_STACKTRACE_USE_BACKTRACE)
594         endif()
595 endif()
596
597 #===============================================================================
598 #= Global Include Directories
599 #-------------------------------------------------------------------------------
600
601 include_directories(
602         ${CMAKE_CURRENT_BINARY_DIR}
603         ${CMAKE_CURRENT_SOURCE_DIR}
604         ${Boost_INCLUDE_DIRS}
605 )
606
607 if(STATIC_PKGDEPS_LIBS)
608         include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
609 else()
610         include_directories(${PKGDEPS_INCLUDE_DIRS})
611 endif()
612
613 #===============================================================================
614 #= Linker Configuration
615 #-------------------------------------------------------------------------------
616
617 link_directories(${Boost_LIBRARY_DIRS})
618
619 set(PULSEVIEW_LINK_LIBS
620         ${Boost_LIBRARIES}
621         ${QT_LIBRARIES}
622         ${CMAKE_THREAD_LIBS_INIT}
623         ${LIBATOMIC_LIBRARY}
624 )
625
626 if(STATIC_PKGDEPS_LIBS)
627         link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
628         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
629 else()
630         link_directories(${PKGDEPS_LIBRARY_DIRS})
631         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
632 endif()
633
634 if(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()
652 endif()
653
654 if(ENABLE_STACKTRACE)
655         list(APPEND PULSEVIEW_LINK_LIBS ${CMAKE_DL_LIBS} ${Backtrace_LIBRARIES})
656         link_libraries("-no-pie -fno-pie")
657 endif()
658
659 if(ANDROID)
660         list(APPEND PULSEVIEW_LINK_LIBS "-llog")
661 endif()
662
663 set(INPUT_FILES_LIST ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC} ${QM_FILES})
664 if(ANDROID)
665         add_library(${PROJECT_NAME} SHARED ${INPUT_FILES_LIST})
666 else()
667         add_executable(${PROJECT_NAME} ${INPUT_FILES_LIST})
668 endif()
669
670 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
671
672 if(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")
675 endif()
676
677 #===============================================================================
678 #= Installation
679 #-------------------------------------------------------------------------------
680
681 # Install the executable.
682 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
683
684 # Install the manpage.
685 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
686
687 # Install the desktop file.
688 install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
689
690 # Install the AppData/AppStream file.
691 install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
692
693 # Install the PulseView icons.
694 install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
695 install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
696
697 # Generate Windows installer script.
698 configure_file(contrib/pulseview_cross.nsi.in ${CMAKE_CURRENT_BINARY_DIR}/contrib/pulseview_cross.nsi @ONLY)
699
700 #===============================================================================
701 #= Packaging (handled by CPack)
702 #-------------------------------------------------------------------------------
703
704 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
705 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
706 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
707 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
708 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
709 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
710 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
711 set(CPACK_SOURCE_GENERATOR "TGZ")
712
713 include(CPack)
714
715 #===============================================================================
716 #= Tests
717 #-------------------------------------------------------------------------------
718
719 if(ENABLE_TESTS)
720         add_subdirectory(test)
721         enable_testing()
722         add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
723 endif()