]> sigrok.org Git - pulseview.git/blame_incremental - CMakeLists.txt
cmake: Don't do a QUIET search for libsigrokcxx
[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.12)
22
23include(GNUInstallDirs)
24
25project(pulseview)
26
27# Let AUTOMOC and AUTOUIC process GENERATED files.
28if(POLICY CMP0071)
29 cmake_policy(SET CMP0071 NEW)
30endif()
31
32# Only interpret if() arguments as variables or keywords when unquoted.
33if(POLICY CMP0054)
34 cmake_policy(SET CMP0054 NEW)
35endif()
36
37list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
38
39#===============================================================================
40#= User Options
41#-------------------------------------------------------------------------------
42
43option(DISABLE_WERROR "Build without -Werror" TRUE)
44option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
45option(ENABLE_STACKTRACE "Enable stack trace when crashing" FALSE)
46option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
47option(ENABLE_TESTS "Enable unit tests" FALSE)
48option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
49
50if(WIN32)
51 # On Windows/MinGW we need to statically link to libraries.
52 # This option is user configurable, but enable it by default on win32.
53 set(STATIC_PKGDEPS_LIBS TRUE)
54
55 # Windows does not support UNIX signals.
56 set(ENABLE_SIGNALS FALSE)
57endif()
58
59if(NOT CMAKE_BUILD_TYPE)
60 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
61 "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
62 FORCE)
63endif()
64
65#===============================================================================
66#= Documentation
67#-------------------------------------------------------------------------------
68
69add_subdirectory(manual)
70
71#===============================================================================
72#= Dependencies
73#-------------------------------------------------------------------------------
74
75list(APPEND PKGDEPS glib-2.0>=2.28.0)
76list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
77
78set(LIBSR_CXX_BINDING "libsigrokcxx>=0.5.1")
79list(APPEND PKGDEPS "${LIBSR_CXX_BINDING}")
80
81if(ENABLE_DECODE)
82 list(APPEND PKGDEPS libsigrokdecode>=0.5.2)
83endif()
84
85if(ANDROID)
86 list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
87endif()
88
89find_package(PkgConfig)
90pkg_check_modules(LIBSRCXX ${LIBSR_CXX_BINDING})
91if(NOT LIBSRCXX_FOUND OR NOT LIBSRCXX_VERSION)
92 message(FATAL_ERROR "libsigrok C++ bindings missing, check libsigrok's 'configure' output (missing dependencies?)")
93endif()
94pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
95
96set(CMAKE_AUTOMOC TRUE)
97
98find_package(Qt5 COMPONENTS Core Gui Widgets Svg REQUIRED)
99
100if(WIN32)
101 # MXE workaround: Use pkg-config to find Qt5 libs.
102 # https://github.com/mxe/mxe/issues/1642
103 # Not required (and doesn't work) on MSYS2.
104 if(NOT DEFINED ENV{MSYSTEM})
105 pkg_check_modules(QT5ALL REQUIRED Qt5Widgets Qt5Gui Qt5Svg)
106 endif()
107endif()
108
109set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
110
111set(BOOSTCOMPS filesystem serialization system)
112if(ENABLE_TESTS)
113 list(APPEND BOOSTCOMPS unit_test_framework)
114endif()
115
116if(ENABLE_STACKTRACE)
117 find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
118else()
119 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
120endif()
121
122# Find the platform's thread library (needed for C++11 threads).
123# This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
124find_package(Threads REQUIRED)
125
126# Check for explicit link against libatomic
127#
128# Depending on the toolchain, linking a program using atomic functions may need
129# "-latomic" explicitly passed to the linker
130#
131# This check first tests if atomics are available in the C-library, if not and
132# libatomic exists, then it runs the same test with -latomic added to the
133# linker flags.
134
135# Helper for checking for atomics
136function(check_working_cxx_atomics varname additional_lib)
137 include(CheckCXXSourceCompiles)
138 include(CMakePushCheckState)
139 cmake_push_check_state()
140 set(CMAKE_REQUIRED_FLAGS "-std=c++11")
141 set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
142 set(CMAKE_REQUIRED_QUIET 1)
143 CHECK_CXX_SOURCE_COMPILES("
144#include <atomic>
145std::atomic<int> x;
146int main() {
147 return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
148}
149" ${varname})
150 cmake_pop_check_state()
151endfunction(check_working_cxx_atomics)
152
153# First check if atomics work without the library.
154# If not, check if the library exists, and atomics work with it.
155check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
156if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
157 message(STATUS "Atomics provided by the C-library - yes")
158else()
159 message(STATUS "Atomics provided by the C-library - no")
160 find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
161 if(LIBATOMIC_LIBRARY)
162 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
163 if (HAVE_CXX_ATOMICS_WITH_LIB)
164 message(STATUS "Atomics provided by libatomic - yes")
165 else()
166 message(STATUS "Atomics provided by libatomic - no")
167 message(FATAL_ERROR "Compiler must support std::atomic!")
168 endif()
169 else()
170 message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
171 endif()
172endif()
173
174#===============================================================================
175#= System Introspection
176#-------------------------------------------------------------------------------
177
178include(memaccess)
179memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
180
181#===============================================================================
182#= Config Header
183#-------------------------------------------------------------------------------
184
185set(PV_TITLE PulseView)
186set(PV_VERSION_STRING "0.5.0")
187
188set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
189
190include(GetGitRevisionDescription)
191
192# Append the revision hash unless we are exactly on a tagged release.
193git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
194if(NOT PV_TAG_VERSION_STRING)
195 get_git_head_revision(PV_REVSPEC PV_HASH)
196 if(PV_HASH)
197 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
198 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
199 endif()
200
201 # Non-tagged releases use the unstable manual
202 set(PV_MANUAL_VERSION "unstable")
203else()
204 # Tagged releases use a fixed manual version
205 set(PV_MANUAL_VERSION ${PV_VERSION_STRING})
206endif()
207
208if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
209 set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
210 set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
211 set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
212 set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
213endif()
214
215message(STATUS "${PV_TITLE} version: ${PV_VERSION_STRING}")
216
217configure_file (
218 ${PROJECT_SOURCE_DIR}/config.h.in
219 ${PROJECT_BINARY_DIR}/config.h
220)
221
222#===============================================================================
223#= Sources
224#-------------------------------------------------------------------------------
225
226set(pulseview_SOURCES
227 main.cpp
228 pv/application.cpp
229 pv/devicemanager.cpp
230 pv/globalsettings.cpp
231 pv/logging.cpp
232 pv/mainwindow.cpp
233 pv/session.cpp
234 pv/storesession.cpp
235 pv/util.cpp
236 pv/binding/binding.cpp
237 pv/binding/inputoutput.cpp
238 pv/binding/device.cpp
239 pv/data/analog.cpp
240 pv/data/analogsegment.cpp
241 pv/data/logic.cpp
242 pv/data/logicsegment.cpp
243 pv/data/signalbase.cpp
244 pv/data/signaldata.cpp
245 pv/data/segment.cpp
246 pv/devices/device.cpp
247 pv/devices/file.cpp
248 pv/devices/hardwaredevice.cpp
249 pv/devices/inputfile.cpp
250 pv/devices/sessionfile.cpp
251 pv/dialogs/connect.cpp
252 pv/dialogs/inputoutputoptions.cpp
253 pv/dialogs/settings.cpp
254 pv/dialogs/storeprogress.cpp
255 pv/popups/deviceoptions.cpp
256 pv/popups/channels.cpp
257 pv/prop/bool.cpp
258 pv/prop/double.cpp
259 pv/prop/enum.cpp
260 pv/prop/int.cpp
261 pv/prop/property.cpp
262 pv/prop/string.cpp
263 pv/toolbars/mainbar.cpp
264 pv/views/trace/analogsignal.cpp
265 pv/views/trace/cursor.cpp
266 pv/views/trace/cursorpair.cpp
267 pv/views/trace/flag.cpp
268 pv/views/trace/header.cpp
269 pv/views/trace/marginwidget.cpp
270 pv/views/trace/logicsignal.cpp
271 pv/views/trace/rowitem.cpp
272 pv/views/trace/ruler.cpp
273 pv/views/trace/signal.cpp
274 pv/views/trace/timeitem.cpp
275 pv/views/trace/timemarker.cpp
276 pv/views/trace/trace.cpp
277 pv/views/trace/tracegroup.cpp
278 pv/views/trace/tracepalette.cpp
279 pv/views/trace/tracetreeitem.cpp
280 pv/views/trace/tracetreeitemowner.cpp
281 pv/views/trace/triggermarker.cpp
282 pv/views/trace/view.cpp
283 pv/views/trace/viewitem.cpp
284 pv/views/trace/viewitemowner.cpp
285 pv/views/trace/viewitempaintparams.cpp
286 pv/views/trace/viewport.cpp
287 pv/views/trace/viewwidget.cpp
288 pv/views/viewbase.cpp
289 pv/views/trace/standardbar.cpp
290 pv/widgets/colorbutton.cpp
291 pv/widgets/colorpopup.cpp
292 pv/widgets/devicetoolbutton.cpp
293 pv/widgets/exportmenu.cpp
294 pv/widgets/importmenu.cpp
295 pv/widgets/popup.cpp
296 pv/widgets/popuptoolbutton.cpp
297 pv/widgets/sweeptimingwidget.cpp
298 pv/widgets/timestampspinbox.cpp
299 pv/widgets/wellarray.cpp
300)
301
302# This list includes only QObject derived class headers.
303set(pulseview_HEADERS
304 pv/logging.hpp
305 pv/globalsettings.hpp
306 pv/mainwindow.hpp
307 pv/session.hpp
308 pv/storesession.hpp
309 pv/binding/device.hpp
310 pv/data/analog.hpp
311 pv/data/analogsegment.hpp
312 pv/data/logic.hpp
313 pv/data/logicsegment.hpp
314 pv/data/signalbase.hpp
315 pv/dialogs/connect.hpp
316 pv/dialogs/inputoutputoptions.hpp
317 pv/dialogs/settings.hpp
318 pv/dialogs/storeprogress.hpp
319 pv/popups/channels.hpp
320 pv/popups/deviceoptions.hpp
321 pv/prop/bool.hpp
322 pv/prop/double.hpp
323 pv/prop/enum.hpp
324 pv/prop/int.hpp
325 pv/prop/property.hpp
326 pv/prop/string.hpp
327 pv/toolbars/mainbar.hpp
328 pv/views/trace/analogsignal.hpp
329 pv/views/trace/cursor.hpp
330 pv/views/trace/flag.hpp
331 pv/views/trace/header.hpp
332 pv/views/trace/logicsignal.hpp
333 pv/views/trace/marginwidget.hpp
334 pv/views/trace/rowitem.hpp
335 pv/views/trace/ruler.hpp
336 pv/views/trace/signal.hpp
337 pv/views/trace/timeitem.hpp
338 pv/views/trace/timemarker.hpp
339 pv/views/trace/trace.hpp
340 pv/views/trace/tracegroup.hpp
341 pv/views/trace/tracetreeitem.hpp
342 pv/views/trace/triggermarker.hpp
343 pv/views/trace/view.hpp
344 pv/views/trace/viewitem.hpp
345 pv/views/trace/viewport.hpp
346 pv/views/trace/viewwidget.hpp
347 pv/views/viewbase.hpp
348 pv/views/trace/standardbar.hpp
349 pv/widgets/colorbutton.hpp
350 pv/widgets/colorpopup.hpp
351 pv/widgets/devicetoolbutton.hpp
352 pv/widgets/exportmenu.hpp
353 pv/widgets/importmenu.hpp
354 pv/widgets/popup.hpp
355 pv/widgets/popuptoolbutton.hpp
356 pv/widgets/sweeptimingwidget.hpp
357 pv/widgets/timestampspinbox.hpp
358 pv/widgets/wellarray.hpp
359)
360
361set(pulseview_RESOURCES
362 pulseview.qrc
363)
364
365if(ENABLE_SIGNALS)
366 list(APPEND pulseview_SOURCES signalhandler.cpp)
367 list(APPEND pulseview_HEADERS signalhandler.hpp)
368endif()
369
370if(ENABLE_DECODE)
371 list(APPEND pulseview_SOURCES
372 pv/binding/decoder.cpp
373 pv/data/decodesignal.cpp
374 pv/data/decode/annotation.cpp
375 pv/data/decode/decoder.cpp
376 pv/data/decode/row.cpp
377 pv/data/decode/rowdata.cpp
378 pv/views/trace/decodetrace.cpp
379 pv/widgets/decodergroupbox.cpp
380 pv/widgets/decodermenu.cpp
381 )
382
383 list(APPEND pulseview_HEADERS
384 pv/data/decodesignal.hpp
385 pv/views/trace/decodetrace.hpp
386 pv/widgets/decodergroupbox.hpp
387 pv/widgets/decodermenu.hpp
388 )
389endif()
390
391if(WIN32)
392 # Use the sigrok icon for the pulseview.exe executable.
393 set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
394 enable_language(RC)
395 list(APPEND pulseview_SOURCES pulseviewico.rc)
396endif()
397
398if(ANDROID)
399 list(APPEND pulseview_SOURCES
400 android/assetreader.cpp
401 android/loghandler.cpp
402 )
403endif()
404
405qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
406
407#===============================================================================
408#= Global Definitions
409#-------------------------------------------------------------------------------
410
411add_definitions(-DQT_NO_KEYWORDS)
412add_definitions(-D__STDC_LIMIT_MACROS)
413add_definitions(-Wall -Wextra)
414add_definitions(-std=c++11)
415add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
416
417if(ENABLE_DECODE)
418 add_definitions(-DENABLE_DECODE)
419endif()
420
421if(NOT DISABLE_WERROR)
422 add_definitions(-Werror)
423endif()
424
425if(ENABLE_SIGNALS)
426 add_definitions(-DENABLE_SIGNALS)
427endif()
428
429if(ENABLE_STACKTRACE)
430 add_definitions(-DENABLE_STACKTRACE)
431endif()
432
433#===============================================================================
434#= Global Include Directories
435#-------------------------------------------------------------------------------
436
437include_directories(
438 ${CMAKE_CURRENT_BINARY_DIR}
439 ${CMAKE_CURRENT_SOURCE_DIR}
440 ${Boost_INCLUDE_DIRS}
441)
442
443if(STATIC_PKGDEPS_LIBS)
444 include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
445else()
446 include_directories(${PKGDEPS_INCLUDE_DIRS})
447endif()
448
449#===============================================================================
450#= Linker Configuration
451#-------------------------------------------------------------------------------
452
453link_directories(${Boost_LIBRARY_DIRS})
454
455set(PULSEVIEW_LINK_LIBS
456 ${Boost_LIBRARIES}
457 ${QT_LIBRARIES}
458 ${CMAKE_THREAD_LIBS_INIT}
459 ${LIBATOMIC_LIBRARY}
460)
461
462if(STATIC_PKGDEPS_LIBS)
463 link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
464 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
465else()
466 link_directories(${PKGDEPS_LIBRARY_DIRS})
467 list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
468endif()
469
470if(WIN32)
471 # On Windows we need to statically link the libqsvg imageformat
472 # plugin (and the QtSvg component) for SVG graphics/icons to work.
473 # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport (only for
474 # Qt < 5.8.0), and all Qt libs and their dependencies.
475 add_definitions(-DQT_STATICPLUGIN)
476 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
477 list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
478 if(Qt5Gui_VERSION VERSION_LESS 5.8.0)
479 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport)
480 endif()
481 list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
482endif()
483
484if(ENABLE_STACKTRACE)
485 # Needed to resolve dladdr.
486 list(APPEND PULSEVIEW_LINK_LIBS "-ldl")
487endif()
488
489if(ANDROID)
490 list(APPEND PULSEVIEW_LINK_LIBS "-llog")
491endif()
492
493if(ANDROID)
494 add_library(${PROJECT_NAME} SHARED ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
495else()
496 add_executable(${PROJECT_NAME} ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
497endif()
498
499target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
500
501if(WIN32 AND NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
502 # Pass -mwindows so that no "DOS box" opens when PulseView is started.
503 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
504endif()
505
506#===============================================================================
507#= Installation
508#-------------------------------------------------------------------------------
509
510# Install the executable.
511install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
512
513# Install the manpage.
514install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
515
516# Install the desktop file.
517install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
518
519# Install the AppData/AppStream file.
520install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
521
522# Install the PulseView icons.
523install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
524install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
525
526# Generate Windows installer script.
527configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
528
529#===============================================================================
530#= Packaging (handled by CPack)
531#-------------------------------------------------------------------------------
532
533set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
534set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
535set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
536set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
537set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
538set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
539set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
540set(CPACK_SOURCE_GENERATOR "TGZ")
541
542include(CPack)
543
544#===============================================================================
545#= Tests
546#-------------------------------------------------------------------------------
547
548if(ENABLE_TESTS)
549 add_subdirectory(test)
550 enable_testing()
551 add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
552endif()