]> sigrok.org Git - pulseview.git/blame - CMakeLists.txt
Segment: Include <memory> so we don't get error at compile time
[pulseview.git] / CMakeLists.txt
CommitLineData
0aad432c 1##
190fc91a 2## This file is part of the PulseView project.
68c4a3b3
JH
3##
4## Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
3933e8a9 5## Copyright (C) 2012-2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
c3660d7d 6## Copyright (C) 2020 Soeren Apel <soeren@apelpie.net>
68c4a3b3
JH
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
e222f01e 22cmake_minimum_required(VERSION 2.8.12)
0cf9fb24 23
d1125d7d 24project(pulseview C CXX)
df944399 25
d1125d7d 26include(GNUInstallDirs)
df944399 27
1c4ec8d0
UH
28# Let AUTOMOC and AUTOUIC process GENERATED files.
29if(POLICY CMP0071)
30 cmake_policy(SET CMP0071 NEW)
31endif()
32
2944860f
UH
33# Only interpret if() arguments as variables or keywords when unquoted.
34if(POLICY CMP0054)
35 cmake_policy(SET CMP0054 NEW)
36endif()
37
cf2b5b64
UH
38list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
39
30588653 40#===============================================================================
506523c1
JH
41#= User Options
42#-------------------------------------------------------------------------------
43
5c3c8c1e 44option(DISABLE_WERROR "Build without -Werror" TRUE)
140181a4 45option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
c1a688de 46option(ENABLE_STACKTRACE "Enable stack trace when crashing" FALSE)
19f511a4 47option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
f058e273 48option(ENABLE_FLOW "Build with libsigrokflow" FALSE)
b2d9be03 49option(ENABLE_TESTS "Enable unit tests" FALSE)
61e1e13e 50option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
b04e278d
AG
51
52if(WIN32)
7d297a01
UH
53 # On Windows/MinGW we need to statically link to libraries.
54 # This option is user configurable, but enable it by default on win32.
b04e278d 55 set(STATIC_PKGDEPS_LIBS TRUE)
6987ceeb 56
0aad432c 57 # Windows does not support UNIX signals.
140181a4 58 set(ENABLE_SIGNALS FALSE)
b04e278d 59endif()
506523c1 60
552f686e 61if(NOT CMAKE_BUILD_TYPE)
7591fe23
UH
62 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
63 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
64 FORCE)
552f686e
JH
65endif()
66
506523c1 67#===============================================================================
f2f536aa
GS
68#= Documentation
69#-------------------------------------------------------------------------------
70
71add_subdirectory(manual)
72
73#===============================================================================
30588653
AG
74#= Dependencies
75#-------------------------------------------------------------------------------
76
e1e2666e 77list(APPEND PKGDEPS glib-2.0>=2.28.0)
d93ac5e8 78list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
5252f438 79
696c7eac 80if(ENABLE_FLOW)
5252f438 81 list(APPEND PKGDEPS gstreamermm-1.0>=1.8.0)
045d8116 82 list(APPEND PKGDEPS libsigrokflow>=0.1.0)
5252f438 83endif()
d93ac5e8 84
1db57c03 85set(LIBSR_CXX_BINDING "libsigrokcxx>=0.5.2")
844c4619 86list(APPEND PKGDEPS "${LIBSR_CXX_BINDING}")
df944399 87
269528f5 88if(ENABLE_DECODE)
a2d1e7a8 89 list(APPEND PKGDEPS libsigrokdecode>=0.5.2)
269528f5
JH
90endif()
91
aff51746
MC
92if(ANDROID)
93 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
94endif()
95
d52d8455 96find_package(PkgConfig)
7bcd627e 97pkg_check_modules(LIBSRCXX ${LIBSR_CXX_BINDING})
844c4619
GS
98if(NOT LIBSRCXX_FOUND OR NOT LIBSRCXX_VERSION)
99 message(FATAL_ERROR "libsigrok C++ bindings missing, check libsigrok's 'configure' output (missing dependencies?)")
100endif()
d52d8455
JH
101pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
102
e222f01e 103set(CMAKE_AUTOMOC TRUE)
e222f01e 104
0466001b 105find_package(Qt5 5.3 COMPONENTS Core Gui LinguistTools Widgets Svg REQUIRED)
e7ab88e3 106
e08e8cc8
UH
107message(STATUS "Qt version: ${Qt5_VERSION}")
108
09f55d96
UH
109if(WIN32)
110 # MXE workaround: Use pkg-config to find Qt5 libs.
111 # https://github.com/mxe/mxe/issues/1642
929b9b19
UH
112 # Not required (and doesn't work) on MSYS2.
113 if(NOT DEFINED ENV{MSYSTEM})
5675292c 114 pkg_check_modules(QT5ALL REQUIRED Qt5Widgets>=5.3 Qt5Gui>=5.3 Qt5Svg>=5.3)
929b9b19 115 endif()
09f55d96 116endif()
9e8e84fc 117
e7ab88e3 118set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
2e2946fe 119
b8f1cdeb 120set(BOOSTCOMPS filesystem serialization system)
226a1527 121if(ENABLE_TESTS)
d68d75c2 122 list(APPEND BOOSTCOMPS unit_test_framework)
2a21747e 123endif()
c1a688de
SA
124
125if(ENABLE_STACKTRACE)
b409dfdc
WS
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()
c1a688de
SA
134 find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
135else()
136 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
137endif()
df944399 138
858ae630
UH
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.
2b76309a
AJ
141find_package(Threads REQUIRED)
142
4da54b6b
SM
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
153function(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>
162std::atomic<int> x;
163int main() {
164 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
165}
166" ${varname})
167 cmake_pop_check_state()
168endfunction(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.
172check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
173if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
174 message(STATUS "Atomics provided by the C-library - yes")
175else()
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()
189endif()
190
fe94bf82
GS
191# Check availability of features which depend on library versions.
192# TODO Ideally use check_symbol_exists() instead, reduce boilerplate.
193if(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()
212endif()
213
9df8453f
MC
214#===============================================================================
215#= System Introspection
216#-------------------------------------------------------------------------------
217
218include(memaccess)
219memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
220
075fb499
AG
221#===============================================================================
222#= Config Header
223#-------------------------------------------------------------------------------
224
f7951df4 225set(PV_TITLE PulseView)
e2649143 226set(PV_VERSION_STRING "0.5.0")
f7951df4 227
d93ac5e8
UH
228set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
229
1e8c82e9 230include(GetGitRevisionDescription)
1e8c82e9 231
812c0e35
DE
232# Append the revision hash unless we are exactly on a tagged release.
233git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
234if(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}")
d69b3c31 239 endif()
a53b8efe
SA
240
241 # Non-tagged releases use the unstable manual
242 set(PV_MANUAL_VERSION "unstable")
243else()
244 # Tagged releases use a fixed manual version
245 set(PV_MANUAL_VERSION ${PV_VERSION_STRING})
d69b3c31
DE
246endif()
247
248if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
1e8c82e9
DE
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})
1e8c82e9
DE
253endif()
254
1e3a52e3 255message(STATUS "${PV_TITLE} version: ${PV_VERSION_STRING}")
075fb499
AG
256
257configure_file (
258 ${PROJECT_SOURCE_DIR}/config.h.in
259 ${PROJECT_BINARY_DIR}/config.h
260)
df944399 261
30588653
AG
262#===============================================================================
263#= Sources
264#-------------------------------------------------------------------------------
265
a8d3fb2d 266set(pulseview_SOURCES
df944399 267 main.cpp
dac1bb97 268 pv/application.cpp
107ca6d3 269 pv/devicemanager.cpp
bf9f1268 270 pv/globalsettings.cpp
bcb4c327 271 pv/logging.cpp
51e77110 272 pv/mainwindow.cpp
f2739bae 273 pv/metadata_obj.cpp
f65cd27b 274 pv/session.cpp
0fbda3c2 275 pv/storesession.cpp
f0c9f81c 276 pv/util.cpp
61703a01 277 pv/binding/binding.cpp
0c913637 278 pv/binding/inputoutput.cpp
3cc9ad7b 279 pv/binding/device.cpp
1b1ec774 280 pv/data/analog.cpp
f3d66e52 281 pv/data/analogsegment.cpp
1b1ec774 282 pv/data/logic.cpp
f3d66e52 283 pv/data/logicsegment.cpp
b0773a8a 284 pv/data/mathsignal.cpp
bf0edd2b 285 pv/data/signalbase.cpp
1b1ec774 286 pv/data/signaldata.cpp
f3d66e52 287 pv/data/segment.cpp
da30ecb7 288 pv/devices/device.cpp
474e817a 289 pv/devices/file.cpp
da30ecb7 290 pv/devices/hardwaredevice.cpp
5237f0c5 291 pv/devices/inputfile.cpp
da30ecb7 292 pv/devices/sessionfile.cpp
9663c82b 293 pv/dialogs/connect.cpp
e93f5538 294 pv/dialogs/inputoutputoptions.cpp
bf9f1268 295 pv/dialogs/settings.cpp
0fbda3c2 296 pv/dialogs/storeprogress.cpp
51d4a9ab 297 pv/popups/deviceoptions.cpp
6ac6242b 298 pv/popups/channels.cpp
de1d99bb 299 pv/prop/bool.cpp
b912c99c 300 pv/prop/double.cpp
820c3dea 301 pv/prop/enum.cpp
a2b92157 302 pv/prop/int.cpp
c8df6005 303 pv/prop/property.cpp
7112a458 304 pv/prop/string.cpp
97378470 305 pv/subwindows/subwindowbase.cpp
7c657094 306 pv/toolbars/mainbar.cpp
1573bf16
SA
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
4640a84e 312 pv/views/trace/mathsignal.cpp
1573bf16
SA
313 pv/views/trace/marginwidget.cpp
314 pv/views/trace/logicsignal.cpp
1573bf16
SA
315 pv/views/trace/ruler.cpp
316 pv/views/trace/signal.cpp
1573bf16
SA
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
f4e57597 331 pv/views/viewbase.cpp
e0ba4f6f 332 pv/views/trace/standardbar.cpp
641574bc
SA
333 pv/widgets/colorbutton.cpp
334 pv/widgets/colorpopup.cpp
079d39ea 335 pv/widgets/devicetoolbutton.cpp
ce6001b8 336 pv/widgets/exportmenu.cpp
adf9e022 337 pv/widgets/flowlayout.cpp
56b6fc88 338 pv/widgets/importmenu.cpp
6e3f046e 339 pv/widgets/popup.cpp
6a91973f 340 pv/widgets/popuptoolbutton.cpp
1198b887 341 pv/widgets/sweeptimingwidget.cpp
806d3e1e 342 pv/widgets/timestampspinbox.cpp
0c0e1888 343 pv/widgets/wellarray.cpp
df944399
JH
344)
345
0aad432c 346# This list includes only QObject derived class headers.
a8d3fb2d 347set(pulseview_HEADERS
4640a84e 348 pv/exprtk.hpp
bcb4c327 349 pv/logging.hpp
bf9f1268 350 pv/globalsettings.hpp
2acdb232 351 pv/mainwindow.hpp
f2739bae 352 pv/metadata_obj.hpp
f65cd27b 353 pv/session.hpp
2acdb232 354 pv/storesession.hpp
3cc9ad7b 355 pv/binding/device.hpp
7db61e77
SA
356 pv/data/analog.hpp
357 pv/data/analogsegment.hpp
358 pv/data/logic.hpp
359 pv/data/logicsegment.hpp
b0773a8a 360 pv/data/mathsignal.hpp
bf0edd2b 361 pv/data/signalbase.hpp
2acdb232 362 pv/dialogs/connect.hpp
e93f5538 363 pv/dialogs/inputoutputoptions.hpp
bf9f1268 364 pv/dialogs/settings.hpp
2acdb232
JH
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
97378470 374 pv/subwindows/subwindowbase.hpp
7c657094 375 pv/toolbars/mainbar.hpp
1573bf16
SA
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
4640a84e 381 pv/views/trace/mathsignal.hpp
1573bf16 382 pv/views/trace/marginwidget.hpp
1573bf16
SA
383 pv/views/trace/ruler.hpp
384 pv/views/trace/signal.hpp
1573bf16
SA
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
f4e57597 395 pv/views/viewbase.hpp
e0ba4f6f 396 pv/views/trace/standardbar.hpp
641574bc
SA
397 pv/widgets/colorbutton.hpp
398 pv/widgets/colorpopup.hpp
079d39ea 399 pv/widgets/devicetoolbutton.hpp
ce6001b8 400 pv/widgets/exportmenu.hpp
adf9e022 401 pv/widgets/flowlayout.hpp
56b6fc88 402 pv/widgets/importmenu.hpp
2acdb232
JH
403 pv/widgets/popup.hpp
404 pv/widgets/popuptoolbutton.hpp
405 pv/widgets/sweeptimingwidget.hpp
806d3e1e 406 pv/widgets/timestampspinbox.hpp
2acdb232 407 pv/widgets/wellarray.hpp
df944399
JH
408)
409
8b9056d4
UH
410set(pulseview_RESOURCES
411 pulseview.qrc
412)
413
140181a4
JH
414if(ENABLE_SIGNALS)
415 list(APPEND pulseview_SOURCES signalhandler.cpp)
2acdb232 416 list(APPEND pulseview_HEADERS signalhandler.hpp)
140181a4
JH
417endif()
418
269528f5
JH
419if(ENABLE_DECODE)
420 list(APPEND pulseview_SOURCES
3cc9ad7b 421 pv/binding/decoder.cpp
ad908057 422 pv/data/decodesignal.cpp
269528f5
JH
423 pv/data/decode/annotation.cpp
424 pv/data/decode/decoder.cpp
f9101a91
JH
425 pv/data/decode/row.cpp
426 pv/data/decode/rowdata.cpp
97378470
SA
427 pv/subwindows/decoder_selector/item.cpp
428 pv/subwindows/decoder_selector/model.cpp
429 pv/subwindows/decoder_selector/subwindow.cpp
121307b3
SA
430 pv/views/decoder_binary/view.cpp
431 pv/views/decoder_binary/QHexView.cpp
24d69d27
SA
432 pv/views/tabular_decoder/model.cpp
433 pv/views/tabular_decoder/view.cpp
1573bf16 434 pv/views/trace/decodetrace.cpp
269528f5
JH
435 pv/widgets/decodergroupbox.cpp
436 pv/widgets/decodermenu.cpp
269528f5
JH
437 )
438
439 list(APPEND pulseview_HEADERS
ad908057 440 pv/data/decodesignal.hpp
97378470 441 pv/subwindows/decoder_selector/subwindow.hpp
121307b3
SA
442 pv/views/decoder_binary/view.hpp
443 pv/views/decoder_binary/QHexView.hpp
24d69d27 444 pv/views/tabular_decoder/view.hpp
1573bf16 445 pv/views/trace/decodetrace.hpp
2acdb232
JH
446 pv/widgets/decodergroupbox.hpp
447 pv/widgets/decodermenu.hpp
269528f5
JH
448 )
449endif()
450
fe15e0bc
UH
451if(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)
61e1e13e 455 list(APPEND pulseview_SOURCES pulseviewico.rc)
fe15e0bc
UH
456endif()
457
9137928c 458if(ANDROID)
dddff2e7
DE
459 list(APPEND pulseview_SOURCES
460 android/assetreader.cpp
461 android/loghandler.cpp
462 )
9137928c
MC
463endif()
464
8b9056d4
UH
465qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
466
0466001b
SA
467#===============================================================================
468#= Translations
469#-------------------------------------------------------------------------------
470
c3660d7d
SA
471file(GLOB TS_FILES ${CMAKE_SOURCE_DIR}/l10n/*.ts)
472set_property(SOURCE ${TS_FILES} PROPERTY OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/l10n)
989d50ad 473if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
474 configure_file("translations.qrc" "translations.qrc" COPYONLY)
475endif ()
0466001b
SA
476
477qt5_add_translation(QM_FILES ${TS_FILES})
478qt5_create_translation(QM_FILES ${pulseview_SOURCES} ${TS_FILES})
479
c3660d7d 480qt5_add_resources(pulseview_RESOURCES_RCC ${CMAKE_BINARY_DIR}/translations.qrc)
0466001b 481
30588653
AG
482#===============================================================================
483#= Global Definitions
484#-------------------------------------------------------------------------------
485
e222f01e 486add_definitions(-DQT_NO_KEYWORDS)
ac223c1e 487add_definitions(-D__STDC_LIMIT_MACROS)
a9974171 488add_definitions(-Wall -Wextra)
95d43108 489add_definitions(-std=c++11)
a838ed7b 490add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
d8cdab78
UH
491if(WIN32)
492 add_definitions(-Wa,-mbig-obj -O3)
493endif()
5f606159 494
696c7eac
UH
495if(ENABLE_FLOW)
496 add_definitions(-DENABLE_FLOW)
5252f438
UH
497endif()
498
269528f5
JH
499if(ENABLE_DECODE)
500 add_definitions(-DENABLE_DECODE)
501endif()
502
5f606159
JH
503if(NOT DISABLE_WERROR)
504 add_definitions(-Werror)
505endif()
df944399 506
9632990d
UH
507if(ENABLE_SIGNALS)
508 add_definitions(-DENABLE_SIGNALS)
509endif()
510
c1a688de 511if(ENABLE_STACKTRACE)
b409dfdc
WS
512 add_definitions(-DENABLE_STACKTRACE -no-pie -fno-pie)
513 if (Backtrace_FOUND)
514 add_definitions(-DBOOST_STACKTRACE_USE_BACKTRACE)
515 endif()
c1a688de
SA
516endif()
517
30588653
AG
518#===============================================================================
519#= Global Include Directories
520#-------------------------------------------------------------------------------
521
b04e278d
AG
522include_directories(
523 ${CMAKE_CURRENT_BINARY_DIR}
cef18fc6 524 ${CMAKE_CURRENT_SOURCE_DIR}
b04e278d
AG
525 ${Boost_INCLUDE_DIRS}
526)
527
528if(STATIC_PKGDEPS_LIBS)
529 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
530else()
531 include_directories(${PKGDEPS_INCLUDE_DIRS})
532endif()
df944399 533
30588653
AG
534#===============================================================================
535#= Linker Configuration
536#-------------------------------------------------------------------------------
537
b04e278d
AG
538link_directories(${Boost_LIBRARY_DIRS})
539
540set(PULSEVIEW_LINK_LIBS
541 ${Boost_LIBRARIES}
542 ${QT_LIBRARIES}
2b76309a 543 ${CMAKE_THREAD_LIBS_INIT}
4da54b6b 544 ${LIBATOMIC_LIBRARY}
b04e278d
AG
545)
546
547if(STATIC_PKGDEPS_LIBS)
cddf172d 548 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
09f55d96 549 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
b04e278d 550else()
cddf172d
UH
551 link_directories(${PKGDEPS_LIBRARY_DIRS})
552 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
b04e278d 553endif()
df944399 554
11a04e2a
UH
555if(WIN32)
556 # On Windows we need to statically link the libqsvg imageformat
557 # plugin (and the QtSvg component) for SVG graphics/icons to work.
356fb5c0
UH
558 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport (only for
559 # Qt < 5.8.0), and all Qt libs and their dependencies.
11a04e2a 560 add_definitions(-DQT_STATICPLUGIN)
09f55d96
UH
561 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
562 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
356fb5c0
UH
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})
11a04e2a
UH
567endif()
568
c1a688de 569if(ENABLE_STACKTRACE)
b409dfdc
WS
570 list(APPEND PULSEVIEW_LINK_LIBS ${CMAKE_DL_LIBS} ${Backtrace_LIBRARIES})
571 link_libraries("-no-pie -fno-pie")
c1a688de
SA
572endif()
573
9137928c
MC
574if(ANDROID)
575 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
576endif()
577
c243364c 578set(INPUT_FILES_LIST ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC} ${QM_FILES})
26807061 579if(ANDROID)
c243364c 580 add_library(${PROJECT_NAME} SHARED ${INPUT_FILES_LIST})
26807061 581else()
c243364c 582 add_executable(${PROJECT_NAME} ${INPUT_FILES_LIST})
26807061 583endif()
df944399 584
5a13850b 585target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
f0fa92c6 586
b732b48f 587if(WIN32 AND NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
61e1e13e
UH
588 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
589 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
b0d8c0dc
UH
590endif()
591
30588653
AG
592#===============================================================================
593#= Installation
594#-------------------------------------------------------------------------------
595
52bbe600 596# Install the executable.
cd6606c2
AG
597install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
598
52bbe600
UH
599# Install the manpage.
600install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
601
96e282c4
UH
602# Install the desktop file.
603install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
604
22fc985b
UH
605# Install the AppData/AppStream file.
606install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
607
09594425
UH
608# Install the PulseView icons.
609install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
610install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
611
f9cb49cc 612# Generate Windows installer script.
baef263a 613configure_file(contrib/pulseview_cross.nsi.in ${CMAKE_CURRENT_BINARY_DIR}/contrib/pulseview_cross.nsi @ONLY)
f9cb49cc 614
cd6606c2
AG
615#===============================================================================
616#= Packaging (handled by CPack)
617#-------------------------------------------------------------------------------
618
b02a8cbf
JH
619set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
620set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
621set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
cd6606c2
AG
622set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
623set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
624set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
1e8c82e9 625set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
1d2fb87d 626set(CPACK_SOURCE_GENERATOR "TGZ")
cd6606c2
AG
627
628include(CPack)
bc1c1462 629
30588653
AG
630#===============================================================================
631#= Tests
632#-------------------------------------------------------------------------------
633
77e8ac52 634if(ENABLE_TESTS)
fb746bcc 635 add_subdirectory(test)
951c583c 636 enable_testing()
fb746bcc 637 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
0aad432c 638endif()