2 ## This file is part of the PulseView project.
4 ## Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 ## Copyright (C) 2012-2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
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.
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.
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/>.
21 cmake_minimum_required(VERSION 2.8.12)
23 include(GNUInstallDirs)
27 # Let AUTOMOC and AUTOUIC process GENERATED files.
29 cmake_policy(SET CMP0071 NEW)
32 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
34 #===============================================================================
36 #-------------------------------------------------------------------------------
38 option(DISABLE_WERROR "Build without -Werror" FALSE)
39 option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
40 option(ENABLE_STACKTRACE "Enable stack trace when crashing" FALSE)
41 option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
42 option(ENABLE_TESTS "Enable unit tests" TRUE)
43 option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
46 # On Windows/MinGW we need to statically link to libraries.
47 # This option is user configurable, but enable it by default on win32.
48 set(STATIC_PKGDEPS_LIBS TRUE)
50 # Windows does not support UNIX signals.
51 set(ENABLE_SIGNALS FALSE)
54 if(NOT CMAKE_BUILD_TYPE)
55 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
56 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
60 #===============================================================================
62 #-------------------------------------------------------------------------------
64 list(APPEND PKGDEPS glib-2.0>=2.28.0)
65 list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
67 list(APPEND PKGDEPS libsigrokcxx>=0.6.0)
70 list(APPEND PKGDEPS libsigrokdecode>=0.6.0)
74 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
77 find_package(PkgConfig)
78 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
80 set(CMAKE_AUTOMOC TRUE)
82 find_package(Qt5 COMPONENTS Core Gui Widgets Svg REQUIRED)
85 # MXE workaround: Use pkg-config to find Qt5 libs.
86 # https://github.com/mxe/mxe/issues/1642
87 # Not required (and doesn't work) on MSYS2.
88 if(NOT DEFINED ENV{MSYSTEM})
89 pkg_check_modules(QT5ALL REQUIRED Qt5Widgets Qt5Gui Qt5Svg)
93 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
95 set(BOOSTCOMPS filesystem serialization system)
97 list(APPEND BOOSTCOMPS unit_test_framework)
100 if(ENABLE_STACKTRACE)
101 find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
103 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
106 # Find the platform's thread library (needed for C++11 threads).
107 # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
108 find_package(Threads REQUIRED)
110 # Check for explicit link against libatomic
112 # Depending on the toolchain, linking a program using atomic functions may need
113 # "-latomic" explicitly passed to the linker
115 # This check first tests if atomics are available in the C-library, if not and
116 # libatomic exists, then it runs the same test with -latomic added to the
119 # Helper for checking for atomics
120 function(check_working_cxx_atomics varname additional_lib)
121 include(CheckCXXSourceCompiles)
122 include(CMakePushCheckState)
123 cmake_push_check_state()
124 set(CMAKE_REQUIRED_FLAGS "-std=c++11")
125 set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
126 set(CMAKE_REQUIRED_QUIET 1)
127 CHECK_CXX_SOURCE_COMPILES("
131 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
134 cmake_pop_check_state()
135 endfunction(check_working_cxx_atomics)
137 # First check if atomics work without the library.
138 # If not, check if the library exists, and atomics work with it.
139 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
140 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
141 message(STATUS "Atomics provided by the C-library - yes")
143 message(STATUS "Atomics provided by the C-library - no")
144 find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
145 if(LIBATOMIC_LIBRARY)
146 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
147 if (HAVE_CXX_ATOMICS_WITH_LIB)
148 message(STATUS "Atomics provided by libatomic - yes")
150 message(STATUS "Atomics provided by libatomic - no")
151 message(FATAL_ERROR "Compiler must support std::atomic!")
154 message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
158 #===============================================================================
159 #= System Introspection
160 #-------------------------------------------------------------------------------
163 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
165 #===============================================================================
167 #-------------------------------------------------------------------------------
169 set(PV_TITLE PulseView)
170 set(PV_VERSION_STRING "0.5.0")
172 set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
174 include(GetGitRevisionDescription)
176 # Append the revision hash unless we are exactly on a tagged release.
177 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
178 if(NOT PV_TAG_VERSION_STRING)
179 get_git_head_revision(PV_REVSPEC PV_HASH)
181 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
182 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
186 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
187 set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
188 set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
189 set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
190 set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
193 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
196 ${PROJECT_SOURCE_DIR}/config.h.in
197 ${PROJECT_BINARY_DIR}/config.h
200 #===============================================================================
202 #-------------------------------------------------------------------------------
204 set(pulseview_SOURCES
208 pv/globalsettings.cpp
214 pv/binding/binding.cpp
215 pv/binding/inputoutput.cpp
216 pv/binding/device.cpp
218 pv/data/analogsegment.cpp
220 pv/data/logicsegment.cpp
221 pv/data/signalbase.cpp
222 pv/data/signaldata.cpp
224 pv/devices/device.cpp
226 pv/devices/hardwaredevice.cpp
227 pv/devices/inputfile.cpp
228 pv/devices/sessionfile.cpp
229 pv/dialogs/connect.cpp
230 pv/dialogs/inputoutputoptions.cpp
231 pv/dialogs/settings.cpp
232 pv/dialogs/storeprogress.cpp
233 pv/popups/deviceoptions.cpp
234 pv/popups/channels.cpp
241 pv/toolbars/mainbar.cpp
242 pv/views/trace/analogsignal.cpp
243 pv/views/trace/cursor.cpp
244 pv/views/trace/cursorpair.cpp
245 pv/views/trace/flag.cpp
246 pv/views/trace/header.cpp
247 pv/views/trace/marginwidget.cpp
248 pv/views/trace/logicsignal.cpp
249 pv/views/trace/rowitem.cpp
250 pv/views/trace/ruler.cpp
251 pv/views/trace/signal.cpp
252 pv/views/trace/timeitem.cpp
253 pv/views/trace/timemarker.cpp
254 pv/views/trace/trace.cpp
255 pv/views/trace/tracegroup.cpp
256 pv/views/trace/tracepalette.cpp
257 pv/views/trace/tracetreeitem.cpp
258 pv/views/trace/tracetreeitemowner.cpp
259 pv/views/trace/triggermarker.cpp
260 pv/views/trace/view.cpp
261 pv/views/trace/viewitem.cpp
262 pv/views/trace/viewitemowner.cpp
263 pv/views/trace/viewitempaintparams.cpp
264 pv/views/trace/viewport.cpp
265 pv/views/trace/viewwidget.cpp
266 pv/views/viewbase.cpp
267 pv/views/trace/standardbar.cpp
268 pv/widgets/colourbutton.cpp
269 pv/widgets/colourpopup.cpp
270 pv/widgets/devicetoolbutton.cpp
271 pv/widgets/exportmenu.cpp
272 pv/widgets/importmenu.cpp
274 pv/widgets/popuptoolbutton.cpp
275 pv/widgets/sweeptimingwidget.cpp
276 pv/widgets/timestampspinbox.cpp
277 pv/widgets/wellarray.cpp
280 # This list includes only QObject derived class headers.
281 set(pulseview_HEADERS
283 pv/globalsettings.hpp
287 pv/binding/device.hpp
289 pv/data/analogsegment.hpp
291 pv/data/logicsegment.hpp
292 pv/data/signalbase.hpp
293 pv/dialogs/connect.hpp
294 pv/dialogs/inputoutputoptions.hpp
295 pv/dialogs/settings.hpp
296 pv/dialogs/storeprogress.hpp
297 pv/popups/channels.hpp
298 pv/popups/deviceoptions.hpp
305 pv/toolbars/mainbar.hpp
306 pv/views/trace/analogsignal.hpp
307 pv/views/trace/cursor.hpp
308 pv/views/trace/flag.hpp
309 pv/views/trace/header.hpp
310 pv/views/trace/logicsignal.hpp
311 pv/views/trace/marginwidget.hpp
312 pv/views/trace/rowitem.hpp
313 pv/views/trace/ruler.hpp
314 pv/views/trace/signal.hpp
315 pv/views/trace/timeitem.hpp
316 pv/views/trace/timemarker.hpp
317 pv/views/trace/trace.hpp
318 pv/views/trace/tracegroup.hpp
319 pv/views/trace/tracetreeitem.hpp
320 pv/views/trace/triggermarker.hpp
321 pv/views/trace/view.hpp
322 pv/views/trace/viewitem.hpp
323 pv/views/trace/viewport.hpp
324 pv/views/trace/viewwidget.hpp
325 pv/views/viewbase.hpp
326 pv/views/trace/standardbar.hpp
327 pv/widgets/colourbutton.hpp
328 pv/widgets/colourpopup.hpp
329 pv/widgets/devicetoolbutton.hpp
330 pv/widgets/exportmenu.hpp
331 pv/widgets/importmenu.hpp
333 pv/widgets/popuptoolbutton.hpp
334 pv/widgets/sweeptimingwidget.hpp
335 pv/widgets/timestampspinbox.hpp
336 pv/widgets/wellarray.hpp
339 set(pulseview_RESOURCES
344 list(APPEND pulseview_SOURCES signalhandler.cpp)
345 list(APPEND pulseview_HEADERS signalhandler.hpp)
349 list(APPEND pulseview_SOURCES
350 pv/binding/decoder.cpp
351 pv/data/decodesignal.cpp
352 pv/data/decode/annotation.cpp
353 pv/data/decode/decoder.cpp
354 pv/data/decode/row.cpp
355 pv/data/decode/rowdata.cpp
356 pv/views/trace/decodetrace.cpp
357 pv/widgets/decodergroupbox.cpp
358 pv/widgets/decodermenu.cpp
361 list(APPEND pulseview_HEADERS
362 pv/data/decodesignal.hpp
363 pv/views/trace/decodetrace.hpp
364 pv/widgets/decodergroupbox.hpp
365 pv/widgets/decodermenu.hpp
370 # Use the sigrok icon for the pulseview.exe executable.
371 set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
373 list(APPEND pulseview_SOURCES pulseviewico.rc)
377 list(APPEND pulseview_SOURCES
378 android/assetreader.cpp
379 android/loghandler.cpp
383 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
385 #===============================================================================
386 #= Global Definitions
387 #-------------------------------------------------------------------------------
389 add_definitions(-DQT_NO_KEYWORDS)
390 add_definitions(-D__STDC_LIMIT_MACROS)
391 add_definitions(-Wall -Wextra)
392 add_definitions(-std=c++11)
393 add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
396 add_definitions(-DENABLE_DECODE)
399 if(NOT DISABLE_WERROR)
400 add_definitions(-Werror)
404 add_definitions(-DENABLE_SIGNALS)
407 if(ENABLE_STACKTRACE)
408 add_definitions(-DENABLE_STACKTRACE)
411 #===============================================================================
412 #= Global Include Directories
413 #-------------------------------------------------------------------------------
416 ${CMAKE_CURRENT_BINARY_DIR}
417 ${CMAKE_CURRENT_SOURCE_DIR}
418 ${Boost_INCLUDE_DIRS}
421 if(STATIC_PKGDEPS_LIBS)
422 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
424 include_directories(${PKGDEPS_INCLUDE_DIRS})
427 #===============================================================================
428 #= Linker Configuration
429 #-------------------------------------------------------------------------------
431 link_directories(${Boost_LIBRARY_DIRS})
433 set(PULSEVIEW_LINK_LIBS
436 ${CMAKE_THREAD_LIBS_INIT}
440 if(STATIC_PKGDEPS_LIBS)
441 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
442 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
444 link_directories(${PKGDEPS_LIBRARY_DIRS})
445 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
449 # On Windows we need to statically link the libqsvg imageformat
450 # plugin (and the QtSvg component) for SVG graphics/icons to work.
451 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport (only for
452 # Qt < 5.8.0), and all Qt libs and their dependencies.
453 add_definitions(-DQT_STATICPLUGIN)
454 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
455 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
456 if(Qt5Gui_VERSION VERSION_LESS 5.8.0)
457 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport)
459 list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
462 if(ENABLE_STACKTRACE)
463 # Needed to resolve dladdr.
464 list(APPEND PULSEVIEW_LINK_LIBS "-ldl")
468 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
472 add_library(${PROJECT_NAME} SHARED ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
474 add_executable(${PROJECT_NAME} ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
477 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
479 if(WIN32 AND NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
480 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
481 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
484 #===============================================================================
486 #-------------------------------------------------------------------------------
488 # Install the executable.
489 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
491 # Install the manpage.
492 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
494 # Install the desktop file.
495 install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
497 # Install the AppData/AppStream file.
498 install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
500 # Install the PulseView icons.
501 install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
502 install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
504 # Generate Windows installer script.
505 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
507 #===============================================================================
508 #= Packaging (handled by CPack)
509 #-------------------------------------------------------------------------------
511 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
512 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
513 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
514 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
515 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
516 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
517 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
518 set(CPACK_SOURCE_GENERATOR "TGZ")
522 #===============================================================================
524 #-------------------------------------------------------------------------------
527 add_subdirectory(test)
529 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)