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