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 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
29 #===============================================================================
31 #-------------------------------------------------------------------------------
33 option(DISABLE_WERROR "Build without -Werror" FALSE)
34 option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
35 option(ENABLE_STACKTRACE "Enable stack trace when crashing" FALSE)
36 option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
37 option(ENABLE_TESTS "Enable unit tests" TRUE)
38 option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
41 # On Windows/MinGW we need to statically link to libraries.
42 # This option is user configurable, but enable it by default on win32.
43 set(STATIC_PKGDEPS_LIBS TRUE)
45 # Windows does not support UNIX signals.
46 set(ENABLE_SIGNALS FALSE)
49 if(NOT CMAKE_BUILD_TYPE)
50 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
51 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
55 #===============================================================================
57 #-------------------------------------------------------------------------------
59 list(APPEND PKGDEPS glib-2.0>=2.28.0)
60 list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
62 list(APPEND PKGDEPS libsigrokcxx>=0.6.0)
65 list(APPEND PKGDEPS libsigrokdecode>=0.6.0)
69 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
72 find_package(PkgConfig)
73 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
75 set(CMAKE_AUTOMOC TRUE)
77 find_package(Qt5 COMPONENTS Core Gui Widgets Svg REQUIRED)
80 # MXE workaround: Use pkg-config to find Qt5 libs.
81 # https://github.com/mxe/mxe/issues/1642
82 # Not required (and doesn't work) on MSYS2.
83 if(NOT DEFINED ENV{MSYSTEM})
84 pkg_check_modules(QT5ALL REQUIRED Qt5Widgets Qt5Gui Qt5Svg)
88 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
90 set(BOOSTCOMPS filesystem serialization system)
92 list(APPEND BOOSTCOMPS unit_test_framework)
96 find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
98 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
101 # Find the platform's thread library (needed for C++11 threads).
102 # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
103 find_package(Threads REQUIRED)
105 # Check for explicit link against libatomic
107 # Depending on the toolchain, linking a program using atomic functions may need
108 # "-latomic" explicitly passed to the linker
110 # This check first tests if atomics are available in the C-library, if not and
111 # libatomic exists, then it runs the same test with -latomic added to the
114 # Helper for checking for atomics
115 function(check_working_cxx_atomics varname additional_lib)
116 include(CheckCXXSourceCompiles)
117 include(CMakePushCheckState)
118 cmake_push_check_state()
119 set(CMAKE_REQUIRED_FLAGS "-std=c++11")
120 set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
121 set(CMAKE_REQUIRED_QUIET 1)
122 CHECK_CXX_SOURCE_COMPILES("
126 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
129 cmake_pop_check_state()
130 endfunction(check_working_cxx_atomics)
132 # First check if atomics work without the library.
133 # If not, check if the library exists, and atomics work with it.
134 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
135 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
136 message(STATUS "Atomics provided by the C-library - yes")
138 message(STATUS "Atomics provided by the C-library - no")
139 find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
140 if(LIBATOMIC_LIBRARY)
141 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
142 if (HAVE_CXX_ATOMICS_WITH_LIB)
143 message(STATUS "Atomics provided by libatomic - yes")
145 message(STATUS "Atomics provided by libatomic - no")
146 message(FATAL_ERROR "Compiler must support std::atomic!")
149 message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
153 #===============================================================================
154 #= System Introspection
155 #-------------------------------------------------------------------------------
158 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
160 #===============================================================================
162 #-------------------------------------------------------------------------------
164 set(PV_TITLE PulseView)
165 set(PV_VERSION_STRING "0.5.0")
167 set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
169 include(GetGitRevisionDescription)
171 # Append the revision hash unless we are exactly on a tagged release.
172 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
173 if(NOT PV_TAG_VERSION_STRING)
174 get_git_head_revision(PV_REVSPEC PV_HASH)
176 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
177 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
181 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
182 set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
183 set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
184 set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
185 set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
188 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
191 ${PROJECT_SOURCE_DIR}/config.h.in
192 ${PROJECT_BINARY_DIR}/config.h
195 #===============================================================================
197 #-------------------------------------------------------------------------------
199 set(pulseview_SOURCES
203 pv/globalsettings.cpp
209 pv/binding/binding.cpp
210 pv/binding/inputoutput.cpp
211 pv/binding/device.cpp
213 pv/data/analogsegment.cpp
215 pv/data/logicsegment.cpp
216 pv/data/signalbase.cpp
217 pv/data/signaldata.cpp
219 pv/devices/device.cpp
221 pv/devices/hardwaredevice.cpp
222 pv/devices/inputfile.cpp
223 pv/devices/sessionfile.cpp
224 pv/dialogs/connect.cpp
225 pv/dialogs/inputoutputoptions.cpp
226 pv/dialogs/settings.cpp
227 pv/dialogs/storeprogress.cpp
228 pv/popups/deviceoptions.cpp
229 pv/popups/channels.cpp
236 pv/toolbars/mainbar.cpp
237 pv/views/trace/analogsignal.cpp
238 pv/views/trace/cursor.cpp
239 pv/views/trace/cursorpair.cpp
240 pv/views/trace/flag.cpp
241 pv/views/trace/header.cpp
242 pv/views/trace/marginwidget.cpp
243 pv/views/trace/logicsignal.cpp
244 pv/views/trace/rowitem.cpp
245 pv/views/trace/ruler.cpp
246 pv/views/trace/signal.cpp
247 pv/views/trace/timeitem.cpp
248 pv/views/trace/timemarker.cpp
249 pv/views/trace/trace.cpp
250 pv/views/trace/tracegroup.cpp
251 pv/views/trace/tracepalette.cpp
252 pv/views/trace/tracetreeitem.cpp
253 pv/views/trace/tracetreeitemowner.cpp
254 pv/views/trace/triggermarker.cpp
255 pv/views/trace/view.cpp
256 pv/views/trace/viewitem.cpp
257 pv/views/trace/viewitemowner.cpp
258 pv/views/trace/viewitempaintparams.cpp
259 pv/views/trace/viewport.cpp
260 pv/views/trace/viewwidget.cpp
261 pv/views/viewbase.cpp
262 pv/views/trace/standardbar.cpp
263 pv/widgets/colourbutton.cpp
264 pv/widgets/colourpopup.cpp
265 pv/widgets/devicetoolbutton.cpp
266 pv/widgets/exportmenu.cpp
267 pv/widgets/importmenu.cpp
269 pv/widgets/popuptoolbutton.cpp
270 pv/widgets/sweeptimingwidget.cpp
271 pv/widgets/timestampspinbox.cpp
272 pv/widgets/wellarray.cpp
275 # This list includes only QObject derived class headers.
276 set(pulseview_HEADERS
278 pv/globalsettings.hpp
282 pv/binding/device.hpp
284 pv/data/analogsegment.hpp
286 pv/data/logicsegment.hpp
287 pv/data/signalbase.hpp
288 pv/dialogs/connect.hpp
289 pv/dialogs/inputoutputoptions.hpp
290 pv/dialogs/settings.hpp
291 pv/dialogs/storeprogress.hpp
292 pv/popups/channels.hpp
293 pv/popups/deviceoptions.hpp
300 pv/toolbars/mainbar.hpp
301 pv/views/trace/analogsignal.hpp
302 pv/views/trace/cursor.hpp
303 pv/views/trace/flag.hpp
304 pv/views/trace/header.hpp
305 pv/views/trace/logicsignal.hpp
306 pv/views/trace/marginwidget.hpp
307 pv/views/trace/rowitem.hpp
308 pv/views/trace/ruler.hpp
309 pv/views/trace/signal.hpp
310 pv/views/trace/timeitem.hpp
311 pv/views/trace/timemarker.hpp
312 pv/views/trace/trace.hpp
313 pv/views/trace/tracegroup.hpp
314 pv/views/trace/tracetreeitem.hpp
315 pv/views/trace/triggermarker.hpp
316 pv/views/trace/view.hpp
317 pv/views/trace/viewitem.hpp
318 pv/views/trace/viewport.hpp
319 pv/views/trace/viewwidget.hpp
320 pv/views/viewbase.hpp
321 pv/views/trace/standardbar.hpp
322 pv/widgets/colourbutton.hpp
323 pv/widgets/colourpopup.hpp
324 pv/widgets/devicetoolbutton.hpp
325 pv/widgets/exportmenu.hpp
326 pv/widgets/importmenu.hpp
328 pv/widgets/popuptoolbutton.hpp
329 pv/widgets/sweeptimingwidget.hpp
330 pv/widgets/timestampspinbox.hpp
331 pv/widgets/wellarray.hpp
334 set(pulseview_RESOURCES
339 list(APPEND pulseview_SOURCES signalhandler.cpp)
340 list(APPEND pulseview_HEADERS signalhandler.hpp)
344 list(APPEND pulseview_SOURCES
345 pv/binding/decoder.cpp
346 pv/data/decodesignal.cpp
347 pv/data/decode/annotation.cpp
348 pv/data/decode/decoder.cpp
349 pv/data/decode/row.cpp
350 pv/data/decode/rowdata.cpp
351 pv/views/trace/decodetrace.cpp
352 pv/widgets/decodergroupbox.cpp
353 pv/widgets/decodermenu.cpp
356 list(APPEND pulseview_HEADERS
357 pv/data/decodesignal.hpp
358 pv/views/trace/decodetrace.hpp
359 pv/widgets/decodergroupbox.hpp
360 pv/widgets/decodermenu.hpp
365 # Use the sigrok icon for the pulseview.exe executable.
366 set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
368 list(APPEND pulseview_SOURCES pulseviewico.rc)
372 list(APPEND pulseview_SOURCES
373 android/assetreader.cpp
374 android/loghandler.cpp
378 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
380 #===============================================================================
381 #= Global Definitions
382 #-------------------------------------------------------------------------------
384 add_definitions(-DQT_NO_KEYWORDS)
385 add_definitions(-D__STDC_LIMIT_MACROS)
386 add_definitions(-Wall -Wextra)
387 add_definitions(-std=c++11)
388 add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
391 add_definitions(-DENABLE_DECODE)
394 if(NOT DISABLE_WERROR)
395 add_definitions(-Werror)
399 add_definitions(-DENABLE_SIGNALS)
402 if(ENABLE_STACKTRACE)
403 add_definitions(-DENABLE_STACKTRACE)
406 #===============================================================================
407 #= Global Include Directories
408 #-------------------------------------------------------------------------------
411 ${CMAKE_CURRENT_BINARY_DIR}
412 ${CMAKE_CURRENT_SOURCE_DIR}
413 ${Boost_INCLUDE_DIRS}
416 if(STATIC_PKGDEPS_LIBS)
417 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
419 include_directories(${PKGDEPS_INCLUDE_DIRS})
422 #===============================================================================
423 #= Linker Configuration
424 #-------------------------------------------------------------------------------
426 link_directories(${Boost_LIBRARY_DIRS})
428 set(PULSEVIEW_LINK_LIBS
431 ${CMAKE_THREAD_LIBS_INIT}
435 if(STATIC_PKGDEPS_LIBS)
436 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
437 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
439 link_directories(${PKGDEPS_LIBRARY_DIRS})
440 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
444 # On Windows we need to statically link the libqsvg imageformat
445 # plugin (and the QtSvg component) for SVG graphics/icons to work.
446 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport (only for
447 # Qt < 5.8.0), and all Qt libs and their dependencies.
448 add_definitions(-DQT_STATICPLUGIN)
449 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
450 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
451 if(Qt5Gui_VERSION VERSION_LESS 5.8.0)
452 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport)
454 list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
457 if(ENABLE_STACKTRACE)
458 # Needed to resolve dladdr.
459 list(APPEND PULSEVIEW_LINK_LIBS "-ldl")
463 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
467 add_library(${PROJECT_NAME} SHARED ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
469 add_executable(${PROJECT_NAME} ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
472 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
474 if(WIN32 AND NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
475 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
476 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
479 #===============================================================================
481 #-------------------------------------------------------------------------------
483 # Install the executable.
484 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
486 # Install the manpage.
487 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
489 # Install the desktop file.
490 install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
492 # Install the AppData/AppStream file.
493 install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
495 # Install the PulseView icons.
496 install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
497 install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
499 # Generate Windows installer script.
500 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
502 #===============================================================================
503 #= Packaging (handled by CPack)
504 #-------------------------------------------------------------------------------
506 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
507 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
508 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
509 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
510 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
511 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
512 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
513 set(CPACK_SOURCE_GENERATOR "TGZ")
517 #===============================================================================
519 #-------------------------------------------------------------------------------
522 add_subdirectory(test)
524 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)