manual: Rename pulseview_manual.* to manual.*.
[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
78 set(LIBSR_CXX_BINDING "libsigrokcxx>=0.6.0")
79 list(APPEND PKGDEPS "${LIBSR_CXX_BINDING}")
80
81 if(ENABLE_DECODE)
82         list(APPEND PKGDEPS libsigrokdecode>=0.6.0)
83 endif()
84
85 if(ANDROID)
86         list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
87 endif()
88
89 find_package(PkgConfig)
90 pkg_check_modules(LIBSRCXX QUIET ${LIBSR_CXX_BINDING})
91 if(NOT LIBSRCXX_FOUND OR NOT LIBSRCXX_VERSION)
92         message(FATAL_ERROR "libsigrok C++ bindings missing, check libsigrok's 'configure' output (missing dependencies?)")
93 endif()
94 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
95
96 set(CMAKE_AUTOMOC TRUE)
97
98 find_package(Qt5 COMPONENTS Core Gui Widgets Svg REQUIRED)
99
100 if(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()
107 endif()
108
109 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
110
111 set(BOOSTCOMPS filesystem serialization system)
112 if(ENABLE_TESTS)
113         list(APPEND BOOSTCOMPS unit_test_framework)
114 endif()
115
116 if(ENABLE_STACKTRACE)
117         find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
118 else()
119         find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
120 endif()
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.
124 find_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
136 function(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>
145 std::atomic<int> x;
146 int main() {
147   return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
148 }
149 " ${varname})
150   cmake_pop_check_state()
151 endfunction(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.
155 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
156 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
157   message(STATUS "Atomics provided by the C-library - yes")
158 else()
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()
172 endif()
173
174 #===============================================================================
175 #= System Introspection
176 #-------------------------------------------------------------------------------
177
178 include(memaccess)
179 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
180
181 #===============================================================================
182 #= Config Header
183 #-------------------------------------------------------------------------------
184
185 set(PV_TITLE PulseView)
186 set(PV_VERSION_STRING "0.5.0")
187
188 set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
189
190 include(GetGitRevisionDescription)
191
192 # Append the revision hash unless we are exactly on a tagged release.
193 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
194 if(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 endif()
201
202 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
203         set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
204         set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
205         set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
206         set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
207 endif()
208
209 message(STATUS "${PV_TITLE} version: ${PV_VERSION_STRING}")
210
211 configure_file (
212         ${PROJECT_SOURCE_DIR}/config.h.in
213         ${PROJECT_BINARY_DIR}/config.h
214 )
215
216 #===============================================================================
217 #= Sources
218 #-------------------------------------------------------------------------------
219
220 set(pulseview_SOURCES
221         main.cpp
222         pv/application.cpp
223         pv/devicemanager.cpp
224         pv/globalsettings.cpp
225         pv/logging.cpp
226         pv/mainwindow.cpp
227         pv/session.cpp
228         pv/storesession.cpp
229         pv/util.cpp
230         pv/binding/binding.cpp
231         pv/binding/inputoutput.cpp
232         pv/binding/device.cpp
233         pv/data/analog.cpp
234         pv/data/analogsegment.cpp
235         pv/data/logic.cpp
236         pv/data/logicsegment.cpp
237         pv/data/signalbase.cpp
238         pv/data/signaldata.cpp
239         pv/data/segment.cpp
240         pv/devices/device.cpp
241         pv/devices/file.cpp
242         pv/devices/hardwaredevice.cpp
243         pv/devices/inputfile.cpp
244         pv/devices/sessionfile.cpp
245         pv/dialogs/connect.cpp
246         pv/dialogs/inputoutputoptions.cpp
247         pv/dialogs/settings.cpp
248         pv/dialogs/storeprogress.cpp
249         pv/popups/deviceoptions.cpp
250         pv/popups/channels.cpp
251         pv/prop/bool.cpp
252         pv/prop/double.cpp
253         pv/prop/enum.cpp
254         pv/prop/int.cpp
255         pv/prop/property.cpp
256         pv/prop/string.cpp
257         pv/toolbars/mainbar.cpp
258         pv/views/trace/analogsignal.cpp
259         pv/views/trace/cursor.cpp
260         pv/views/trace/cursorpair.cpp
261         pv/views/trace/flag.cpp
262         pv/views/trace/header.cpp
263         pv/views/trace/marginwidget.cpp
264         pv/views/trace/logicsignal.cpp
265         pv/views/trace/rowitem.cpp
266         pv/views/trace/ruler.cpp
267         pv/views/trace/signal.cpp
268         pv/views/trace/timeitem.cpp
269         pv/views/trace/timemarker.cpp
270         pv/views/trace/trace.cpp
271         pv/views/trace/tracegroup.cpp
272         pv/views/trace/tracepalette.cpp
273         pv/views/trace/tracetreeitem.cpp
274         pv/views/trace/tracetreeitemowner.cpp
275         pv/views/trace/triggermarker.cpp
276         pv/views/trace/view.cpp
277         pv/views/trace/viewitem.cpp
278         pv/views/trace/viewitemowner.cpp
279         pv/views/trace/viewitempaintparams.cpp
280         pv/views/trace/viewport.cpp
281         pv/views/trace/viewwidget.cpp
282         pv/views/viewbase.cpp
283         pv/views/trace/standardbar.cpp
284         pv/widgets/colorbutton.cpp
285         pv/widgets/colorpopup.cpp
286         pv/widgets/devicetoolbutton.cpp
287         pv/widgets/exportmenu.cpp
288         pv/widgets/importmenu.cpp
289         pv/widgets/popup.cpp
290         pv/widgets/popuptoolbutton.cpp
291         pv/widgets/sweeptimingwidget.cpp
292         pv/widgets/timestampspinbox.cpp
293         pv/widgets/wellarray.cpp
294 )
295
296 # This list includes only QObject derived class headers.
297 set(pulseview_HEADERS
298         pv/logging.hpp
299         pv/globalsettings.hpp
300         pv/mainwindow.hpp
301         pv/session.hpp
302         pv/storesession.hpp
303         pv/binding/device.hpp
304         pv/data/analog.hpp
305         pv/data/analogsegment.hpp
306         pv/data/logic.hpp
307         pv/data/logicsegment.hpp
308         pv/data/signalbase.hpp
309         pv/dialogs/connect.hpp
310         pv/dialogs/inputoutputoptions.hpp
311         pv/dialogs/settings.hpp
312         pv/dialogs/storeprogress.hpp
313         pv/popups/channels.hpp
314         pv/popups/deviceoptions.hpp
315         pv/prop/bool.hpp
316         pv/prop/double.hpp
317         pv/prop/enum.hpp
318         pv/prop/int.hpp
319         pv/prop/property.hpp
320         pv/prop/string.hpp
321         pv/toolbars/mainbar.hpp
322         pv/views/trace/analogsignal.hpp
323         pv/views/trace/cursor.hpp
324         pv/views/trace/flag.hpp
325         pv/views/trace/header.hpp
326         pv/views/trace/logicsignal.hpp
327         pv/views/trace/marginwidget.hpp
328         pv/views/trace/rowitem.hpp
329         pv/views/trace/ruler.hpp
330         pv/views/trace/signal.hpp
331         pv/views/trace/timeitem.hpp
332         pv/views/trace/timemarker.hpp
333         pv/views/trace/trace.hpp
334         pv/views/trace/tracegroup.hpp
335         pv/views/trace/tracetreeitem.hpp
336         pv/views/trace/triggermarker.hpp
337         pv/views/trace/view.hpp
338         pv/views/trace/viewitem.hpp
339         pv/views/trace/viewport.hpp
340         pv/views/trace/viewwidget.hpp
341         pv/views/viewbase.hpp
342         pv/views/trace/standardbar.hpp
343         pv/widgets/colorbutton.hpp
344         pv/widgets/colorpopup.hpp
345         pv/widgets/devicetoolbutton.hpp
346         pv/widgets/exportmenu.hpp
347         pv/widgets/importmenu.hpp
348         pv/widgets/popup.hpp
349         pv/widgets/popuptoolbutton.hpp
350         pv/widgets/sweeptimingwidget.hpp
351         pv/widgets/timestampspinbox.hpp
352         pv/widgets/wellarray.hpp
353 )
354
355 set(pulseview_RESOURCES
356         pulseview.qrc
357 )
358
359 if(ENABLE_SIGNALS)
360         list(APPEND pulseview_SOURCES signalhandler.cpp)
361         list(APPEND pulseview_HEADERS signalhandler.hpp)
362 endif()
363
364 if(ENABLE_DECODE)
365         list(APPEND pulseview_SOURCES
366                 pv/binding/decoder.cpp
367                 pv/data/decodesignal.cpp
368                 pv/data/decode/annotation.cpp
369                 pv/data/decode/decoder.cpp
370                 pv/data/decode/row.cpp
371                 pv/data/decode/rowdata.cpp
372                 pv/views/trace/decodetrace.cpp
373                 pv/widgets/decodergroupbox.cpp
374                 pv/widgets/decodermenu.cpp
375         )
376
377         list(APPEND pulseview_HEADERS
378                 pv/data/decodesignal.hpp
379                 pv/views/trace/decodetrace.hpp
380                 pv/widgets/decodergroupbox.hpp
381                 pv/widgets/decodermenu.hpp
382         )
383 endif()
384
385 if(WIN32)
386         # Use the sigrok icon for the pulseview.exe executable.
387         set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
388         enable_language(RC)
389         list(APPEND pulseview_SOURCES pulseviewico.rc)
390 endif()
391
392 if(ANDROID)
393         list(APPEND pulseview_SOURCES
394                 android/assetreader.cpp
395                 android/loghandler.cpp
396         )
397 endif()
398
399 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
400
401 #===============================================================================
402 #= Global Definitions
403 #-------------------------------------------------------------------------------
404
405 add_definitions(-DQT_NO_KEYWORDS)
406 add_definitions(-D__STDC_LIMIT_MACROS)
407 add_definitions(-Wall -Wextra)
408 add_definitions(-std=c++11)
409 add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
410
411 if(ENABLE_DECODE)
412         add_definitions(-DENABLE_DECODE)
413 endif()
414
415 if(NOT DISABLE_WERROR)
416         add_definitions(-Werror)
417 endif()
418
419 if(ENABLE_SIGNALS)
420         add_definitions(-DENABLE_SIGNALS)
421 endif()
422
423 if(ENABLE_STACKTRACE)
424         add_definitions(-DENABLE_STACKTRACE)
425 endif()
426
427 #===============================================================================
428 #= Global Include Directories
429 #-------------------------------------------------------------------------------
430
431 include_directories(
432         ${CMAKE_CURRENT_BINARY_DIR}
433         ${CMAKE_CURRENT_SOURCE_DIR}
434         ${Boost_INCLUDE_DIRS}
435 )
436
437 if(STATIC_PKGDEPS_LIBS)
438         include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
439 else()
440         include_directories(${PKGDEPS_INCLUDE_DIRS})
441 endif()
442
443 #===============================================================================
444 #= Linker Configuration
445 #-------------------------------------------------------------------------------
446
447 link_directories(${Boost_LIBRARY_DIRS})
448
449 set(PULSEVIEW_LINK_LIBS
450         ${Boost_LIBRARIES}
451         ${QT_LIBRARIES}
452         ${CMAKE_THREAD_LIBS_INIT}
453         ${LIBATOMIC_LIBRARY}
454 )
455
456 if(STATIC_PKGDEPS_LIBS)
457         link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
458         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
459 else()
460         link_directories(${PKGDEPS_LIBRARY_DIRS})
461         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
462 endif()
463
464 if(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 (only for
468         # Qt < 5.8.0), and all 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         if(Qt5Gui_VERSION VERSION_LESS 5.8.0)
473                 list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport)
474         endif()
475         list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
476 endif()
477
478 if(ENABLE_STACKTRACE)
479         # Needed to resolve dladdr.
480         list(APPEND PULSEVIEW_LINK_LIBS "-ldl")
481 endif()
482
483 if(ANDROID)
484         list(APPEND PULSEVIEW_LINK_LIBS "-llog")
485 endif()
486
487 if(ANDROID)
488         add_library(${PROJECT_NAME} SHARED ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
489 else()
490         add_executable(${PROJECT_NAME} ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
491 endif()
492
493 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
494
495 if(WIN32 AND NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
496         # Pass -mwindows so that no "DOS box" opens when PulseView is started.
497         set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
498 endif()
499
500 #===============================================================================
501 #= Installation
502 #-------------------------------------------------------------------------------
503
504 # Install the executable.
505 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
506
507 # Install the manpage.
508 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
509
510 # Install the desktop file.
511 install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
512
513 # Install the AppData/AppStream file.
514 install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
515
516 # Install the PulseView icons.
517 install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
518 install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
519
520 # Generate Windows installer script.
521 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
522
523 #===============================================================================
524 #= Packaging (handled by CPack)
525 #-------------------------------------------------------------------------------
526
527 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
528 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
529 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
530 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
531 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
532 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
533 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
534 set(CPACK_SOURCE_GENERATOR "TGZ")
535
536 include(CPack)
537
538 #===============================================================================
539 #= Tests
540 #-------------------------------------------------------------------------------
541
542 if(ENABLE_TESTS)
543         add_subdirectory(test)
544         enable_testing()
545         add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
546 endif()