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 # Only interpret if() arguments as variables or keywords when unquoted.
34 cmake_policy(SET CMP0054 NEW)
37 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
39 #===============================================================================
41 #-------------------------------------------------------------------------------
43 option(DISABLE_WERROR "Build without -Werror" FALSE)
44 option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
45 option(ENABLE_STACKTRACE "Enable stack trace when crashing" FALSE)
46 option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
47 option(ENABLE_TESTS "Enable unit tests" FALSE)
48 option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
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)
55 # Windows does not support UNIX signals.
56 set(ENABLE_SIGNALS FALSE)
59 if(NOT CMAKE_BUILD_TYPE)
60 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
61 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
65 #===============================================================================
67 #-------------------------------------------------------------------------------
69 list(APPEND PKGDEPS glib-2.0>=2.28.0)
70 list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
72 set(LIBSR_CXX_BINDING "libsigrokcxx>=0.6.0")
73 list(APPEND PKGDEPS "${LIBSR_CXX_BINDING}")
76 list(APPEND PKGDEPS libsigrokdecode>=0.6.0)
80 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
83 find_package(PkgConfig)
84 pkg_check_modules(LIBSRCXX QUIET ${LIBSR_CXX_BINDING})
85 if(NOT LIBSRCXX_FOUND OR NOT LIBSRCXX_VERSION)
86 message(FATAL_ERROR "libsigrok C++ bindings missing, check libsigrok's 'configure' output (missing dependencies?)")
88 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
90 set(CMAKE_AUTOMOC TRUE)
92 find_package(Qt5 COMPONENTS Core Gui Widgets Svg REQUIRED)
95 # MXE workaround: Use pkg-config to find Qt5 libs.
96 # https://github.com/mxe/mxe/issues/1642
97 # Not required (and doesn't work) on MSYS2.
98 if(NOT DEFINED ENV{MSYSTEM})
99 pkg_check_modules(QT5ALL REQUIRED Qt5Widgets Qt5Gui Qt5Svg)
103 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
105 set(BOOSTCOMPS filesystem serialization system)
107 list(APPEND BOOSTCOMPS unit_test_framework)
110 if(ENABLE_STACKTRACE)
111 find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
113 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
116 # Find the platform's thread library (needed for C++11 threads).
117 # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
118 find_package(Threads REQUIRED)
120 # Check for explicit link against libatomic
122 # Depending on the toolchain, linking a program using atomic functions may need
123 # "-latomic" explicitly passed to the linker
125 # This check first tests if atomics are available in the C-library, if not and
126 # libatomic exists, then it runs the same test with -latomic added to the
129 # Helper for checking for atomics
130 function(check_working_cxx_atomics varname additional_lib)
131 include(CheckCXXSourceCompiles)
132 include(CMakePushCheckState)
133 cmake_push_check_state()
134 set(CMAKE_REQUIRED_FLAGS "-std=c++11")
135 set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
136 set(CMAKE_REQUIRED_QUIET 1)
137 CHECK_CXX_SOURCE_COMPILES("
141 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
144 cmake_pop_check_state()
145 endfunction(check_working_cxx_atomics)
147 # First check if atomics work without the library.
148 # If not, check if the library exists, and atomics work with it.
149 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
150 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
151 message(STATUS "Atomics provided by the C-library - yes")
153 message(STATUS "Atomics provided by the C-library - no")
154 find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
155 if(LIBATOMIC_LIBRARY)
156 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
157 if (HAVE_CXX_ATOMICS_WITH_LIB)
158 message(STATUS "Atomics provided by libatomic - yes")
160 message(STATUS "Atomics provided by libatomic - no")
161 message(FATAL_ERROR "Compiler must support std::atomic!")
164 message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
168 #===============================================================================
169 #= System Introspection
170 #-------------------------------------------------------------------------------
173 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
175 #===============================================================================
177 #-------------------------------------------------------------------------------
179 set(PV_TITLE PulseView)
180 set(PV_VERSION_STRING "0.5.0")
182 set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
184 include(GetGitRevisionDescription)
186 # Append the revision hash unless we are exactly on a tagged release.
187 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
188 if(NOT PV_TAG_VERSION_STRING)
189 get_git_head_revision(PV_REVSPEC PV_HASH)
191 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
192 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
196 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
197 set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
198 set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
199 set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
200 set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
203 message(STATUS "${PV_TITLE} version: ${PV_VERSION_STRING}")
206 ${PROJECT_SOURCE_DIR}/config.h.in
207 ${PROJECT_BINARY_DIR}/config.h
210 #===============================================================================
212 #-------------------------------------------------------------------------------
214 set(pulseview_SOURCES
218 pv/globalsettings.cpp
224 pv/binding/binding.cpp
225 pv/binding/inputoutput.cpp
226 pv/binding/device.cpp
228 pv/data/analogsegment.cpp
230 pv/data/logicsegment.cpp
231 pv/data/signalbase.cpp
232 pv/data/signaldata.cpp
234 pv/devices/device.cpp
236 pv/devices/hardwaredevice.cpp
237 pv/devices/inputfile.cpp
238 pv/devices/sessionfile.cpp
239 pv/dialogs/connect.cpp
240 pv/dialogs/inputoutputoptions.cpp
241 pv/dialogs/settings.cpp
242 pv/dialogs/storeprogress.cpp
243 pv/popups/deviceoptions.cpp
244 pv/popups/channels.cpp
251 pv/toolbars/mainbar.cpp
252 pv/views/trace/analogsignal.cpp
253 pv/views/trace/cursor.cpp
254 pv/views/trace/cursorpair.cpp
255 pv/views/trace/flag.cpp
256 pv/views/trace/header.cpp
257 pv/views/trace/marginwidget.cpp
258 pv/views/trace/logicsignal.cpp
259 pv/views/trace/rowitem.cpp
260 pv/views/trace/ruler.cpp
261 pv/views/trace/signal.cpp
262 pv/views/trace/timeitem.cpp
263 pv/views/trace/timemarker.cpp
264 pv/views/trace/trace.cpp
265 pv/views/trace/tracegroup.cpp
266 pv/views/trace/tracepalette.cpp
267 pv/views/trace/tracetreeitem.cpp
268 pv/views/trace/tracetreeitemowner.cpp
269 pv/views/trace/triggermarker.cpp
270 pv/views/trace/view.cpp
271 pv/views/trace/viewitem.cpp
272 pv/views/trace/viewitemowner.cpp
273 pv/views/trace/viewitempaintparams.cpp
274 pv/views/trace/viewport.cpp
275 pv/views/trace/viewwidget.cpp
276 pv/views/viewbase.cpp
277 pv/views/trace/standardbar.cpp
278 pv/widgets/colorbutton.cpp
279 pv/widgets/colorpopup.cpp
280 pv/widgets/devicetoolbutton.cpp
281 pv/widgets/exportmenu.cpp
282 pv/widgets/importmenu.cpp
284 pv/widgets/popuptoolbutton.cpp
285 pv/widgets/sweeptimingwidget.cpp
286 pv/widgets/timestampspinbox.cpp
287 pv/widgets/wellarray.cpp
290 # This list includes only QObject derived class headers.
291 set(pulseview_HEADERS
293 pv/globalsettings.hpp
297 pv/binding/device.hpp
299 pv/data/analogsegment.hpp
301 pv/data/logicsegment.hpp
302 pv/data/signalbase.hpp
303 pv/dialogs/connect.hpp
304 pv/dialogs/inputoutputoptions.hpp
305 pv/dialogs/settings.hpp
306 pv/dialogs/storeprogress.hpp
307 pv/popups/channels.hpp
308 pv/popups/deviceoptions.hpp
315 pv/toolbars/mainbar.hpp
316 pv/views/trace/analogsignal.hpp
317 pv/views/trace/cursor.hpp
318 pv/views/trace/flag.hpp
319 pv/views/trace/header.hpp
320 pv/views/trace/logicsignal.hpp
321 pv/views/trace/marginwidget.hpp
322 pv/views/trace/rowitem.hpp
323 pv/views/trace/ruler.hpp
324 pv/views/trace/signal.hpp
325 pv/views/trace/timeitem.hpp
326 pv/views/trace/timemarker.hpp
327 pv/views/trace/trace.hpp
328 pv/views/trace/tracegroup.hpp
329 pv/views/trace/tracetreeitem.hpp
330 pv/views/trace/triggermarker.hpp
331 pv/views/trace/view.hpp
332 pv/views/trace/viewitem.hpp
333 pv/views/trace/viewport.hpp
334 pv/views/trace/viewwidget.hpp
335 pv/views/viewbase.hpp
336 pv/views/trace/standardbar.hpp
337 pv/widgets/colorbutton.hpp
338 pv/widgets/colorpopup.hpp
339 pv/widgets/devicetoolbutton.hpp
340 pv/widgets/exportmenu.hpp
341 pv/widgets/importmenu.hpp
343 pv/widgets/popuptoolbutton.hpp
344 pv/widgets/sweeptimingwidget.hpp
345 pv/widgets/timestampspinbox.hpp
346 pv/widgets/wellarray.hpp
349 set(pulseview_RESOURCES
354 list(APPEND pulseview_SOURCES signalhandler.cpp)
355 list(APPEND pulseview_HEADERS signalhandler.hpp)
359 list(APPEND pulseview_SOURCES
360 pv/binding/decoder.cpp
361 pv/data/decodesignal.cpp
362 pv/data/decode/annotation.cpp
363 pv/data/decode/decoder.cpp
364 pv/data/decode/row.cpp
365 pv/data/decode/rowdata.cpp
366 pv/views/trace/decodetrace.cpp
367 pv/widgets/decodergroupbox.cpp
368 pv/widgets/decodermenu.cpp
371 list(APPEND pulseview_HEADERS
372 pv/data/decodesignal.hpp
373 pv/views/trace/decodetrace.hpp
374 pv/widgets/decodergroupbox.hpp
375 pv/widgets/decodermenu.hpp
380 # Use the sigrok icon for the pulseview.exe executable.
381 set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
383 list(APPEND pulseview_SOURCES pulseviewico.rc)
387 list(APPEND pulseview_SOURCES
388 android/assetreader.cpp
389 android/loghandler.cpp
393 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
395 #===============================================================================
396 #= Global Definitions
397 #-------------------------------------------------------------------------------
399 add_definitions(-DQT_NO_KEYWORDS)
400 add_definitions(-D__STDC_LIMIT_MACROS)
401 add_definitions(-Wall -Wextra)
402 add_definitions(-std=c++11)
403 add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
406 add_definitions(-DENABLE_DECODE)
409 if(NOT DISABLE_WERROR)
410 add_definitions(-Werror)
414 add_definitions(-DENABLE_SIGNALS)
417 if(ENABLE_STACKTRACE)
418 add_definitions(-DENABLE_STACKTRACE)
421 #===============================================================================
422 #= Global Include Directories
423 #-------------------------------------------------------------------------------
426 ${CMAKE_CURRENT_BINARY_DIR}
427 ${CMAKE_CURRENT_SOURCE_DIR}
428 ${Boost_INCLUDE_DIRS}
431 if(STATIC_PKGDEPS_LIBS)
432 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
434 include_directories(${PKGDEPS_INCLUDE_DIRS})
437 #===============================================================================
438 #= Linker Configuration
439 #-------------------------------------------------------------------------------
441 link_directories(${Boost_LIBRARY_DIRS})
443 set(PULSEVIEW_LINK_LIBS
446 ${CMAKE_THREAD_LIBS_INIT}
450 if(STATIC_PKGDEPS_LIBS)
451 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
452 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
454 link_directories(${PKGDEPS_LIBRARY_DIRS})
455 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
459 # On Windows we need to statically link the libqsvg imageformat
460 # plugin (and the QtSvg component) for SVG graphics/icons to work.
461 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport (only for
462 # Qt < 5.8.0), and all Qt libs and their dependencies.
463 add_definitions(-DQT_STATICPLUGIN)
464 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
465 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
466 if(Qt5Gui_VERSION VERSION_LESS 5.8.0)
467 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport)
469 list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
472 if(ENABLE_STACKTRACE)
473 # Needed to resolve dladdr.
474 list(APPEND PULSEVIEW_LINK_LIBS "-ldl")
478 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
482 add_library(${PROJECT_NAME} SHARED ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
484 add_executable(${PROJECT_NAME} ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
487 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
489 if(WIN32 AND NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
490 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
491 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
494 #===============================================================================
496 #-------------------------------------------------------------------------------
498 # Install the executable.
499 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
501 # Install the manpage.
502 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
504 # Install the desktop file.
505 install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
507 # Install the AppData/AppStream file.
508 install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
510 # Install the PulseView icons.
511 install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
512 install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
514 # Generate Windows installer script.
515 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
517 #===============================================================================
518 #= Packaging (handled by CPack)
519 #-------------------------------------------------------------------------------
521 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
522 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
523 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
524 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
525 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
526 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
527 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
528 set(CPACK_SOURCE_GENERATOR "TGZ")
532 #===============================================================================
534 #-------------------------------------------------------------------------------
537 add_subdirectory(test)
539 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)