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