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