View: Provide a clear setup path for the initial v_offset value
[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.6)
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 option(FORCE_QT4 "Force use of Qt4 even if Qt5 is available" FALSE)
39
40 if(WIN32)
41         # On Windows/MinGW we need to statically link to libraries.
42         # This option is user configurable, but enable it by default on win32.
43         set(STATIC_PKGDEPS_LIBS TRUE)
44
45         # For boost-thread we need two additional settings on win32:
46         set(Boost_USE_STATIC_LIBS ON)
47         add_definitions(-DBOOST_THREAD_USE_LIB)
48
49         # On Windows/MinGW we need to use 'thread_win32' instead of 'thread'.
50         # The library is named libboost_thread_win32* (not libboost_thread*).
51         set(Boost_THREADAPI win32)
52
53         # Windows does not support UNIX signals.
54         set(ENABLE_SIGNALS FALSE)
55 endif()
56
57 if(NOT CMAKE_BUILD_TYPE)
58         set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
59         "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
60         FORCE)
61 endif()
62
63 #===============================================================================
64 #= Dependencies
65 #-------------------------------------------------------------------------------
66
67 list(APPEND PKGDEPS libsigrokcxx>=0.4.0)
68
69 if(ENABLE_DECODE)
70         list(APPEND PKGDEPS libsigrokdecode>=0.4.0)
71 endif()
72
73 if(ANDROID)
74         list(APPEND PKGDEPS libsigrokandroidutils>=0.1.0)
75 endif()
76
77 find_package(PkgConfig)
78 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
79
80 if(FORCE_QT4)
81         set(Qt5Core_FOUND FALSE)
82 else()
83         find_package(Qt5Core QUIET)
84 endif()
85
86 if(Qt5Core_FOUND)
87         message("-- Using Qt5")
88         find_package(Qt5Widgets REQUIRED)
89         find_package(Qt5Gui REQUIRED)
90         find_package(Qt5Svg REQUIRED)
91         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
92         set(QT_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
93         set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
94         add_definitions(${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS})
95 else()
96         find_program(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 qmake-mac)
97         find_package(Qt4 REQUIRED QtCore QtGui QtSvg)
98 endif()
99
100 if(ENABLE_TESTS)
101         find_package(Boost 1.53 COMPONENTS filesystem system thread unit_test_framework REQUIRED)
102 else()
103         find_package(Boost 1.53 COMPONENTS filesystem system thread REQUIRED)
104 endif()
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.
108 find_package(Threads REQUIRED)
109
110 #===============================================================================
111 #= System Introspection
112 #-------------------------------------------------------------------------------
113
114 include(memaccess)
115 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
116
117 #===============================================================================
118 #= Config Header
119 #-------------------------------------------------------------------------------
120
121 set(PV_TITLE PulseView)
122 set(PV_DESCRIPTION "A GUI for sigrok")
123 set(PV_VERSION_STRING "0.4.0")
124
125 include(GetGitRevisionDescription)
126
127 # Append the revision hash unless we are exactly on a tagged release.
128 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
129 if(NOT PV_TAG_VERSION_STRING)
130         get_git_head_revision(PV_REVSPEC PV_HASH)
131         if(PV_HASH)
132                 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
133                 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
134         endif()
135 endif()
136
137 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
138         set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
139         set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
140         set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
141         set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
142 endif()
143
144 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
145
146 configure_file (
147         ${PROJECT_SOURCE_DIR}/config.h.in
148         ${PROJECT_BINARY_DIR}/config.h
149 )
150
151 #===============================================================================
152 #= Sources
153 #-------------------------------------------------------------------------------
154
155 set(pulseview_SOURCES
156         main.cpp
157         pv/application.cpp
158         pv/devicemanager.cpp
159         pv/mainwindow.cpp
160         pv/session.cpp
161         pv/storesession.cpp
162         pv/util.cpp
163         pv/binding/binding.cpp
164         pv/binding/inputoutput.cpp
165         pv/binding/device.cpp
166         pv/data/analog.cpp
167         pv/data/analogsegment.cpp
168         pv/data/logic.cpp
169         pv/data/logicsegment.cpp
170         pv/data/signaldata.cpp
171         pv/data/segment.cpp
172         pv/devices/device.cpp
173         pv/devices/file.cpp
174         pv/devices/hardwaredevice.cpp
175         pv/devices/inputfile.cpp
176         pv/devices/sessionfile.cpp
177         pv/dialogs/about.cpp
178         pv/dialogs/connect.cpp
179         pv/dialogs/inputoutputoptions.cpp
180         pv/dialogs/storeprogress.cpp
181         pv/popups/deviceoptions.cpp
182         pv/popups/channels.cpp
183         pv/prop/bool.cpp
184         pv/prop/double.cpp
185         pv/prop/enum.cpp
186         pv/prop/int.cpp
187         pv/prop/property.cpp
188         pv/prop/string.cpp
189         pv/toolbars/mainbar.cpp
190         pv/view/analogsignal.cpp
191         pv/view/cursor.cpp
192         pv/view/cursorpair.cpp
193         pv/view/flag.cpp
194         pv/view/header.cpp
195         pv/view/marginwidget.cpp
196         pv/view/logicsignal.cpp
197         pv/view/rowitem.cpp
198         pv/view/ruler.cpp
199         pv/view/signal.cpp
200         pv/view/signalscalehandle.cpp
201         pv/view/timeitem.cpp
202         pv/view/timemarker.cpp
203         pv/view/trace.cpp
204         pv/view/tracegroup.cpp
205         pv/view/tracepalette.cpp
206         pv/view/tracetreeitem.cpp
207         pv/view/tracetreeitemowner.cpp
208         pv/view/triggermarker.cpp
209         pv/view/view.cpp
210         pv/view/viewitem.cpp
211         pv/view/viewitemowner.cpp
212         pv/view/viewitempaintparams.cpp
213         pv/view/viewport.cpp
214         pv/view/viewwidget.cpp
215         pv/widgets/colourbutton.cpp
216         pv/widgets/colourpopup.cpp
217         pv/widgets/devicetoolbutton.cpp
218         pv/widgets/exportmenu.cpp
219         pv/widgets/hidingmenubar.cpp
220         pv/widgets/importmenu.cpp
221         pv/widgets/popup.cpp
222         pv/widgets/popuptoolbutton.cpp
223         pv/widgets/sweeptimingwidget.cpp
224         pv/widgets/timestampspinbox.cpp
225         pv/widgets/wellarray.cpp
226 )
227
228 # This list includes only QObject derived class headers.
229 set(pulseview_HEADERS
230         pv/mainwindow.hpp
231         pv/session.hpp
232         pv/storesession.hpp
233         pv/binding/device.hpp
234         pv/dialogs/about.hpp
235         pv/dialogs/connect.hpp
236         pv/dialogs/inputoutputoptions.hpp
237         pv/dialogs/storeprogress.hpp
238         pv/popups/channels.hpp
239         pv/popups/deviceoptions.hpp
240         pv/prop/bool.hpp
241         pv/prop/double.hpp
242         pv/prop/enum.hpp
243         pv/prop/int.hpp
244         pv/prop/property.hpp
245         pv/prop/string.hpp
246         pv/toolbars/mainbar.hpp
247         pv/view/cursor.hpp
248         pv/view/flag.hpp
249         pv/view/header.hpp
250         pv/view/logicsignal.hpp
251         pv/view/marginwidget.hpp
252         pv/view/rowitem.hpp
253         pv/view/ruler.hpp
254         pv/view/signal.hpp
255         pv/view/signalscalehandle.hpp
256         pv/view/timeitem.hpp
257         pv/view/timemarker.hpp
258         pv/view/trace.hpp
259         pv/view/tracegroup.hpp
260         pv/view/tracetreeitem.hpp
261         pv/view/triggermarker.hpp
262         pv/view/view.hpp
263         pv/view/viewitem.hpp
264         pv/view/viewport.hpp
265         pv/view/viewwidget.hpp
266         pv/widgets/colourbutton.hpp
267         pv/widgets/colourpopup.hpp
268         pv/widgets/devicetoolbutton.hpp
269         pv/widgets/exportmenu.hpp
270         pv/widgets/hidingmenubar.hpp
271         pv/widgets/importmenu.hpp
272         pv/widgets/popup.hpp
273         pv/widgets/popuptoolbutton.hpp
274         pv/widgets/sweeptimingwidget.hpp
275         pv/widgets/timestampspinbox.hpp
276         pv/widgets/wellarray.hpp
277 )
278
279 set(pulseview_FORMS
280         pv/dialogs/about.ui
281 )
282
283 set(pulseview_RESOURCES
284         pulseview.qrc
285 )
286
287 if(ENABLE_SIGNALS)
288         list(APPEND pulseview_SOURCES signalhandler.cpp)
289         list(APPEND pulseview_HEADERS signalhandler.hpp)
290 endif()
291
292 if(ENABLE_DECODE)
293         list(APPEND pulseview_SOURCES
294                 pv/binding/decoder.cpp
295                 pv/data/decoderstack.cpp
296                 pv/data/decode/annotation.cpp
297                 pv/data/decode/decoder.cpp
298                 pv/data/decode/row.cpp
299                 pv/data/decode/rowdata.cpp
300                 pv/view/decodetrace.cpp
301                 pv/widgets/decodergroupbox.cpp
302                 pv/widgets/decodermenu.cpp
303         )
304
305         list(APPEND pulseview_HEADERS
306                 pv/data/decoderstack.hpp
307                 pv/view/decodetrace.hpp
308                 pv/widgets/decodergroupbox.hpp
309                 pv/widgets/decodermenu.hpp
310         )
311 endif()
312
313 if(WIN32)
314         # Use the sigrok icon for the pulseview.exe executable.
315         set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
316         enable_language(RC)
317         list(APPEND pulseview_SOURCES pulseviewico.rc)
318 endif()
319
320 if(ANDROID)
321         list(APPEND pulseview_SOURCES
322                 android/assetreader.cpp
323                 android/loghandler.cpp
324         )
325 endif()
326
327 if(Qt5Core_FOUND)
328         qt5_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS})
329         qt5_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
330         qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
331 else()
332         # Workaround for QTBUG-22829: -DBOOST_NEXT_PRIOR_HPP_INCLUDED.
333         # https://bugreports.qt.io/browse/QTBUG-22829
334         qt4_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS}
335                 OPTIONS -DBOOST_NEXT_PRIOR_HPP_INCLUDED)
336         qt4_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
337         qt4_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
338         include(${QT_USE_FILE})
339 endif()
340
341 #===============================================================================
342 #= Global Definitions
343 #-------------------------------------------------------------------------------
344
345 add_definitions(${QT_DEFINITIONS} -DQT_NO_KEYWORDS)
346 add_definitions(-D__STDC_LIMIT_MACROS)
347 add_definitions(-Wall -Wextra)
348 add_definitions(-std=c++11)
349
350 if(ENABLE_DECODE)
351         add_definitions(-DENABLE_DECODE)
352 endif()
353
354 if(NOT DISABLE_WERROR)
355         add_definitions(-Werror)
356 endif()
357
358 if(ENABLE_SIGNALS)
359         add_definitions(-DENABLE_SIGNALS)
360 endif()
361
362 #===============================================================================
363 #= Global Include Directories
364 #-------------------------------------------------------------------------------
365
366 include_directories(
367         ${CMAKE_CURRENT_BINARY_DIR}
368         ${CMAKE_CURRENT_SOURCE_DIR}
369         ${Boost_INCLUDE_DIRS}
370         ${QT_INCLUDE_DIRS}
371 )
372
373 if(STATIC_PKGDEPS_LIBS)
374         include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
375 else()
376         include_directories(${PKGDEPS_INCLUDE_DIRS})
377 endif()
378
379 #===============================================================================
380 #= Linker Configuration
381 #-------------------------------------------------------------------------------
382
383 link_directories(${Boost_LIBRARY_DIRS})
384
385 set(PULSEVIEW_LINK_LIBS
386         ${Boost_LIBRARIES}
387         ${QT_LIBRARIES}
388         ${CMAKE_THREAD_LIBS_INIT}
389 )
390
391 if(STATIC_PKGDEPS_LIBS)
392         link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
393         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LIBRARIES})
394 if(WIN32)
395         # Workaround for a MinGW linking issue.
396         list(APPEND PULSEVIEW_LINK_LIBS "-llzma -llcms2")
397 endif()
398 else()
399         link_directories(${PKGDEPS_LIBRARY_DIRS})
400         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
401 endif()
402
403 if(WIN32)
404         # On Windows we need to statically link the libqsvg imageformat
405         # plugin (and the QtSvg component) for SVG graphics/icons to work.
406         add_definitions(-DQT_STATICPLUGIN)
407         link_directories("${QT_PLUGINS_DIR}/imageformats")
408         list(APPEND PULSEVIEW_LINK_LIBS "-lqsvg")
409         list(APPEND PULSEVIEW_LINK_LIBS ${QT_QTSVG_LIBRARY})
410 endif()
411
412 if(ANDROID)
413         list(APPEND PULSEVIEW_LINK_LIBS "-llog")
414 endif()
415
416 if(ANDROID)
417 add_library(${PROJECT_NAME} SHARED
418         ${pulseview_SOURCES}
419         ${pulseview_HEADERS_MOC}
420         ${pulseview_FORMS_HEADERS}
421         ${pulseview_RESOURCES_RCC}
422 )
423 else()
424 add_executable(${PROJECT_NAME}
425         ${pulseview_SOURCES}
426         ${pulseview_HEADERS_MOC}
427         ${pulseview_FORMS_HEADERS}
428         ${pulseview_RESOURCES_RCC}
429 )
430 endif()
431
432 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
433
434 if(WIN32)
435         # Pass -mwindows so that no "DOS box" opens when PulseView is started.
436         set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
437 endif()
438
439 #===============================================================================
440 #= Installation
441 #-------------------------------------------------------------------------------
442
443 # Install the executable.
444 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
445
446 # Install the manpage.
447 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
448
449 # Generate Windows installer script.
450 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
451
452 #===============================================================================
453 #= Packaging (handled by CPack)
454 #-------------------------------------------------------------------------------
455
456 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
457 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
458 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
459 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
460 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
461 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
462 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
463 set(CPACK_SOURCE_GENERATOR "TGZ")
464
465 include(CPack)
466
467 #===============================================================================
468 #= Tests
469 #-------------------------------------------------------------------------------
470
471 if(ENABLE_TESTS)
472         add_subdirectory(test)
473         enable_testing()
474         add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
475 endif()