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