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.6)
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_DECODE "Build with libsigrokdecode" TRUE)
36 option(ENABLE_TESTS "Enable unit tests" TRUE)
37 option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
38 option(FORCE_QT4 "Force use of Qt4 even if Qt5 is available" 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 libsigrokcxx>=0.4.0)
62 list(APPEND PKGDEPS libsigrokdecode>=0.4.0)
66 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
69 find_package(PkgConfig)
70 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
73 set(Qt5Core_FOUND FALSE)
75 find_package(Qt5Core QUIET)
77 # MXE workaround: Use pkg-config to find Qt5 libs.
78 # https://github.com/mxe/mxe/issues/1642
79 pkg_check_modules(QT5ALL REQUIRED Qt5Widgets Qt5Gui Qt5Svg)
84 message("-- Using Qt5")
85 find_package(Qt5Widgets REQUIRED)
86 find_package(Qt5Gui REQUIRED)
87 find_package(Qt5Svg REQUIRED)
88 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
89 set(QT_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
90 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
91 add_definitions(${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS})
93 find_program(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 qmake-mac)
94 find_package(Qt4 REQUIRED QtCore QtGui QtSvg)
97 set(BOOSTCOMPS filesystem serialization system)
99 list(APPEND BOOSTCOMPS unit_test_framework)
101 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
103 # Find the platform's thread library (needed for C++11 threads).
104 # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
105 find_package(Threads REQUIRED)
108 # Check for explicit link against libatomic
110 # Depending on the toolchain, linking a program using atomic functions may need
111 # "-latomic" explicitly passed to the linker
113 # This check first tests if atomics are available in the C-library, if not and
114 # libatomic exists, then it runs the same test with -latomic added to the
117 # Helper for checking for atomics
118 function(check_working_cxx_atomics varname additional_lib)
119 include(CheckCXXSourceCompiles)
120 include(CMakePushCheckState)
121 cmake_push_check_state()
122 set(CMAKE_REQUIRED_FLAGS "-std=c++11")
123 set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
124 set(CMAKE_REQUIRED_QUIET 1)
125 CHECK_CXX_SOURCE_COMPILES("
129 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
132 cmake_pop_check_state()
133 endfunction(check_working_cxx_atomics)
135 # First check if atomics work without the library.
136 # If not, check if the library exists, and atomics work with it.
137 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
138 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
139 message(STATUS "Atomics provided by the C-library - yes")
141 message(STATUS "Atomics provided by the C-library - no")
142 find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
143 if(LIBATOMIC_LIBRARY)
144 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
145 if (HAVE_CXX_ATOMICS_WITH_LIB)
146 message(STATUS "Atomics provided by libatomic - yes")
148 message(STATUS "Atomics provided by libatomic - no")
149 message(FATAL_ERROR "Compiler must support std::atomic!")
152 message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
156 #===============================================================================
157 #= System Introspection
158 #-------------------------------------------------------------------------------
161 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
163 #===============================================================================
165 #-------------------------------------------------------------------------------
167 set(PV_TITLE PulseView)
168 set(PV_DESCRIPTION "A GUI for sigrok")
169 set(PV_VERSION_STRING "0.4.0")
171 include(GetGitRevisionDescription)
173 # Append the revision hash unless we are exactly on a tagged release.
174 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
175 if(NOT PV_TAG_VERSION_STRING)
176 get_git_head_revision(PV_REVSPEC PV_HASH)
178 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
179 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
183 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
184 set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
185 set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
186 set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
187 set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
190 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
193 ${PROJECT_SOURCE_DIR}/config.h.in
194 ${PROJECT_BINARY_DIR}/config.h
197 #===============================================================================
199 #-------------------------------------------------------------------------------
201 set(pulseview_SOURCES
205 pv/globalsettings.cpp
210 pv/binding/binding.cpp
211 pv/binding/inputoutput.cpp
212 pv/binding/device.cpp
214 pv/data/analogsegment.cpp
216 pv/data/logicsegment.cpp
217 pv/data/signalbase.cpp
218 pv/data/signaldata.cpp
220 pv/devices/device.cpp
222 pv/devices/hardwaredevice.cpp
223 pv/devices/inputfile.cpp
224 pv/devices/sessionfile.cpp
225 pv/dialogs/connect.cpp
226 pv/dialogs/inputoutputoptions.cpp
227 pv/dialogs/settings.cpp
228 pv/dialogs/storeprogress.cpp
229 pv/popups/deviceoptions.cpp
230 pv/popups/channels.cpp
237 pv/toolbars/mainbar.cpp
238 pv/view/analogsignal.cpp
240 pv/view/cursorpair.cpp
243 pv/view/marginwidget.cpp
244 pv/view/logicsignal.cpp
248 pv/view/signalscalehandle.cpp
250 pv/view/timemarker.cpp
252 pv/view/tracegroup.cpp
253 pv/view/tracepalette.cpp
254 pv/view/tracetreeitem.cpp
255 pv/view/tracetreeitemowner.cpp
256 pv/view/triggermarker.cpp
259 pv/view/viewitemowner.cpp
260 pv/view/viewitempaintparams.cpp
262 pv/view/viewwidget.cpp
263 pv/views/viewbase.cpp
264 pv/views/trace/standardbar.cpp
265 pv/widgets/colourbutton.cpp
266 pv/widgets/colourpopup.cpp
267 pv/widgets/devicetoolbutton.cpp
268 pv/widgets/exportmenu.cpp
269 pv/widgets/importmenu.cpp
271 pv/widgets/popuptoolbutton.cpp
272 pv/widgets/sweeptimingwidget.cpp
273 pv/widgets/timestampspinbox.cpp
274 pv/widgets/wellarray.cpp
277 # This list includes only QObject derived class headers.
278 set(pulseview_HEADERS
279 pv/globalsettings.hpp
283 pv/binding/device.hpp
285 pv/data/analogsegment.hpp
287 pv/data/logicsegment.hpp
288 pv/data/signalbase.hpp
289 pv/dialogs/connect.hpp
290 pv/dialogs/inputoutputoptions.hpp
291 pv/dialogs/settings.hpp
292 pv/dialogs/storeprogress.hpp
293 pv/popups/channels.hpp
294 pv/popups/deviceoptions.hpp
301 pv/toolbars/mainbar.hpp
302 pv/view/analogsignal.hpp
306 pv/view/logicsignal.hpp
307 pv/view/marginwidget.hpp
311 pv/view/signalscalehandle.hpp
313 pv/view/timemarker.hpp
315 pv/view/tracegroup.hpp
316 pv/view/tracetreeitem.hpp
317 pv/view/triggermarker.hpp
321 pv/view/viewwidget.hpp
322 pv/views/viewbase.hpp
323 pv/views/trace/standardbar.hpp
324 pv/widgets/colourbutton.hpp
325 pv/widgets/colourpopup.hpp
326 pv/widgets/devicetoolbutton.hpp
327 pv/widgets/exportmenu.hpp
328 pv/widgets/importmenu.hpp
330 pv/widgets/popuptoolbutton.hpp
331 pv/widgets/sweeptimingwidget.hpp
332 pv/widgets/timestampspinbox.hpp
333 pv/widgets/wellarray.hpp
336 set(pulseview_RESOURCES
341 list(APPEND pulseview_SOURCES signalhandler.cpp)
342 list(APPEND pulseview_HEADERS signalhandler.hpp)
346 list(APPEND pulseview_SOURCES
347 pv/binding/decoder.cpp
348 pv/data/decoderstack.cpp
349 pv/data/decode/annotation.cpp
350 pv/data/decode/decoder.cpp
351 pv/data/decode/row.cpp
352 pv/data/decode/rowdata.cpp
353 pv/view/decodetrace.cpp
354 pv/widgets/decodergroupbox.cpp
355 pv/widgets/decodermenu.cpp
358 list(APPEND pulseview_HEADERS
359 pv/data/decoderstack.hpp
360 pv/view/decodetrace.hpp
361 pv/widgets/decodergroupbox.hpp
362 pv/widgets/decodermenu.hpp
367 # Use the sigrok icon for the pulseview.exe executable.
368 set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
370 list(APPEND pulseview_SOURCES pulseviewico.rc)
374 list(APPEND pulseview_SOURCES
375 android/assetreader.cpp
376 android/loghandler.cpp
381 qt5_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS})
382 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
384 # Workaround for QTBUG-22829: -DBOOST_NEXT_PRIOR_HPP_INCLUDED.
385 # https://bugreports.qt.io/browse/QTBUG-22829
386 qt4_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS}
387 OPTIONS -DBOOST_NEXT_PRIOR_HPP_INCLUDED)
388 qt4_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
389 include(${QT_USE_FILE})
392 #===============================================================================
393 #= Global Definitions
394 #-------------------------------------------------------------------------------
396 add_definitions(${QT_DEFINITIONS} -DQT_NO_KEYWORDS)
397 add_definitions(-D__STDC_LIMIT_MACROS)
398 add_definitions(-Wall -Wextra)
399 add_definitions(-std=c++11)
400 add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
403 add_definitions(-DENABLE_DECODE)
406 if(NOT DISABLE_WERROR)
407 add_definitions(-Werror)
411 add_definitions(-DENABLE_SIGNALS)
414 #===============================================================================
415 #= Global Include Directories
416 #-------------------------------------------------------------------------------
419 ${CMAKE_CURRENT_BINARY_DIR}
420 ${CMAKE_CURRENT_SOURCE_DIR}
421 ${Boost_INCLUDE_DIRS}
425 if(STATIC_PKGDEPS_LIBS)
426 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
428 include_directories(${PKGDEPS_INCLUDE_DIRS})
431 #===============================================================================
432 #= Linker Configuration
433 #-------------------------------------------------------------------------------
435 link_directories(${Boost_LIBRARY_DIRS})
437 set(PULSEVIEW_LINK_LIBS
440 ${CMAKE_THREAD_LIBS_INIT}
444 if(STATIC_PKGDEPS_LIBS)
445 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
446 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
448 link_directories(${PKGDEPS_LIBRARY_DIRS})
449 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
453 # On Windows we need to statically link the libqsvg imageformat
454 # plugin (and the QtSvg component) for SVG graphics/icons to work.
455 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport, and all
456 # Qt libs and their dependencies.
457 add_definitions(-DQT_STATICPLUGIN)
458 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
459 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
460 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport ${QT5ALL_LDFLAGS})
464 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
468 add_library(${PROJECT_NAME} SHARED
470 ${pulseview_HEADERS_MOC}
471 ${pulseview_RESOURCES_RCC}
474 add_executable(${PROJECT_NAME}
476 ${pulseview_HEADERS_MOC}
477 ${pulseview_RESOURCES_RCC}
481 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
484 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
485 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
488 #===============================================================================
490 #-------------------------------------------------------------------------------
492 # Install the executable.
493 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
495 # Install the manpage.
496 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
498 # Generate Windows installer script.
499 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
501 #===============================================================================
502 #= Packaging (handled by CPack)
503 #-------------------------------------------------------------------------------
505 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
506 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
507 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
508 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
509 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
510 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
511 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
512 set(CPACK_SOURCE_GENERATOR "TGZ")
516 #===============================================================================
518 #-------------------------------------------------------------------------------
521 add_subdirectory(test)
523 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)