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