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 # For boost-thread we need two additional settings on win32:
46 set(Boost_USE_STATIC_LIBS ON)
47 add_definitions(-DBOOST_THREAD_USE_LIB)
49 # On Windows/MinGW we need to use 'thread_win32' instead of 'thread'.
50 # The library is named libboost_thread_win32* (not libboost_thread*).
51 set(Boost_THREADAPI win32)
53 # Windows does not support UNIX signals.
54 set(ENABLE_SIGNALS FALSE)
57 if(NOT CMAKE_BUILD_TYPE)
58 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
59 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
63 #===============================================================================
65 #-------------------------------------------------------------------------------
67 list(APPEND PKGDEPS libsigrokcxx>=0.4.0)
70 list(APPEND PKGDEPS libsigrokdecode>=0.4.0)
74 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
77 find_package(PkgConfig)
78 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
81 set(Qt5Core_FOUND FALSE)
83 find_package(Qt5Core QUIET)
85 # MXE workaround: Use pkg-config to find Qt5 libs.
86 # https://github.com/mxe/mxe/issues/1642
87 pkg_check_modules(QT5ALL REQUIRED Qt5Widgets Qt5Gui Qt5Svg)
92 message("-- Using Qt5")
93 find_package(Qt5Widgets REQUIRED)
94 find_package(Qt5Gui REQUIRED)
95 find_package(Qt5Svg REQUIRED)
96 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
97 set(QT_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
98 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
99 add_definitions(${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS})
101 find_program(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 qmake-mac)
102 find_package(Qt4 REQUIRED QtCore QtGui QtSvg)
105 set(BOOSTCOMPS filesystem serialization system thread)
107 list(APPEND BOOSTCOMPS unit_test_framework)
109 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
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.
113 find_package(Threads REQUIRED)
116 # Check for explicit link against libatomic
118 # Depending on the toolchain, linking a program using atomic functions may need
119 # "-latomic" explicitly passed to the linker
121 # This check first tests if atomics are available in the C-library, if not and
122 # libatomic exists, then it runs the same test with -latomic added to the
125 # Helper for checking for atomics
126 function(check_working_cxx_atomics varname additional_lib)
127 include(CheckCXXSourceCompiles)
128 include(CMakePushCheckState)
129 cmake_push_check_state()
130 set(CMAKE_REQUIRED_FLAGS "-std=c++11")
131 set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
132 set(CMAKE_REQUIRED_QUIET 1)
133 CHECK_CXX_SOURCE_COMPILES("
137 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
140 cmake_pop_check_state()
141 endfunction(check_working_cxx_atomics)
143 # First check if atomics work without the library.
144 # If not, check if the library exists, and atomics work with it.
145 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
146 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
147 message(STATUS "Atomics provided by the C-library - yes")
149 message(STATUS "Atomics provided by the C-library - no")
150 find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
151 if(LIBATOMIC_LIBRARY)
152 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
153 if (HAVE_CXX_ATOMICS_WITH_LIB)
154 message(STATUS "Atomics provided by libatomic - yes")
156 message(STATUS "Atomics provided by libatomic - no")
157 message(FATAL_ERROR "Compiler must support std::atomic!")
160 message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
164 #===============================================================================
165 #= System Introspection
166 #-------------------------------------------------------------------------------
169 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
171 #===============================================================================
173 #-------------------------------------------------------------------------------
175 set(PV_TITLE PulseView)
176 set(PV_DESCRIPTION "A GUI for sigrok")
177 set(PV_VERSION_STRING "0.4.0")
179 include(GetGitRevisionDescription)
181 # Append the revision hash unless we are exactly on a tagged release.
182 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
183 if(NOT PV_TAG_VERSION_STRING)
184 get_git_head_revision(PV_REVSPEC PV_HASH)
186 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
187 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
191 if(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})
198 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
201 ${PROJECT_SOURCE_DIR}/config.h.in
202 ${PROJECT_BINARY_DIR}/config.h
205 #===============================================================================
207 #-------------------------------------------------------------------------------
209 set(pulseview_SOURCES
213 pv/globalsettings.cpp
218 pv/binding/binding.cpp
219 pv/binding/inputoutput.cpp
220 pv/binding/device.cpp
222 pv/data/analogsegment.cpp
224 pv/data/logicsegment.cpp
225 pv/data/signalbase.cpp
226 pv/data/signaldata.cpp
228 pv/devices/device.cpp
230 pv/devices/hardwaredevice.cpp
231 pv/devices/inputfile.cpp
232 pv/devices/sessionfile.cpp
233 pv/dialogs/connect.cpp
234 pv/dialogs/inputoutputoptions.cpp
235 pv/dialogs/settings.cpp
236 pv/dialogs/storeprogress.cpp
237 pv/popups/deviceoptions.cpp
238 pv/popups/channels.cpp
245 pv/toolbars/mainbar.cpp
246 pv/view/analogsignal.cpp
248 pv/view/cursorpair.cpp
251 pv/view/marginwidget.cpp
252 pv/view/logicsignal.cpp
256 pv/view/signalscalehandle.cpp
258 pv/view/timemarker.cpp
260 pv/view/tracegroup.cpp
261 pv/view/tracepalette.cpp
262 pv/view/tracetreeitem.cpp
263 pv/view/tracetreeitemowner.cpp
264 pv/view/triggermarker.cpp
267 pv/view/viewitemowner.cpp
268 pv/view/viewitempaintparams.cpp
270 pv/view/viewwidget.cpp
271 pv/views/viewbase.cpp
272 pv/views/trace/standardbar.cpp
273 pv/widgets/colourbutton.cpp
274 pv/widgets/colourpopup.cpp
275 pv/widgets/devicetoolbutton.cpp
276 pv/widgets/exportmenu.cpp
277 pv/widgets/importmenu.cpp
279 pv/widgets/popuptoolbutton.cpp
280 pv/widgets/sweeptimingwidget.cpp
281 pv/widgets/timestampspinbox.cpp
282 pv/widgets/wellarray.cpp
285 # This list includes only QObject derived class headers.
286 set(pulseview_HEADERS
287 pv/globalsettings.hpp
291 pv/binding/device.hpp
293 pv/data/analogsegment.hpp
295 pv/data/logicsegment.hpp
296 pv/data/signalbase.hpp
297 pv/dialogs/connect.hpp
298 pv/dialogs/inputoutputoptions.hpp
299 pv/dialogs/settings.hpp
300 pv/dialogs/storeprogress.hpp
301 pv/popups/channels.hpp
302 pv/popups/deviceoptions.hpp
309 pv/toolbars/mainbar.hpp
310 pv/view/analogsignal.hpp
314 pv/view/logicsignal.hpp
315 pv/view/marginwidget.hpp
319 pv/view/signalscalehandle.hpp
321 pv/view/timemarker.hpp
323 pv/view/tracegroup.hpp
324 pv/view/tracetreeitem.hpp
325 pv/view/triggermarker.hpp
329 pv/view/viewwidget.hpp
330 pv/views/viewbase.hpp
331 pv/views/trace/standardbar.hpp
332 pv/widgets/colourbutton.hpp
333 pv/widgets/colourpopup.hpp
334 pv/widgets/devicetoolbutton.hpp
335 pv/widgets/exportmenu.hpp
336 pv/widgets/importmenu.hpp
338 pv/widgets/popuptoolbutton.hpp
339 pv/widgets/sweeptimingwidget.hpp
340 pv/widgets/timestampspinbox.hpp
341 pv/widgets/wellarray.hpp
344 set(pulseview_RESOURCES
349 list(APPEND pulseview_SOURCES signalhandler.cpp)
350 list(APPEND pulseview_HEADERS signalhandler.hpp)
354 list(APPEND pulseview_SOURCES
355 pv/binding/decoder.cpp
356 pv/data/decoderstack.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/view/decodetrace.cpp
362 pv/widgets/decodergroupbox.cpp
363 pv/widgets/decodermenu.cpp
366 list(APPEND pulseview_HEADERS
367 pv/data/decoderstack.hpp
368 pv/view/decodetrace.hpp
369 pv/widgets/decodergroupbox.hpp
370 pv/widgets/decodermenu.hpp
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>")
378 list(APPEND pulseview_SOURCES pulseviewico.rc)
382 list(APPEND pulseview_SOURCES
383 android/assetreader.cpp
384 android/loghandler.cpp
389 qt5_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS})
390 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
392 # Workaround for QTBUG-22829: -DBOOST_NEXT_PRIOR_HPP_INCLUDED.
393 # https://bugreports.qt.io/browse/QTBUG-22829
394 qt4_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS}
395 OPTIONS -DBOOST_NEXT_PRIOR_HPP_INCLUDED)
396 qt4_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
397 include(${QT_USE_FILE})
400 #===============================================================================
401 #= Global Definitions
402 #-------------------------------------------------------------------------------
404 add_definitions(${QT_DEFINITIONS} -DQT_NO_KEYWORDS)
405 add_definitions(-D__STDC_LIMIT_MACROS)
406 add_definitions(-Wall -Wextra)
407 add_definitions(-std=c++11)
408 add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
411 add_definitions(-DENABLE_DECODE)
414 if(NOT DISABLE_WERROR)
415 add_definitions(-Werror)
419 add_definitions(-DENABLE_SIGNALS)
422 #===============================================================================
423 #= Global Include Directories
424 #-------------------------------------------------------------------------------
427 ${CMAKE_CURRENT_BINARY_DIR}
428 ${CMAKE_CURRENT_SOURCE_DIR}
429 ${Boost_INCLUDE_DIRS}
433 if(STATIC_PKGDEPS_LIBS)
434 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
436 include_directories(${PKGDEPS_INCLUDE_DIRS})
439 #===============================================================================
440 #= Linker Configuration
441 #-------------------------------------------------------------------------------
443 link_directories(${Boost_LIBRARY_DIRS})
445 set(PULSEVIEW_LINK_LIBS
448 ${CMAKE_THREAD_LIBS_INIT}
452 if(STATIC_PKGDEPS_LIBS)
453 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
454 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
456 link_directories(${PKGDEPS_LIBRARY_DIRS})
457 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
461 # On Windows we need to statically link the libqsvg imageformat
462 # plugin (and the QtSvg component) for SVG graphics/icons to work.
463 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport, and all
464 # Qt libs and their dependencies.
465 add_definitions(-DQT_STATICPLUGIN)
466 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
467 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
468 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport ${QT5ALL_LDFLAGS})
472 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
476 add_library(${PROJECT_NAME} SHARED
478 ${pulseview_HEADERS_MOC}
479 ${pulseview_RESOURCES_RCC}
482 add_executable(${PROJECT_NAME}
484 ${pulseview_HEADERS_MOC}
485 ${pulseview_RESOURCES_RCC}
489 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
492 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
493 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
496 #===============================================================================
498 #-------------------------------------------------------------------------------
500 # Install the executable.
501 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
503 # Install the manpage.
504 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
506 # Generate Windows installer script.
507 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
509 #===============================================================================
510 #= Packaging (handled by CPack)
511 #-------------------------------------------------------------------------------
513 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
514 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
515 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
516 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
517 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
518 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
519 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
520 set(CPACK_SOURCE_GENERATOR "TGZ")
524 #===============================================================================
526 #-------------------------------------------------------------------------------
529 add_subdirectory(test)
531 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)