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