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