Add a hotkey and setting for showing/hiding the minor analog grid.
[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 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
28
29 #===============================================================================
30 #= User Options
31 #-------------------------------------------------------------------------------
32
33 option(DISABLE_WERROR "Build without -Werror" FALSE)
34 option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
35 option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
36 option(ENABLE_TESTS "Enable unit tests" TRUE)
37 option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
38
39 if(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)
46 endif()
47
48 if(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)
52 endif()
53
54 #===============================================================================
55 #= Dependencies
56 #-------------------------------------------------------------------------------
57
58 list(APPEND PKGDEPS libsigrokcxx>=0.4.0)
59
60 if(ENABLE_DECODE)
61         list(APPEND PKGDEPS libsigrokdecode>=0.4.0)
62 endif()
63
64 if(ANDROID)
65         list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
66 endif()
67
68 find_package(PkgConfig)
69 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
70
71 set(CMAKE_AUTOMOC TRUE)
72 set(CMAKE_AUTORCC TRUE)
73
74 find_package(Qt5 COMPONENTS Core Gui Widgets Svg REQUIRED)
75
76 if(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)
80 endif()
81
82 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
83
84 set(BOOSTCOMPS filesystem serialization system)
85 if(ENABLE_TESTS)
86         list(APPEND BOOSTCOMPS unit_test_framework)
87 endif()
88 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
89
90 # Find the platform's thread library (needed for C++11 threads).
91 # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
92 find_package(Threads REQUIRED)
93
94 # Check for explicit link against libatomic
95 #
96 # Depending on the toolchain, linking a program using atomic functions may need
97 # "-latomic" explicitly passed to the linker
98 #
99 # This check first tests if atomics are available in the C-library, if not and
100 # libatomic exists, then it runs the same test with -latomic added to the
101 # linker flags.
102
103 # Helper for checking for atomics
104 function(check_working_cxx_atomics varname additional_lib)
105   include(CheckCXXSourceCompiles)
106   include(CMakePushCheckState)
107   cmake_push_check_state()
108   set(CMAKE_REQUIRED_FLAGS "-std=c++11")
109   set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
110   set(CMAKE_REQUIRED_QUIET 1)
111   CHECK_CXX_SOURCE_COMPILES("
112 #include <atomic>
113 std::atomic<int> x;
114 int main() {
115   return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
116 }
117 " ${varname})
118   cmake_pop_check_state()
119 endfunction(check_working_cxx_atomics)
120
121 # First check if atomics work without the library.
122 # If not, check if the library exists, and atomics work with it.
123 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
124 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
125   message(STATUS "Atomics provided by the C-library - yes")
126 else()
127   message(STATUS "Atomics provided by the C-library - no")
128   find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
129   if(LIBATOMIC_LIBRARY)
130     check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
131     if (HAVE_CXX_ATOMICS_WITH_LIB)
132       message(STATUS "Atomics provided by libatomic - yes")
133     else()
134       message(STATUS "Atomics provided by libatomic - no")
135       message(FATAL_ERROR "Compiler must support std::atomic!")
136     endif()
137   else()
138     message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
139   endif()
140 endif()
141
142 #===============================================================================
143 #= System Introspection
144 #-------------------------------------------------------------------------------
145
146 include(memaccess)
147 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
148
149 #===============================================================================
150 #= Config Header
151 #-------------------------------------------------------------------------------
152
153 set(PV_TITLE PulseView)
154 set(PV_DESCRIPTION "A GUI for sigrok")
155 set(PV_VERSION_STRING "0.4.0")
156
157 include(GetGitRevisionDescription)
158
159 # Append the revision hash unless we are exactly on a tagged release.
160 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
161 if(NOT PV_TAG_VERSION_STRING)
162         get_git_head_revision(PV_REVSPEC PV_HASH)
163         if(PV_HASH)
164                 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
165                 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
166         endif()
167 endif()
168
169 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
170         set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
171         set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
172         set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
173         set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
174 endif()
175
176 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
177
178 configure_file (
179         ${PROJECT_SOURCE_DIR}/config.h.in
180         ${PROJECT_BINARY_DIR}/config.h
181 )
182
183 #===============================================================================
184 #= Sources
185 #-------------------------------------------------------------------------------
186
187 set(pulseview_SOURCES
188         main.cpp
189         pv/application.cpp
190         pv/devicemanager.cpp
191         pv/globalsettings.cpp
192         pv/mainwindow.cpp
193         pv/session.cpp
194         pv/storesession.cpp
195         pv/util.cpp
196         pv/binding/binding.cpp
197         pv/binding/inputoutput.cpp
198         pv/binding/device.cpp
199         pv/data/analog.cpp
200         pv/data/analogsegment.cpp
201         pv/data/logic.cpp
202         pv/data/logicsegment.cpp
203         pv/data/signalbase.cpp
204         pv/data/signaldata.cpp
205         pv/data/segment.cpp
206         pv/devices/device.cpp
207         pv/devices/file.cpp
208         pv/devices/hardwaredevice.cpp
209         pv/devices/inputfile.cpp
210         pv/devices/sessionfile.cpp
211         pv/dialogs/connect.cpp
212         pv/dialogs/inputoutputoptions.cpp
213         pv/dialogs/settings.cpp
214         pv/dialogs/storeprogress.cpp
215         pv/popups/deviceoptions.cpp
216         pv/popups/channels.cpp
217         pv/prop/bool.cpp
218         pv/prop/double.cpp
219         pv/prop/enum.cpp
220         pv/prop/int.cpp
221         pv/prop/property.cpp
222         pv/prop/string.cpp
223         pv/toolbars/mainbar.cpp
224         pv/view/analogsignal.cpp
225         pv/view/cursor.cpp
226         pv/view/cursorpair.cpp
227         pv/view/flag.cpp
228         pv/view/header.cpp
229         pv/view/marginwidget.cpp
230         pv/view/logicsignal.cpp
231         pv/view/rowitem.cpp
232         pv/view/ruler.cpp
233         pv/view/signal.cpp
234         pv/view/signalscalehandle.cpp
235         pv/view/timeitem.cpp
236         pv/view/timemarker.cpp
237         pv/view/trace.cpp
238         pv/view/tracegroup.cpp
239         pv/view/tracepalette.cpp
240         pv/view/tracetreeitem.cpp
241         pv/view/tracetreeitemowner.cpp
242         pv/view/triggermarker.cpp
243         pv/view/view.cpp
244         pv/view/viewitem.cpp
245         pv/view/viewitemowner.cpp
246         pv/view/viewitempaintparams.cpp
247         pv/view/viewport.cpp
248         pv/view/viewwidget.cpp
249         pv/views/viewbase.cpp
250         pv/views/trace/standardbar.cpp
251         pv/widgets/colourbutton.cpp
252         pv/widgets/colourpopup.cpp
253         pv/widgets/devicetoolbutton.cpp
254         pv/widgets/exportmenu.cpp
255         pv/widgets/importmenu.cpp
256         pv/widgets/popup.cpp
257         pv/widgets/popuptoolbutton.cpp
258         pv/widgets/sweeptimingwidget.cpp
259         pv/widgets/timestampspinbox.cpp
260         pv/widgets/wellarray.cpp
261         pulseview.qrc
262 )
263
264 # This list includes only QObject derived class headers.
265 set(pulseview_HEADERS
266         pv/globalsettings.hpp
267         pv/mainwindow.hpp
268         pv/session.hpp
269         pv/storesession.hpp
270         pv/binding/device.hpp
271         pv/data/analog.hpp
272         pv/data/analogsegment.hpp
273         pv/data/logic.hpp
274         pv/data/logicsegment.hpp
275         pv/data/signalbase.hpp
276         pv/dialogs/connect.hpp
277         pv/dialogs/inputoutputoptions.hpp
278         pv/dialogs/settings.hpp
279         pv/dialogs/storeprogress.hpp
280         pv/popups/channels.hpp
281         pv/popups/deviceoptions.hpp
282         pv/prop/bool.hpp
283         pv/prop/double.hpp
284         pv/prop/enum.hpp
285         pv/prop/int.hpp
286         pv/prop/property.hpp
287         pv/prop/string.hpp
288         pv/toolbars/mainbar.hpp
289         pv/view/analogsignal.hpp
290     &