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