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