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