Fix #404 by only saving enabled signals
[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 libsigrokcxx>=0.4.0)
69
70 if(ENABLE_DECODE)
71         list(APPEND PKGDEPS libsigrokdecode>=0.4.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 set(PV_VERSION_STRING "0.3.0")
125
126 include(GetGitRevisionDescription)
127 git_describe(PV_TAG_VERSION_STRING --tags --dirty)
128
129 if(NOT PV_TAG_VERSION_STRING AND EXISTS "${PROJECT_SOURCE_DIR}/VERSION")
130         # Read the version from a file that is distributed with
131         # the source package (see writepackageversion.cmake).
132         file(STRINGS "${PROJECT_SOURCE_DIR}/VERSION" PV_TAG_VERSION_STRING LIMIT_COUNT 1)
133 endif()
134
135 if(PV_TAG_VERSION_STRING MATCHES
136                 "^pulseview-([0-9]+\\.[0-9]+\\.[0-9]+)(-[0-9a-z]+)?(-g[-0-9a-z]+)?$")
137         set(PV_TAG_VERSION ${CMAKE_MATCH_1})
138         set(PV_TAG_PATCHLEVEL ${CMAKE_MATCH_2})
139         set(PV_TAG_REVHASH ${CMAKE_MATCH_3})
140
141         if(PV_VERSION_STRING VERSION_GREATER ${PV_TAG_VERSION})
142                 # Tagged version older than current one: indicate pre-release.
143                 set(PV_VERSION_STRING "${PV_VERSION_STRING}-pre${PV_TAG_REVHASH}")
144         else()
145                 # For post-release changes, indicate the patch level.
146                 set(PV_VERSION_STRING "${PV_TAG_VERSION}${PV_TAG_PATCHLEVEL}${PV_TAG_REVHASH}")
147         endif()
148 endif()
149
150 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
151         set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
152         set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
153         set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
154         set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
155 endif()
156
157 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
158
159 configure_file (
160         ${PROJECT_SOURCE_DIR}/config.h.in
161         ${PROJECT_BINARY_DIR}/config.h
162 )
163
164 #===============================================================================
165 #= Sources
166 #-------------------------------------------------------------------------------
167
168 set(pulseview_SOURCES
169         main.cpp
170         pv/application.cpp
171         pv/devicemanager.cpp
172         pv/mainwindow.cpp
173         pv/session.cpp
174         pv/storesession.cpp
175         pv/util.cpp
176         pv/binding/binding.cpp
177         pv/binding/inputoutput.cpp
178         pv/binding/device.cpp
179         pv/data/analog.cpp
180         pv/data/analogsegment.cpp
181         pv/data/logic.cpp
182         pv/data/logicsegment.cpp
183         pv/data/signaldata.cpp
184         pv/data/segment.cpp
185         pv/devices/device.cpp
186         pv/devices/file.cpp
187         pv/devices/hardwaredevice.cpp
188         pv/devices/inputfile.cpp
189         pv/devices/sessionfile.cpp
190         pv/dialogs/about.cpp
191         pv/dialogs/connect.cpp
192         pv/dialogs/inputoutputoptions.cpp
193         pv/dialogs/storeprogress.cpp
194         pv/popups/deviceoptions.cpp
195         pv/popups/channels.cpp
196         pv/prop/bool.cpp
197         pv/prop/double.cpp
198         pv/prop/enum.cpp
199         pv/prop/int.cpp
200         pv/prop/property.cpp
201         pv/prop/string.cpp
202         pv/toolbars/mainbar.cpp
203         pv/view/analogsignal.cpp
204         pv/view/cursor.cpp
205         pv/view/cursorpair.cpp
206         pv/view/flag.cpp
207         pv/view/header.cpp
208         pv/view/marginwidget.cpp
209         pv/view/logicsignal.cpp
210         pv/view/rowitem.cpp
211         pv/view/rowitemowner.cpp
212         pv/view/ruler.cpp
213         pv/view/signal.cpp
214         pv/view/timeitem.cpp
215         pv/view/timemarker.cpp
216         pv/view/trace.cpp
217         pv/view/tracegroup.cpp
218         pv/view/tracepalette.cpp
219         pv/view/view.cpp
220         pv/view/viewitem.cpp
221         pv/view/viewitempaintparams.cpp
222         pv/view/viewport.cpp
223         pv/view/viewwidget.cpp
224         pv/widgets/colourbutton.cpp
225         pv/widgets/colourpopup.cpp
226         pv/widgets/devicetoolbutton.cpp
227         pv/widgets/exportmenu.cpp
228         pv/widgets/hidingmenubar.cpp
229         pv/widgets/importmenu.cpp
230         pv/widgets/popup.cpp
231         pv/widgets/popuptoolbutton.cpp
232         pv/widgets/sweeptimingwidget.cpp
233         pv/widgets/wellarray.cpp
234 )
235
236 # This list includes only QObject derived class headers.
237 set(pulseview_HEADERS
238         pv/mainwindow.hpp
239         pv/session.hpp
240         pv/storesession.hpp
241         pv/binding/device.hpp
242         pv/dialogs/about.hpp
243         pv/dialogs/connect.hpp
244         pv/dialogs/inputoutputoptions.hpp
245         pv/dialogs/storeprogress.hpp
246         pv/popups/channels.hpp
247         pv/popups/deviceoptions.hpp
248         pv/prop/bool.hpp
249         pv/prop/double.hpp
250         pv/prop/enum.hpp
251         pv/prop/int.hpp
252         pv/prop/property.hpp
253         pv/prop/string.hpp
254         pv/toolbars/mainbar.hpp
255         pv/view/cursor.hpp
256         pv/view/flag.hpp
257         pv/view/header.hpp
258         pv/view/logicsignal.hpp
259         pv/view/marginwidget.hpp
260         pv/view/rowitem.hpp
261         pv/view/ruler.hpp
262         pv/view/signal.hpp
263         pv/view/timeitem.hpp
264         pv/view/timemarker.hpp
265         pv/view/trace.hpp
266         pv/view/tracegroup.hpp
267         pv/view/view.hpp
268         pv/view/viewitem.hpp
269         pv/view/viewport.hpp
270         pv/view/viewwidget.hpp
271         pv/widgets/colourbutton.hpp
272         pv/widgets/colourpopup.hpp
273         pv/widgets/devicetoolbutton.hpp
274         pv/widgets/exportmenu.hpp
275         pv/widgets/hidingmenubar.hpp
276         pv/widgets/importmenu.hpp
277         pv/widgets/popup.hpp
278         pv/widgets/popuptoolbutton.hpp
279         pv/widgets/sweeptimingwidget.hpp
280         pv/widgets/wellarray.hpp
281 )
282
283 set(pulseview_FORMS
284         pv/dialogs/about.ui
285 )
286
287 set(pulseview_RESOURCES
288         pulseview.qrc
289 )
290
291 if(ENABLE_SIGNALS)
292         list(APPEND pulseview_SOURCES signalhandler.cpp)
293         list(APPEND pulseview_HEADERS signalhandler.hpp)
294 endif()
295
296 if(ENABLE_DECODE)
297         list(APPEND pulseview_SOURCES
298                 pv/binding/decoder.cpp
299                 pv/data/decoderstack.cpp
300                 pv/data/decode/annotation.cpp
301                 pv/data/decode/decoder.cpp
302                 pv/data/decode/row.cpp
303                 pv/data/decode/rowdata.cpp
304                 pv/view/decodetrace.cpp
305                 pv/widgets/decodergroupbox.cpp
306                 pv/widgets/decodermenu.cpp
307         )
308
309         list(APPEND pulseview_HEADERS
310                 pv/data/decoderstack.hpp
311                 pv/view/decodetrace.hpp
312                 pv/widgets/decodergroupbox.hpp
313                 pv/widgets/decodermenu.hpp
314         )
315 endif()
316
317 if(WIN32)
318         # Use the sigrok icon for the pulseview.exe executable.
319         set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
320         enable_language(RC)
321         list(APPEND pulseview_SOURCES pulseviewico.rc)
322 endif()
323
324 if(ANDROID)
325         list(APPEND pulseview_SOURCES android/loghandler.cpp)
326 endif()
327
328 if(Qt5Core_FOUND)
329         qt5_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS})
330         qt5_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
331         qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
332 else()
333         # Workaroud for QTBUG-22829: -DBOOST_NEXT_PRIOR_HPP_INCLUDED.
334         # https://bugreports.qt.io/browse/QTBUG-22829
335         qt4_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS}
336                 OPTIONS -DBOOST_NEXT_PRIOR_HPP_INCLUDED)
337         qt4_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
338         qt4_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
339         include(${QT_USE_FILE})
340 endif()
341
342 #===============================================================================
343 #= Global Definitions
344 #-------------------------------------------------------------------------------
345
346 add_definitions(${QT_DEFINITIONS} -DQT_NO_KEYWORDS)
347 add_definitions(-D__STDC_LIMIT_MACROS)
348 add_definitions(-Wall -Wextra)
349 add_definitions(-std=c++11)
350
351 if(ENABLE_DECODE)
352         add_definitions(-DENABLE_DECODE)
353 endif()
354
355 if(NOT DISABLE_WERROR)
356         add_definitions(-Werror)
357 endif()
358
359 if(ENABLE_SIGNALS)
360         add_definitions(-DENABLE_SIGNALS)
361 endif()
362
363 #===============================================================================
364 #= Global Include Directories
365 #-------------------------------------------------------------------------------
366
367 include_directories(
368         ${CMAKE_CURRENT_BINARY_DIR}
369         ${CMAKE_CURRENT_SOURCE_DIR}
370         ${Boost_INCLUDE_DIRS}
371         ${QT_INCLUDE_DIRS}
372 )
373
374 if(STATIC_PKGDEPS_LIBS)
375         include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
376 else()
377         include_directories(${PKGDEPS_INCLUDE_DIRS})
378 endif()
379
380 #===============================================================================
381 #= Linker Configuration
382 #-------------------------------------------------------------------------------
383
384 link_directories(${Boost_LIBRARY_DIRS})
385
386 set(PULSEVIEW_LINK_LIBS
387         ${Boost_LIBRARIES}
388         ${QT_LIBRARIES}
389         ${CMAKE_THREAD_LIBS_INIT}
390 )
391
392 if(STATIC_PKGDEPS_LIBS)
393         link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
394         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LIBRARIES})
395 if(WIN32)
396         # Workaround for a MinGW linking issue.
397         list(APPEND PULSEVIEW_LINK_LIBS "-llzma -llcms2")
398 endif()
399 else()
400         link_directories(${PKGDEPS_LIBRARY_DIRS})
401         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
402 endif()
403
404 if(WIN32)
405         # On Windows we need to statically link the libqsvg imageformat
406         # plugin (and the QtSvg component) for SVG graphics/icons to work.
407         add_definitions(-DQT_STATICPLUGIN)
408         link_directories("${QT_PLUGINS_DIR}/imageformats")
409         list(APPEND PULSEVIEW_LINK_LIBS "-lqsvg")
410         list(APPEND PULSEVIEW_LINK_LIBS ${QT_QTSVG_LIBRARY})
411 endif()
412
413 if(ANDROID)
414         list(APPEND PULSEVIEW_LINK_LIBS "-llog")
415 endif()
416
417 if(ANDROID)
418 add_library(${PROJECT_NAME} SHARED
419         ${pulseview_SOURCES}
420         ${pulseview_HEADERS_MOC}
421         ${pulseview_FORMS_HEADERS}
422         ${pulseview_RESOURCES_RCC}
423 )
424 else()
425 add_executable(${PROJECT_NAME}
426         ${pulseview_SOURCES}
427         ${pulseview_HEADERS_MOC}
428         ${pulseview_FORMS_HEADERS}
429         ${pulseview_RESOURCES_RCC}
430 )
431 endif()
432
433 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
434
435 if(WIN32)
436         # Pass -mwindows so that no "DOS box" opens when PulseView is started.
437         set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
438 endif()
439
440 #===============================================================================
441 #= Installation
442 #-------------------------------------------------------------------------------
443
444 # Install the executable.
445 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
446
447 # Install the manpage.
448 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
449
450 #===============================================================================
451 #= Packaging (handled by CPack)
452 #-------------------------------------------------------------------------------
453
454 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
455 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
456 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
457 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
458 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
459 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
460 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
461 set(CPACK_SOURCE_GENERATOR "TGZ")
462 set(CPACK_INSTALL_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/CMake/writepackageversion.cmake)
463
464 include(CPack)
465
466 #===============================================================================
467 #= Tests
468 #-------------------------------------------------------------------------------
469
470 if(ENABLE_TESTS)
471         add_subdirectory(test)
472         enable_testing()
473         add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
474 endif()