Connect dialog: Fix up UI and allow for VXI
[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 # Check for explicit link against libatomic
112 #
113 # Depending on the toolchain, linking a program using atomic functions may need
114 # "-latomic" explicitly passed to the linker
115 #
116 # This check first tests if atomics are available in the C-library, if not and
117 # libatomic exists, then it runs the same test with -latomic added to the
118 # linker flags.
119
120 # Helper for checking for atomics
121 function(check_working_cxx_atomics varname additional_lib)
122   include(CheckCXXSourceCompiles)
123   include(CMakePushCheckState)
124   cmake_push_check_state()
125   set(CMAKE_REQUIRED_FLAGS "-std=c++11")
126   set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
127   set(CMAKE_REQUIRED_QUIET 1)
128   CHECK_CXX_SOURCE_COMPILES("
129 #include <atomic>
130 std::atomic<int> x;
131 int main() {
132   return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
133 }
134 " ${varname})
135   cmake_pop_check_state()
136 endfunction(check_working_cxx_atomics)
137
138 # First check if atomics work without the library.
139 # If not, check if the library exists, and atomics work with it.
140 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
141 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
142   message(STATUS "Atomics provided by the C-library - yes")
143 else()
144   message(STATUS "Atomics provided by the C-library - no")
145   find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
146   if(LIBATOMIC_LIBRARY)
147     check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
148     if (HAVE_CXX_ATOMICS_WITH_LIB)
149       message(STATUS "Atomics provided by libatomic - yes")
150     else()
151       message(STATUS "Atomics provided by libatomic - no")
152       message(FATAL_ERROR "Compiler must support std::atomic!")
153     endif()
154   else()
155     message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
156   endif()
157 endif()
158
159 #===============================================================================
160 #= System Introspection
161 #-------------------------------------------------------------------------------
162
163 include(memaccess)
164 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
165
166 #===============================================================================
167 #= Config Header
168 #-------------------------------------------------------------------------------
169
170 set(PV_TITLE PulseView)
171 set(PV_DESCRIPTION "A GUI for sigrok")
172 set(PV_VERSION_STRING "0.4.0")
173
174 include(GetGitRevisionDescription)
175
176 # Append the revision hash unless we are exactly on a tagged release.
177 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
178 if(NOT PV_TAG_VERSION_STRING)
179         get_git_head_revision(PV_REVSPEC PV_HASH)
180         if(PV_HASH)
181                 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
182                 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
183         endif()
184 endif()
185
186 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
187         set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
188         set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
189         set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
190         set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
191 endif()
192
193 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
194
195 configure_file (
196         ${PROJECT_SOURCE_DIR}/config.h.in
197         ${PROJECT_BINARY_DIR}/config.h
198 )
199
200 #===============================================================================
201 #= Sources
202 #-------------------------------------------------------------------------------
203
204 set(pulseview_SOURCES
205         main.cpp
206         pv/application.cpp
207         pv/devicemanager.cpp
208         pv/mainwindow.cpp
209         pv/session.cpp
210         pv/storesession.cpp
211         pv/util.cpp
212         pv/binding/binding.cpp
213         pv/binding/inputoutput.cpp
214         pv/binding/device.cpp
215         pv/data/analog.cpp
216         pv/data/analogsegment.cpp
217         pv/data/logic.cpp
218         pv/data/logicsegment.cpp
219         pv/data/signaldata.cpp
220         pv/data/segment.cpp
221         pv/devices/device.cpp
222         pv/devices/file.cpp
223         pv/devices/hardwaredevice.cpp
224         pv/devices/inputfile.cpp
225         pv/devices/sessionfile.cpp
226         pv/dialogs/about.cpp
227         pv/dialogs/connect.cpp
228         pv/dialogs/inputoutputoptions.cpp
229         pv/dialogs/storeprogress.cpp
230         pv/popups/deviceoptions.cpp
231         pv/popups/channels.cpp
232         pv/prop/bool.cpp
233         pv/prop/double.cpp
234         pv/prop/enum.cpp
235         pv/prop/int.cpp
236         pv/prop/property.cpp
237         pv/prop/string.cpp
238         pv/toolbars/mainbar.cpp
239         pv/view/analogsignal.cpp
240         pv/view/cursor.cpp
241         pv/view/cursorpair.cpp
242         pv/view/flag.cpp
243         pv/view/header.cpp
244         pv/view/marginwidget.cpp
245         pv/view/logicsignal.cpp
246         pv/view/rowitem.cpp
247         pv/view/ruler.cpp
248         pv/view/signal.cpp
249         pv/view/signalscalehandle.cpp
250         pv/view/timeitem.cpp
251         pv/view/timemarker.cpp
252         pv/view/trace.cpp
253         pv/view/tracegroup.cpp
254         pv/view/tracepalette.cpp
255         pv/view/tracetreeitem.cpp
256         pv/view/tracetreeitemowner.cpp
257         pv/view/triggermarker.cpp
258         pv/view/view.cpp
259         pv/view/viewitem.cpp
260         pv/view/viewitemowner.cpp
261         pv/view/viewitempaintparams.cpp
262         pv/view/viewport.cpp
263         pv/view/viewwidget.cpp
264         pv/widgets/colourbutton.cpp
265         pv/widgets/colourpopup.cpp
266         pv/widgets/devicetoolbutton.cpp
267         pv/widgets/exportmenu.cpp
268         pv/widgets/hidingmenubar.cpp
269         pv/widgets/importmenu.cpp
270         pv/widgets/popup.cpp
271         pv/widgets/popuptoolbutton.cpp
272         pv/widgets/sweeptimingwidget.cpp
273         pv/widgets/timestampspinbox.cpp
274         pv/widgets/wellarray.cpp
275 )
276
277 # This list includes only QObject derived class headers.
278 set(pulseview_HEADERS
279         pv/mainwindow.hpp
280         pv/session.hpp
281         pv/storesession.hpp
282         pv/binding/device.hpp
283         pv/dialogs/about.hpp
284         pv/dialogs/connect.hpp
285         pv/dialogs/inputoutputoptions.hpp
286         pv/dialogs/storeprogress.hpp
287         pv/popups/channels.hpp
288         pv/popups/deviceoptions.hpp
289         pv/prop/bool.hpp
290         pv/prop/double.hpp
291         pv/prop/enum.hpp
292         pv/prop/int.hpp
293         pv/prop/property.hpp
294         pv/prop/string.hpp
295         pv/toolbars/mainbar.hpp
296         pv/view/analogsignal.hpp
297         pv/view/cursor.hpp
298         pv/view/flag.hpp
299         pv/view/header.hpp
300         pv/view/logicsignal.hpp
301         pv/view/marginwidget.hpp
302         pv/view/rowitem.hpp
303         pv/view/ruler.hpp
304         pv/view/signal.hpp
305         pv/view/signalscalehandle.hpp
306         pv/view/timeitem.hpp
307         pv/view/timemarker.hpp
308         pv/view/trace.hpp
309         pv/view/tracegroup.hpp
310         pv/view/tracetreeitem.hpp
311         pv/view/triggermarker.hpp
312         pv/view/view.hpp
313         pv/view/viewitem.hpp
314         pv/view/viewport.hpp
315         pv/view/viewwidget.hpp
316         pv/widgets/colourbutton.hpp
317         pv/widgets/colourpopup.hpp
318         pv/widgets/devicetoolbutton.hpp
319         pv/widgets/exportmenu.hpp
320         pv/widgets/hidingmenubar.hpp
321         pv/widgets/importmenu.hpp
322         pv/widgets/popup.hpp
323         pv/widgets/popuptoolbutton.hpp
324         pv/widgets/sweeptimingwidget.hpp
325         pv/widgets/timestampspinbox.hpp
326         pv/widgets/wellarray.hpp
327 )
328
329 set(pulseview_FORMS
330         pv/dialogs/about.ui
331 )
332
333 set(pulseview_RESOURCES
334         pulseview.qrc
335 )
336
337 if(ENABLE_SIGNALS)
338         list(APPEND pulseview_SOURCES signalhandler.cpp)
339         list(APPEND pulseview_HEADERS signalhandler.hpp)
340 endif()
341
342 if(ENABLE_DECODE)
343         list(APPEND pulseview_SOURCES
344                 pv/binding/decoder.cpp
345                 pv/data/decoderstack.cpp
346                 pv/data/decode/annotation.cpp
347                 pv/data/decode/decoder.cpp
348                 pv/data/decode/row.cpp
349                 pv/data/decode/rowdata.cpp
350                 pv/view/decodetrace.cpp
351                 pv/widgets/decodergroupbox.cpp
352                 pv/widgets/decodermenu.cpp
353         )
354
355         list(APPEND pulseview_HEADERS
356                 pv/data/decoderstack.hpp
357                 pv/view/decodetrace.hpp
358                 pv/widgets/decodergroupbox.hpp
359                 pv/widgets/decodermenu.hpp
360         )
361 endif()
362
363 if(WIN32)
364         # Use the sigrok icon for the pulseview.exe executable.
365         set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
366         enable_language(RC)
367         list(APPEND pulseview_SOURCES pulseviewico.rc)
368 endif()
369
370 if(ANDROID)
371         list(APPEND pulseview_SOURCES
372                 android/assetreader.cpp
373                 android/loghandler.cpp
374         )
375 endif()
376
377 if(Qt5Core_FOUND)
378         qt5_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS})
379         qt5_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
380         qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
381 else()
382         # Workaround for QTBUG-22829: -DBOOST_NEXT_PRIOR_HPP_INCLUDED.
383         # https://bugreports.qt.io/browse/QTBUG-22829
384         qt4_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS}
385                 OPTIONS -DBOOST_NEXT_PRIOR_HPP_INCLUDED)
386         qt4_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
387         qt4_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
388         include(${QT_USE_FILE})
389 endif()
390
391 #===============================================================================
392 #= Global Definitions
393 #-------------------------------------------------------------------------------
394
395 add_definitions(${QT_DEFINITIONS} -DQT_NO_KEYWORDS)
396 add_definitions(-D__STDC_LIMIT_MACROS)
397 add_definitions(-Wall -Wextra)
398 add_definitions(-std=c++11)
399
400 if(ENABLE_DECODE)
401         add_definitions(-DENABLE_DECODE)
402 endif()
403
404 if(NOT DISABLE_WERROR)
405         add_definitions(-Werror)
406 endif()
407
408 if(ENABLE_SIGNALS)
409         add_definitions(-DENABLE_SIGNALS)
410 endif()
411
412 #===============================================================================
413 #= Global Include Directories
414 #-------------------------------------------------------------------------------
415
416 include_directories(
417         ${CMAKE_CURRENT_BINARY_DIR}
418         ${CMAKE_CURRENT_SOURCE_DIR}
419         ${Boost_INCLUDE_DIRS}
420         ${QT_INCLUDE_DIRS}
421 )
422
423 if(STATIC_PKGDEPS_LIBS)
424         include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
425 else()
426         include_directories(${PKGDEPS_INCLUDE_DIRS})
427 endif()
428
429 #===============================================================================
430 #= Linker Configuration
431 #-------------------------------------------------------------------------------
432
433 link_directories(${Boost_LIBRARY_DIRS})
434
435 set(PULSEVIEW_LINK_LIBS
436         ${Boost_LIBRARIES}
437         ${QT_LIBRARIES}
438         ${CMAKE_THREAD_LIBS_INIT}
439         ${LIBATOMIC_LIBRARY}
440 )
441
442 if(STATIC_PKGDEPS_LIBS)
443         link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
444         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LIBRARIES})
445 if(WIN32)
446         # Workaround for a MinGW linking issue.
447         list(APPEND PULSEVIEW_LINK_LIBS "-llzma -llcms2")
448 endif()
449 else()
450         link_directories(${PKGDEPS_LIBRARY_DIRS})
451         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
452 endif()
453
454 if(WIN32)
455         # On Windows we need to statically link the libqsvg imageformat
456         # plugin (and the QtSvg component) for SVG graphics/icons to work.
457         add_definitions(-DQT_STATICPLUGIN)
458         link_directories("${QT_PLUGINS_DIR}/imageformats")
459         list(APPEND PULSEVIEW_LINK_LIBS "-lqsvg")
460         list(APPEND PULSEVIEW_LINK_LIBS ${QT_QTSVG_LIBRARY})
461 endif()
462
463 if(ANDROID)
464         list(APPEND PULSEVIEW_LINK_LIBS "-llog")
465 endif()
466
467 if(ANDROID)
468 add_library(${PROJECT_NAME} SHARED
469         ${pulseview_SOURCES}
470         ${pulseview_HEADERS_MOC}
471         ${pulseview_FORMS_HEADERS}
472         ${pulseview_RESOURCES_RCC}
473 )
474 else()
475 add_executable(${PROJECT_NAME}
476         ${pulseview_SOURCES}
477         ${pulseview_HEADERS_MOC}
478         ${pulseview_FORMS_HEADERS}
479         ${pulseview_RESOURCES_RCC}
480 )
481 endif()
482
483 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
484
485 if(WIN32)
486         # Pass -mwindows so that no "DOS box" opens when PulseView is started.
487         set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
488 endif()
489
490 #===============================================================================
491 #= Installation
492 #-------------------------------------------------------------------------------
493
494 # Install the executable.
495 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
496
497 # Install the manpage.
498 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
499
500 # Generate Windows installer script.
501 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
502
503 #===============================================================================
504 #= Packaging (handled by CPack)
505 #-------------------------------------------------------------------------------
506
507 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
508 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
509 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
510 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
511 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
512 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
513 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
514 set(CPACK_SOURCE_GENERATOR "TGZ")
515
516 include(CPack)
517
518 #===============================================================================
519 #= Tests
520 #-------------------------------------------------------------------------------
521
522 if(ENABLE_TESTS)
523         add_subdirectory(test)
524         enable_testing()
525         add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
526 endif()