]> sigrok.org Git - pulseview.git/blame_incremental - CMakeLists.txt
Segment: Move definition of MaxChunkSize
[pulseview.git] / CMakeLists.txt
... / ...
CommitLineData
1##
2## This file is part of the PulseView project.
3##
4## Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5## Copyright (C) 2012-2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
6##
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.
11##
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.
16##
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/>.
19##
20
21cmake_minimum_required(VERSION 2.8.6)
22
23include(GNUInstallDirs)
24
25project(pulseview)
26
27list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
28
29#===============================================================================
30#= User Options
31#-------------------------------------------------------------------------------
32
33option(DISABLE_WERROR "Build without -Werror" FALSE)
34option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
35option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
36option(ENABLE_TESTS "Enable unit tests" TRUE)
37option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
38option(FORCE_QT4 "Force use of Qt4 even if Qt5 is available" FALSE)
39
40if(WIN32)
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)
44
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)
48
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)
52
53 # Windows does not support UNIX signals.
54 set(ENABLE_SIGNALS FALSE)
55endif()
56
57if(NOT CMAKE_BUILD_TYPE)
58 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
59 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
60 FORCE)
61endif()
62
63#===============================================================================
64#= Dependencies
65#-------------------------------------------------------------------------------
66
67list(APPEND PKGDEPS libsigrokcxx>=0.4.0)
68
69if(ENABLE_DECODE)
70 list(APPEND PKGDEPS libsigrokdecode>=0.4.0)
71endif()
72
73if(ANDROID)
74 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
75endif()
76
77find_package(PkgConfig)
78pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
79
80if(FORCE_QT4)
81 set(Qt5Core_FOUND FALSE)
82else()
83 find_package(Qt5Core QUIET)
84if(WIN32)
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)
88endif()
89endif()
90
91if(Qt5Core_FOUND)
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})
100else()
101 find_program(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 qmake-mac)
102 find_package(Qt4 REQUIRED QtCore QtGui QtSvg)
103endif()
104
105set(BOOSTCOMPS filesystem serialization system thread)
106if(ENABLE_TESTS)
107 list(APPEND BOOSTCOMPS unit_test_framework)
108endif()
109find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
110
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.
113find_package(Threads REQUIRED)
114
115
116# Check for explicit link against libatomic
117#
118# Depending on the toolchain, linking a program using atomic functions may need
119# "-latomic" explicitly passed to the linker
120#
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
123# linker flags.
124
125# Helper for checking for atomics
126function(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("
134#include <atomic>
135std::atomic<int> x;
136int main() {
137 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
138}
139" ${varname})
140 cmake_pop_check_state()
141endfunction(check_working_cxx_atomics)
142
143# First check if atomics work without the library.
144# If not, check if the library exists, and atomics work with it.
145check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
146if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
147 message(STATUS "Atomics provided by the C-library - yes")
148else()
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")
155 else()
156 message(STATUS "Atomics provided by libatomic - no")
157 message(FATAL_ERROR "Compiler must support std::atomic!")
158 endif()
159 else()
160 message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
161 endif()
162endif()
163
164#===============================================================================
165#= System Introspection
166#-------------------------------------------------------------------------------
167
168include(memaccess)
169memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
170
171#===============================================================================
172#= Config Header
173#-------------------------------------------------------------------------------
174
175set(PV_TITLE PulseView)
176set(PV_DESCRIPTION "A GUI for sigrok")
177set(PV_VERSION_STRING "0.4.0")
178
179include(GetGitRevisionDescription)
180
181# Append the revision hash unless we are exactly on a tagged release.
182git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
183if(NOT PV_TAG_VERSION_STRING)
184 get_git_head_revision(PV_REVSPEC PV_HASH)
185 if(PV_HASH)
186 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
187 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
188 endif()
189endif()
190
191if(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})
196endif()
197
198message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
199
200configure_file (
201 ${PROJECT_SOURCE_DIR}/config.h.in
202 ${PROJECT_BINARY_DIR}/config.h
203)
204
205#===============================================================================
206#= Sources
207#-------------------------------------------------------------------------------
208
209set(pulseview_SOURCES
210 main.cpp
211 pv/application.cpp
212 pv/devicemanager.cpp
213 pv/mainwindow.cpp
214 pv/session.cpp
215 pv/storesession.cpp
216 pv/util.cpp
217 pv/binding/binding.cpp
218 pv/binding/inputoutput.cpp
219 pv/binding/device.cpp
220 pv/data/analog.cpp
221 pv/data/analogsegment.cpp
222 pv/data/logic.cpp
223 pv/data/logicsegment.cpp
224 pv/data/signalbase.cpp
225 pv/data/signaldata.cpp
226 pv/data/segment.cpp
227 pv/devices/device.cpp
228 pv/devices/file.cpp
229 pv/devices/hardwaredevice.cpp
230 pv/devices/inputfile.cpp
231 pv/devices/sessionfile.cpp
232 pv/dialogs/about.cpp
233 pv/dialogs/connect.cpp
234 pv/dialogs/inputoutputoptions.cpp
235 pv/dialogs/storeprogress.cpp
236 pv/popups/deviceoptions.cpp
237 pv/popups/channels.cpp
238 pv/prop/bool.cpp
239 pv/prop/double.cpp
240 pv/prop/enum.cpp
241 pv/prop/int.cpp
242 pv/prop/property.cpp
243 pv/prop/string.cpp
244 pv/toolbars/mainbar.cpp
245 pv/view/analogsignal.cpp
246 pv/view/cursor.cpp
247 pv/view/cursorpair.cpp
248 pv/view/flag.cpp
249 pv/view/header.cpp
250 pv/view/marginwidget.cpp
251 pv/view/logicsignal.cpp
252 pv/view/rowitem.cpp
253 pv/view/ruler.cpp
254 pv/view/signal.cpp
255 pv/view/signalscalehandle.cpp
256 pv/view/timeitem.cpp
257 pv/view/timemarker.cpp
258 pv/view/trace.cpp
259 pv/view/tracegroup.cpp
260 pv/view/tracepalette.cpp
261 pv/view/tracetreeitem.cpp
262 pv/view/tracetreeitemowner.cpp
263 pv/view/triggermarker.cpp
264 pv/view/view.cpp
265 pv/view/viewitem.cpp
266 pv/view/viewitemowner.cpp
267 pv/view/viewitempaintparams.cpp
268 pv/view/viewport.cpp
269 pv/view/viewwidget.cpp
270 pv/views/viewbase.cpp
271 pv/views/trace/standardbar.cpp
272 pv/widgets/colourbutton.cpp
273 pv/widgets/colourpopup.cpp
274 pv/widgets/devicetoolbutton.cpp
275 pv/widgets/exportmenu.cpp
276 pv/widgets/importmenu.cpp
277 pv/widgets/popup.cpp
278 pv/widgets/popuptoolbutton.cpp
279 pv/widgets/sweeptimingwidget.cpp
280 pv/widgets/timestampspinbox.cpp
281 pv/widgets/wellarray.cpp
282)
283
284# This list includes only QObject derived class headers.
285set(pulseview_HEADERS
286 pv/mainwindow.hpp
287 pv/session.hpp
288 pv/storesession.hpp
289 pv/binding/device.hpp
290 pv/data/analog.hpp
291 pv/data/analogsegment.hpp
292 pv/data/logic.hpp
293 pv/data/logicsegment.hpp
294 pv/data/signalbase.hpp
295 pv/dialogs/about.hpp
296 pv/dialogs/connect.hpp
297 pv/dialogs/inputoutputoptions.hpp
298 pv/dialogs/storeprogress.hpp
299 pv/popups/channels.hpp
300 pv/popups/deviceoptions.hpp
301 pv/prop/bool.hpp
302 pv/prop/double.hpp
303 pv/prop/enum.hpp
304 pv/prop/int.hpp
305 pv/prop/property.hpp
306 pv/prop/string.hpp
307 pv/toolbars/mainbar.hpp
308 pv/view/analogsignal.hpp
309 pv/view/cursor.hpp
310 pv/view/flag.hpp
311 pv/view/header.hpp
312 pv/view/logicsignal.hpp
313 pv/view/marginwidget.hpp
314 pv/view/rowitem.hpp
315 pv/view/ruler.hpp
316 pv/view/signal.hpp
317 pv/view/signalscalehandle.hpp
318 pv/view/timeitem.hpp
319 pv/view/timemarker.hpp
320 pv/view/trace.hpp
321 pv/view/tracegroup.hpp
322 pv/view/tracetreeitem.hpp
323 pv/view/triggermarker.hpp
324 pv/view/view.hpp
325 pv/view/viewitem.hpp
326 pv/view/viewport.hpp
327 pv/view/viewwidget.hpp
328 pv/views/viewbase.hpp
329 pv/views/trace/standardbar.hpp
330 pv/widgets/colourbutton.hpp
331 pv/widgets/colourpopup.hpp
332 pv/widgets/devicetoolbutton.hpp
333 pv/widgets/exportmenu.hpp
334 pv/widgets/importmenu.hpp
335 pv/widgets/popup.hpp
336 pv/widgets/popuptoolbutton.hpp
337 pv/widgets/sweeptimingwidget.hpp
338 pv/widgets/timestampspinbox.hpp
339 pv/widgets/wellarray.hpp
340)
341
342set(pulseview_FORMS
343 pv/dialogs/about.ui
344)
345
346set(pulseview_RESOURCES
347 pulseview.qrc
348)
349
350if(ENABLE_SIGNALS)
351 list(APPEND pulseview_SOURCES signalhandler.cpp)
352 list(APPEND pulseview_HEADERS signalhandler.hpp)
353endif()
354
355if(ENABLE_DECODE)
356 list(APPEND pulseview_SOURCES
357 pv/binding/decoder.cpp
358 pv/data/decoderstack.cpp
359 pv/data/decode/annotation.cpp
360 pv/data/decode/decoder.cpp
361 pv/data/decode/row.cpp
362 pv/data/decode/rowdata.cpp
363 pv/view/decodetrace.cpp
364 pv/widgets/decodergroupbox.cpp
365 pv/widgets/decodermenu.cpp
366 )
367
368 list(APPEND pulseview_HEADERS
369 pv/data/decoderstack.hpp
370 pv/view/decodetrace.hpp
371 pv/widgets/decodergroupbox.hpp
372 pv/widgets/decodermenu.hpp
373 )
374endif()
375
376if(WIN32)
377 # Use the sigrok icon for the pulseview.exe executable.
378 set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
379 enable_language(RC)
380 list(APPEND pulseview_SOURCES pulseviewico.rc)
381endif()
382
383if(ANDROID)
384 list(APPEND pulseview_SOURCES
385 android/assetreader.cpp
386 android/loghandler.cpp
387 )
388endif()
389
390if(Qt5Core_FOUND)
391 qt5_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS})
392 qt5_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
393 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
394else()
395 # Workaround for QTBUG-22829: -DBOOST_NEXT_PRIOR_HPP_INCLUDED.
396 # https://bugreports.qt.io/browse/QTBUG-22829
397 qt4_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS}
398 OPTIONS -DBOOST_NEXT_PRIOR_HPP_INCLUDED)
399 qt4_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
400 qt4_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
401 include(${QT_USE_FILE})
402endif()
403
404#===============================================================================
405#= Global Definitions
406#-------------------------------------------------------------------------------
407
408add_definitions(${QT_DEFINITIONS} -DQT_NO_KEYWORDS)
409add_definitions(-D__STDC_LIMIT_MACROS)
410add_definitions(-Wall -Wextra)
411add_definitions(-std=c++11)
412add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
413
414if(ENABLE_DECODE)
415 add_definitions(-DENABLE_DECODE)
416endif()
417
418if(NOT DISABLE_WERROR)
419 add_definitions(-Werror)
420endif()
421
422if(ENABLE_SIGNALS)
423 add_definitions(-DENABLE_SIGNALS)
424endif()
425
426#===============================================================================
427#= Global Include Directories
428#-------------------------------------------------------------------------------
429
430include_directories(
431 ${CMAKE_CURRENT_BINARY_DIR}
432 ${CMAKE_CURRENT_SOURCE_DIR}
433 ${Boost_INCLUDE_DIRS}
434 ${QT_INCLUDE_DIRS}
435)
436
437if(STATIC_PKGDEPS_LIBS)
438 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
439else()
440 include_directories(${PKGDEPS_INCLUDE_DIRS})
441endif()
442
443#===============================================================================
444#= Linker Configuration
445#-------------------------------------------------------------------------------
446
447link_directories(${Boost_LIBRARY_DIRS})
448
449set(PULSEVIEW_LINK_LIBS
450 ${Boost_LIBRARIES}
451 ${QT_LIBRARIES}
452 ${CMAKE_THREAD_LIBS_INIT}
453 ${LIBATOMIC_LIBRARY}
454)
455
456if(STATIC_PKGDEPS_LIBS)
457 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
458 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
459else()
460 link_directories(${PKGDEPS_LIBRARY_DIRS})
461 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
462endif()
463
464if(WIN32)
465 # On Windows we need to statically link the libqsvg imageformat
466 # plugin (and the QtSvg component) for SVG graphics/icons to work.
467 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport, and all
468 # Qt libs and their dependencies.
469 add_definitions(-DQT_STATICPLUGIN)
470 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
471 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
472 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport ${QT5ALL_LDFLAGS})
473endif()
474
475if(ANDROID)
476 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
477endif()
478
479if(ANDROID)
480add_library(${PROJECT_NAME} SHARED
481 ${pulseview_SOURCES}
482 ${pulseview_HEADERS_MOC}
483 ${pulseview_FORMS_HEADERS}
484 ${pulseview_RESOURCES_RCC}
485)
486else()
487add_executable(${PROJECT_NAME}
488 ${pulseview_SOURCES}
489 ${pulseview_HEADERS_MOC}
490 ${pulseview_FORMS_HEADERS}
491 ${pulseview_RESOURCES_RCC}
492)
493endif()
494
495target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
496
497if(WIN32)
498 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
499 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
500endif()
501
502#===============================================================================
503#= Installation
504#-------------------------------------------------------------------------------
505
506# Install the executable.
507install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
508
509# Install the manpage.
510install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
511
512# Generate Windows installer script.
513configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
514
515#===============================================================================
516#= Packaging (handled by CPack)
517#-------------------------------------------------------------------------------
518
519set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
520set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
521set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
522set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
523set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
524set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
525set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
526set(CPACK_SOURCE_GENERATOR "TGZ")
527
528include(CPack)
529
530#===============================================================================
531#= Tests
532#-------------------------------------------------------------------------------
533
534if(ENABLE_TESTS)
535 add_subdirectory(test)
536 enable_testing()
537 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
538endif()