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