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(FindPkgConfig)
24 include(GNUInstallDirs)
28 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
30 #===============================================================================
32 #-------------------------------------------------------------------------------
34 option(DISABLE_WERROR "Build without -Werror" FALSE)
35 option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
36 option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
37 option(ENABLE_TESTS "Enable unit tests" FALSE)
38 option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
39 option(FORCE_QT4 "Force use of Qt4 even if Qt5 is available" FALSE)
42 # On Windows/MinGW we need to statically link to libraries.
43 # This option is user configurable, but enable it by default on win32.
44 set(STATIC_PKGDEPS_LIBS TRUE)
46 # For boost-thread we need two additional settings on win32:
47 set(Boost_USE_STATIC_LIBS ON)
48 add_definitions(-DBOOST_THREAD_USE_LIB)
50 # On Windows/MinGW we need to use 'thread_win32' instead of 'thread'.
51 # The library is named libboost_thread_win32* (not libboost_thread*).
52 set(Boost_THREADAPI win32)
54 # Windows does not support UNIX signals.
55 set(ENABLE_SIGNALS FALSE)
58 if(NOT CMAKE_BUILD_TYPE)
59 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
60 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
64 #===============================================================================
66 #-------------------------------------------------------------------------------
68 list(APPEND PKGDEPS libsigrokcxx>=0.4.0)
71 list(APPEND PKGDEPS libsigrokdecode>=0.4.0)
75 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
78 find_package(PkgConfig)
79 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
82 set(Qt5Core_FOUND FALSE)
84 find_package(Qt5Core QUIET)
88 message("-- Using Qt5")
89 find_package(Qt5Widgets REQUIRED)
90 find_package(Qt5Gui REQUIRED)
91 find_package(Qt5Svg REQUIRED)
92 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
93 set(QT_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
94 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
95 add_definitions(${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS})
97 find_program(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 qmake-mac)
98 find_package(Qt4 REQUIRED QtCore QtGui QtSvg)
102 find_package(Boost 1.48 COMPONENTS filesystem system thread unit_test_framework REQUIRED)
104 find_package(Boost 1.48 COMPONENTS filesystem system thread REQUIRED)
107 # Find the platform's thread library (needed for C++11 threads).
108 # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
109 find_package(Threads REQUIRED)
111 #===============================================================================
112 #= System Introspection
113 #-------------------------------------------------------------------------------
116 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
118 #===============================================================================
120 #-------------------------------------------------------------------------------
122 set(PV_TITLE PulseView)
123 set(PV_DESCRIPTION "A GUI for sigrok")
124 set(PV_VERSION_STRING "0.3.0")
126 include(GetGitRevisionDescription)
128 # Append the revision hash unless we are exactly on a tagged release.
129 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
130 if(NOT PV_TAG_VERSION_STRING)
131 get_git_head_revision(PV_REVSPEC PV_HASH)
133 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
134 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
138 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
139 set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
140 set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
141 set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
142 set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
145 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
148 ${PROJECT_SOURCE_DIR}/config.h.in
149 ${PROJECT_BINARY_DIR}/config.h
152 #===============================================================================
154 #-------------------------------------------------------------------------------
156 set(pulseview_SOURCES
164 pv/binding/binding.cpp
165 pv/binding/inputoutput.cpp
166 pv/binding/device.cpp
168 pv/data/analogsegment.cpp
170 pv/data/logicsegment.cpp
171 pv/data/signaldata.cpp
173 pv/devices/device.cpp
175 pv/devices/hardwaredevice.cpp
176 pv/devices/inputfile.cpp
177 pv/devices/sessionfile.cpp
179 pv/dialogs/connect.cpp
180 pv/dialogs/inputoutputoptions.cpp
181 pv/dialogs/storeprogress.cpp
182 pv/popups/deviceoptions.cpp
183 pv/popups/channels.cpp
190 pv/toolbars/mainbar.cpp
191 pv/view/analogsignal.cpp
193 pv/view/cursorpair.cpp
196 pv/view/marginwidget.cpp
197 pv/view/logicsignal.cpp
201 pv/view/signalscalehandle.cpp
203 pv/view/timemarker.cpp
205 pv/view/tracegroup.cpp
206 pv/view/tracepalette.cpp
207 pv/view/tracetreeitem.cpp
208 pv/view/tracetreeitemowner.cpp
211 pv/view/viewitemowner.cpp
212 pv/view/viewitempaintparams.cpp
214 pv/view/viewwidget.cpp
215 pv/widgets/colourbutton.cpp
216 pv/widgets/colourpopup.cpp
217 pv/widgets/devicetoolbutton.cpp
218 pv/widgets/exportmenu.cpp
219 pv/widgets/hidingmenubar.cpp
220 pv/widgets/importmenu.cpp
222 pv/widgets/popuptoolbutton.cpp
223 pv/widgets/sweeptimingwidget.cpp
224 pv/widgets/timestampspinbox.cpp
225 pv/widgets/wellarray.cpp
228 # This list includes only QObject derived class headers.
229 set(pulseview_HEADERS
233 pv/binding/device.hpp
235 pv/dialogs/connect.hpp
236 pv/dialogs/inputoutputoptions.hpp
237 pv/dialogs/storeprogress.hpp
238 pv/popups/channels.hpp
239 pv/popups/deviceoptions.hpp
246 pv/toolbars/mainbar.hpp
250 pv/view/logicsignal.hpp
251 pv/view/marginwidget.hpp
255 pv/view/signalscalehandle.hpp
257 pv/view/timemarker.hpp
259 pv/view/tracegroup.hpp
260 pv/view/tracetreeitem.hpp
264 pv/view/viewwidget.hpp
265 pv/widgets/colourbutton.hpp
266 pv/widgets/colourpopup.hpp
267 pv/widgets/devicetoolbutton.hpp
268 pv/widgets/exportmenu.hpp
269 pv/widgets/hidingmenubar.hpp
270 pv/widgets/importmenu.hpp
272 pv/widgets/popuptoolbutton.hpp
273 pv/widgets/sweeptimingwidget.hpp
274 pv/widgets/timestampspinbox.hpp
275 pv/widgets/wellarray.hpp
282 set(pulseview_RESOURCES
287 list(APPEND pulseview_SOURCES signalhandler.cpp)
288 list(APPEND pulseview_HEADERS signalhandler.hpp)
292 list(APPEND pulseview_SOURCES
293 pv/binding/decoder.cpp
294 pv/data/decoderstack.cpp
295 pv/data/decode/annotation.cpp
296 pv/data/decode/decoder.cpp
297 pv/data/decode/row.cpp
298 pv/data/decode/rowdata.cpp
299 pv/view/decodetrace.cpp
300 pv/widgets/decodergroupbox.cpp
301 pv/widgets/decodermenu.cpp
304 list(APPEND pulseview_HEADERS
305 pv/data/decoderstack.hpp
306 pv/view/decodetrace.hpp
307 pv/widgets/decodergroupbox.hpp
308 pv/widgets/decodermenu.hpp
313 # Use the sigrok icon for the pulseview.exe executable.
314 set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
316 list(APPEND pulseview_SOURCES pulseviewico.rc)
320 list(APPEND pulseview_SOURCES
321 android/assetreader.cpp
322 android/loghandler.cpp
327 qt5_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS})
328 qt5_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
329 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
331 # Workaroud for QTBUG-22829: -DBOOST_NEXT_PRIOR_HPP_INCLUDED.
332 # https://bugreports.qt.io/browse/QTBUG-22829
333 qt4_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS}
334 OPTIONS -DBOOST_NEXT_PRIOR_HPP_INCLUDED)
335 qt4_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
336 qt4_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
337 include(${QT_USE_FILE})
340 #===============================================================================
341 #= Global Definitions
342 #-------------------------------------------------------------------------------
344 add_definitions(${QT_DEFINITIONS} -DQT_NO_KEYWORDS)
345 add_definitions(-D__STDC_LIMIT_MACROS)
346 add_definitions(-Wall -Wextra)
347 add_definitions(-std=c++11)
350 add_definitions(-DENABLE_DECODE)
353 if(NOT DISABLE_WERROR)
354 add_definitions(-Werror)
358 add_definitions(-DENABLE_SIGNALS)
361 #===============================================================================
362 #= Global Include Directories
363 #-------------------------------------------------------------------------------
366 ${CMAKE_CURRENT_BINARY_DIR}
367 ${CMAKE_CURRENT_SOURCE_DIR}
368 ${Boost_INCLUDE_DIRS}
372 if(STATIC_PKGDEPS_LIBS)
373 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
375 include_directories(${PKGDEPS_INCLUDE_DIRS})
378 #===============================================================================
379 #= Linker Configuration
380 #-------------------------------------------------------------------------------
382 link_directories(${Boost_LIBRARY_DIRS})
384 set(PULSEVIEW_LINK_LIBS
387 ${CMAKE_THREAD_LIBS_INIT}
390 if(STATIC_PKGDEPS_LIBS)
391 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
392 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LIBRARIES})
394 # Workaround for a MinGW linking issue.
395 list(APPEND PULSEVIEW_LINK_LIBS "-llzma -llcms2")
398 link_directories(${PKGDEPS_LIBRARY_DIRS})
399 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
403 # On Windows we need to statically link the libqsvg imageformat
404 # plugin (and the QtSvg component) for SVG graphics/icons to work.
405 add_definitions(-DQT_STATICPLUGIN)
406 link_directories("${QT_PLUGINS_DIR}/imageformats")
407 list(APPEND PULSEVIEW_LINK_LIBS "-lqsvg")
408 list(APPEND PULSEVIEW_LINK_LIBS ${QT_QTSVG_LIBRARY})
412 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
416 add_library(${PROJECT_NAME} SHARED
418 ${pulseview_HEADERS_MOC}
419 ${pulseview_FORMS_HEADERS}
420 ${pulseview_RESOURCES_RCC}
423 add_executable(${PROJECT_NAME}
425 ${pulseview_HEADERS_MOC}
426 ${pulseview_FORMS_HEADERS}
427 ${pulseview_RESOURCES_RCC}
431 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
434 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
435 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
438 #===============================================================================
440 #-------------------------------------------------------------------------------
442 # Install the executable.
443 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
445 # Install the manpage.
446 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
448 # Generate Windows installer script.
449 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
451 #===============================================================================
452 #= Packaging (handled by CPack)
453 #-------------------------------------------------------------------------------
455 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
456 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
457 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
458 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
459 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
460 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
461 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
462 set(CPACK_SOURCE_GENERATOR "TGZ")
466 #===============================================================================
468 #-------------------------------------------------------------------------------
471 add_subdirectory(test)
473 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)