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