]> sigrok.org Git - pulseview.git/blame_incremental - CMakeLists.txt
Fix up change handler registration
[pulseview.git] / CMakeLists.txt
... / ...
CommitLineData
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##
7## This program is free software: you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation, either version 2 of the License, or
10## (at your option) any later version.
11##
12## This program is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with this program. If not, see <http://www.gnu.org/licenses/>.
19##
20
21cmake_minimum_required(VERSION 2.8.12)
22
23include(GNUInstallDirs)
24
25project(pulseview)
26
27# Let AUTOMOC and AUTOUIC process GENERATED files.
28if(POLICY CMP0071)
29 cmake_policy(SET CMP0071 NEW)
30endif()
31
32# Only interpret if() arguments as variables or keywords when unquoted.
33if(POLICY CMP0054)
34 cmake_policy(SET CMP0054 NEW)
35endif()
36
37list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
38
39#===============================================================================
40#= User Options
41#-------------------------------------------------------------------------------
42
43option(DISABLE_WERROR "Build without -Werror" FALSE)
44option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
45option(ENABLE_STACKTRACE "Enable stack trace when crashing" FALSE)
46option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
47option(ENABLE_TESTS "Enable unit tests" FALSE)
48option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
49
50if(WIN32)
51 # On Windows/MinGW we need to statically link to libraries.
52 # This option is user configurable, but enable it by default on win32.
53 set(STATIC_PKGDEPS_LIBS TRUE)
54
55 # Windows does not support UNIX signals.
56 set(ENABLE_SIGNALS FALSE)
57endif()
58
59if(NOT CMAKE_BUILD_TYPE)
60 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
61 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
62 FORCE)
63endif()
64
65#===============================================================================
66#= Dependencies
67#-------------------------------------------------------------------------------
68
69list(APPEND PKGDEPS glib-2.0>=2.28.0)
70list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
71
72list(APPEND PKGDEPS libsigrokcxx>=0.6.0)
73
74if(ENABLE_DECODE)
75 list(APPEND PKGDEPS libsigrokdecode>=0.6.0)
76endif()
77
78if(ANDROID)
79 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
80endif()
81
82find_package(PkgConfig)
83pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
84
85set(CMAKE_AUTOMOC TRUE)
86
87find_package(Qt5 COMPONENTS Core Gui Widgets Svg REQUIRED)
88
89if(WIN32)
90 # MXE workaround: Use pkg-config to find Qt5 libs.
91 # https://github.com/mxe/mxe/issues/1642
92 # Not required (and doesn't work) on MSYS2.
93 if(NOT DEFINED ENV{MSYSTEM})
94 pkg_check_modules(QT5ALL REQUIRED Qt5Widgets Qt5Gui Qt5Svg)
95 endif()
96endif()
97
98set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
99
100set(BOOSTCOMPS filesystem serialization system)
101if(ENABLE_TESTS)
102 list(APPEND BOOSTCOMPS unit_test_framework)
103endif()
104
105if(ENABLE_STACKTRACE)
106 find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
107else()
108 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
109endif()
110
111# Find the platform's thread library (needed for C++11 threads).
112# This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
113find_package(Threads REQUIRED)
114
115# Check for explicit link against libatomic
116#
117# Depending on the toolchain, linking a program using atomic functions may need
118# "-latomic" explicitly passed to the linker
119#
120# This check first tests if atomics are available in the C-library, if not and
121# libatomic exists, then it runs the same test with -latomic added to the
122# linker flags.
123
124# Helper for checking for atomics
125function(check_working_cxx_atomics varname additional_lib)
126 include(CheckCXXSourceCompiles)
127 include(CMakePushCheckState)
128 cmake_push_check_state()
129 set(CMAKE_REQUIRED_FLAGS "-std=c++11")
130 set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
131 set(CMAKE_REQUIRED_QUIET 1)
132 CHECK_CXX_SOURCE_COMPILES("
133#include <atomic>
134std::atomic<int> x;
135int main() {
136 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
137}
138" ${varname})
139 cmake_pop_check_state()
140endfunction(check_working_cxx_atomics)
141
142# First check if atomics work without the library.
143# If not, check if the library exists, and atomics work with it.
144check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
145if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
146 message(STATUS "Atomics provided by the C-library - yes")
147else()
148 message(STATUS "Atomics provided by the C-library - no")
149 find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
150 if(LIBATOMIC_LIBRARY)
151 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
152 if (HAVE_CXX_ATOMICS_WITH_LIB)
153 message(STATUS "Atomics provided by libatomic - yes")
154 else()
155 message(STATUS "Atomics provided by libatomic - no")
156 message(FATAL_ERROR "Compiler must support std::atomic!")
157 endif()
158 else()
159 message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
160 endif()
161endif()
162
163#===============================================================================
164#= System Introspection
165#-------------------------------------------------------------------------------
166
167include(memaccess)
168memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
169
170#===============================================================================
171#= Config Header
172#-------------------------------------------------------------------------------
173
174set(PV_TITLE PulseView)
175set(PV_VERSION_STRING "0.5.0")
176
177set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
178
179include(GetGitRevisionDescription)
180
181# Append the revision hash unless we are exactly on a tagged release.
182git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
183if(NOT PV_TAG_VERSION_STRING)
184 get_git_head_revision(PV_REVSPEC PV_HASH)
185 if(PV_HASH)
186 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
187 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
188 endif()
189endif()
190
191if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
192 set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
193 set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
194 set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
195 set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
196endif()
197
198message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
199
200configure_file (
201 ${PROJECT_SOURCE_DIR}/config.h.in
202 ${PROJECT_BINARY_DIR}/config.h
203)
204
205#===============================================================================
206#= Sources
207#-------------------------------------------------------------------------------
208
209set(pulseview_SOURCES
210 main.cpp
211 pv/application.cpp
212 pv/devicemanager.cpp
213 pv/globalsettings.cpp
214 pv/logging.cpp
215 pv/mainwindow.cpp
216 pv/session.cpp
217 pv/storesession.cpp
218 pv/util.cpp
219 pv/binding/binding.cpp
220 pv/binding/inputoutput.cpp
221 pv/binding/device.cpp
222 pv/data/analog.cpp
223 pv/data/analogsegment.cpp
224 pv/data/logic.cpp
225 pv/data/logicsegment.cpp
226 pv/data/signalbase.cpp
227 pv/data/signaldata.cpp
228 pv/data/segment.cpp
229 pv/devices/device.cpp
230 pv/devices/file.cpp
231 pv/devices/hardwaredevice.cpp
232 pv/devices/inputfile.cpp
233 pv/devices/sessionfile.cpp
234 pv/dialogs/connect.cpp
235 pv/dialogs/inputoutputoptions.cpp
236 pv/dialogs/settings.cpp
237 pv/dialogs/storeprogress.cpp
238 pv/popups/deviceoptions.cpp
239 pv/popups/channels.cpp
240 pv/prop/bool.cpp
241 pv/prop/double.cpp
242 pv/prop/enum.cpp
243 pv/prop/int.cpp
244 pv/prop/property.cpp
245 pv/prop/string.cpp
246 pv/toolbars/mainbar.cpp
247 pv/views/trace/analogsignal.cpp
248 pv/views/trace/cursor.cpp
249 pv/views/trace/cursorpair.cpp
250 pv/views/trace/flag.cpp
251 pv/views/trace/header.cpp
252 pv/views/trace/marginwidget.cpp
253 pv/views/trace/logicsignal.cpp
254 pv/views/trace/rowitem.cpp
255 pv/views/trace/ruler.cpp
256 pv/views/trace/signal.cpp
257 pv/views/trace/timeitem.cpp
258 pv/views/trace/timemarker.cpp
259 pv/views/trace/trace.cpp
260 pv/views/trace/tracegroup.cpp
261 pv/views/trace/tracepalette.cpp
262 pv/views/trace/tracetreeitem.cpp
263 pv/views/trace/tracetreeitemowner.cpp
264 pv/views/trace/triggermarker.cpp
265 pv/views/trace/view.cpp
266 pv/views/trace/viewitem.cpp
267 pv/views/trace/viewitemowner.cpp
268 pv/views/trace/viewitempaintparams.cpp
269 pv/views/trace/viewport.cpp
270 pv/views/trace/viewwidget.cpp
271 pv/views/viewbase.cpp
272 pv/views/trace/standardbar.cpp
273 pv/widgets/colorbutton.cpp
274 pv/widgets/colorpopup.cpp
275 pv/widgets/devicetoolbutton.cpp
276 pv/widgets/exportmenu.cpp
277 pv/widgets/importmenu.cpp
278 pv/widgets/popup.cpp
279 pv/widgets/popuptoolbutton.cpp
280 pv/widgets/sweeptimingwidget.cpp
281 pv/widgets/timestampspinbox.cpp
282 pv/widgets/wellarray.cpp
283)
284
285# This list includes only QObject derived class headers.
286set(pulseview_HEADERS
287 pv/logging.hpp
288 pv/globalsettings.hpp
289 pv/mainwindow.hpp
290 pv/session.hpp
291 pv/storesession.hpp
292 pv/binding/device.hpp
293 pv/data/analog.hpp
294 pv/data/analogsegment.hpp
295 pv/data/logic.hpp
296 pv/data/logicsegment.hpp
297 pv/data/signalbase.hpp
298 pv/dialogs/connect.hpp
299 pv/dialogs/inputoutputoptions.hpp
300 pv/dialogs/settings.hpp
301 pv/dialogs/storeprogress.hpp
302 pv/popups/channels.hpp
303 pv/popups/deviceoptions.hpp
304 pv/prop/bool.hpp
305 pv/prop/double.hpp
306 pv/prop/enum.hpp
307 pv/prop/int.hpp
308 pv/prop/property.hpp
309 pv/prop/string.hpp
310 pv/toolbars/mainbar.hpp
311 pv/views/trace/analogsignal.hpp
312 pv/views/trace/cursor.hpp
313 pv/views/trace/flag.hpp
314 pv/views/trace/header.hpp
315 pv/views/trace/logicsignal.hpp
316 pv/views/trace/marginwidget.hpp
317 pv/views/trace/rowitem.hpp
318 pv/views/trace/ruler.hpp
319 pv/views/trace/signal.hpp
320 pv/views/trace/timeitem.hpp
321 pv/views/trace/timemarker.hpp
322 pv/views/trace/trace.hpp
323 pv/views/trace/tracegroup.hpp
324 pv/views/trace/tracetreeitem.hpp
325 pv/views/trace/triggermarker.hpp
326 pv/views/trace/view.hpp
327 pv/views/trace/viewitem.hpp
328 pv/views/trace/viewport.hpp
329 pv/views/trace/viewwidget.hpp
330 pv/views/viewbase.hpp
331 pv/views/trace/standardbar.hpp
332 pv/widgets/colorbutton.hpp
333 pv/widgets/colorpopup.hpp
334 pv/widgets/devicetoolbutton.hpp
335 pv/widgets/exportmenu.hpp
336 pv/widgets/importmenu.hpp
337 pv/widgets/popup.hpp
338 pv/widgets/popuptoolbutton.hpp
339 pv/widgets/sweeptimingwidget.hpp
340 pv/widgets/timestampspinbox.hpp
341 pv/widgets/wellarray.hpp
342)
343
344set(pulseview_RESOURCES
345 pulseview.qrc
346)
347
348if(ENABLE_SIGNALS)
349 list(APPEND pulseview_SOURCES signalhandler.cpp)
350 list(APPEND pulseview_HEADERS signalhandler.hpp)
351endif()
352
353if(ENABLE_DECODE)
354 list(APPEND pulseview_SOURCES
355 pv/binding/decoder.cpp
356 pv/data/decodesignal.cpp
357 pv/data/decode/annotation.cpp
358 pv/data/decode/decoder.cpp
359 pv/data/decode/row.cpp
360 pv/data/decode/rowdata.cpp
361 pv/views/trace/decodetrace.cpp
362 pv/widgets/decodergroupbox.cpp
363 pv/widgets/decodermenu.cpp
364 )
365
366 list(APPEND pulseview_HEADERS
367 pv/data/decodesignal.hpp
368 pv/views/trace/decodetrace.hpp
369 pv/widgets/decodergroupbox.hpp
370 pv/widgets/decodermenu.hpp
371 )
372endif()
373
374if(WIN32)
375 # Use the sigrok icon for the pulseview.exe executable.
376 set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
377 enable_language(RC)
378 list(APPEND pulseview_SOURCES pulseviewico.rc)
379endif()
380
381if(ANDROID)
382 list(APPEND pulseview_SOURCES
383 android/assetreader.cpp
384 android/loghandler.cpp
385 )
386endif()
387
388qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
389
390#===============================================================================
391#= Global Definitions
392#-------------------------------------------------------------------------------
393
394add_definitions(-DQT_NO_KEYWORDS)
395add_definitions(-D__STDC_LIMIT_MACROS)
396add_definitions(-Wall -Wextra)
397add_definitions(-std=c++11)
398add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
399
400if(ENABLE_DECODE)
401 add_definitions(-DENABLE_DECODE)
402endif()
403
404if(NOT DISABLE_WERROR)
405 add_definitions(-Werror)
406endif()
407
408if(ENABLE_SIGNALS)
409 add_definitions(-DENABLE_SIGNALS)
410endif()
411
412if(ENABLE_STACKTRACE)
413 add_definitions(-DENABLE_STACKTRACE)
414endif()
415
416#===============================================================================
417#= Global Include Directories
418#-------------------------------------------------------------------------------
419
420include_directories(
421 ${CMAKE_CURRENT_BINARY_DIR}
422 ${CMAKE_CURRENT_SOURCE_DIR}
423 ${Boost_INCLUDE_DIRS}
424)
425
426if(STATIC_PKGDEPS_LIBS)
427 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
428else()
429 include_directories(${PKGDEPS_INCLUDE_DIRS})
430endif()
431
432#===============================================================================
433#= Linker Configuration
434#-------------------------------------------------------------------------------
435
436link_directories(${Boost_LIBRARY_DIRS})
437
438set(PULSEVIEW_LINK_LIBS
439 ${Boost_LIBRARIES}
440 ${QT_LIBRARIES}
441 ${CMAKE_THREAD_LIBS_INIT}
442 ${LIBATOMIC_LIBRARY}
443)
444
445if(STATIC_PKGDEPS_LIBS)
446 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
447 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
448else()
449 link_directories(${PKGDEPS_LIBRARY_DIRS})
450 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
451endif()
452
453if(WIN32)
454 # On Windows we need to statically link the libqsvg imageformat
455 # plugin (and the QtSvg component) for SVG graphics/icons to work.
456 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport (only for
457 # Qt < 5.8.0), and all Qt libs and their dependencies.
458 add_definitions(-DQT_STATICPLUGIN)
459 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
460 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
461 if(Qt5Gui_VERSION VERSION_LESS 5.8.0)
462 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport)
463 endif()
464 list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
465endif()
466
467if(ENABLE_STACKTRACE)
468 # Needed to resolve dladdr.
469 list(APPEND PULSEVIEW_LINK_LIBS "-ldl")
470endif()
471
472if(ANDROID)
473 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
474endif()
475
476if(ANDROID)
477 add_library(${PROJECT_NAME} SHARED ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
478else()
479 add_executable(${PROJECT_NAME} ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
480endif()
481
482target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
483
484if(WIN32 AND NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
485 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
486 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
487endif()
488
489#===============================================================================
490#= Installation
491#-------------------------------------------------------------------------------
492
493# Install the executable.
494install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
495
496# Install the manpage.
497install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
498
499# Install the desktop file.
500install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
501
502# Install the AppData/AppStream file.
503install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
504
505# Install the PulseView icons.
506install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
507install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
508
509# Generate Windows installer script.
510configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
511
512#===============================================================================
513#= Packaging (handled by CPack)
514#-------------------------------------------------------------------------------
515
516set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
517set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
518set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
519set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
520set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
521set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
522set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
523set(CPACK_SOURCE_GENERATOR "TGZ")
524
525include(CPack)
526
527#===============================================================================
528#= Tests
529#-------------------------------------------------------------------------------
530
531if(ENABLE_TESTS)
532 add_subdirectory(test)
533 enable_testing()
534 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
535endif()