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