]> sigrok.org Git - pulseview.git/blob - CMakeLists.txt
Restart min-max-based conversion if min or max change
[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.12)
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
39 if(WIN32)
40         # On Windows/MinGW we need to statically link to libraries.
41         # This option is user configurable, but enable it by default on win32.
42         set(STATIC_PKGDEPS_LIBS TRUE)
43
44         # Windows does not support UNIX signals.
45         set(ENABLE_SIGNALS FALSE)
46 endif()
47
48 if(NOT CMAKE_BUILD_TYPE)
49         set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
50         "Choose the type of build (None, Debug, Release, RelWithDebInfo, MinSizeRel)."
51         FORCE)
52 endif()
53
54 #===============================================================================
55 #= Dependencies
56 #-------------------------------------------------------------------------------
57
58 list(APPEND PKGDEPS glib-2.0>=2.28.0)
59 list(APPEND PKGDEPS glibmm-2.4>=2.28.0)
60
61 list(APPEND PKGDEPS libsigrokcxx>=0.6.0)
62
63 if(ENABLE_DECODE)
64         list(APPEND PKGDEPS libsigrokdecode>=0.6.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 set(CMAKE_AUTOMOC TRUE)
75
76 find_package(Qt5 COMPONENTS Core Gui Widgets Svg REQUIRED)
77
78 if(WIN32)
79         # MXE workaround: Use pkg-config to find Qt5 libs.
80         # https://github.com/mxe/mxe/issues/1642
81         pkg_check_modules(QT5ALL REQUIRED Qt5Widgets Qt5Gui Qt5Svg)
82 endif()
83
84 set(QT_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Svg)
85
86 set(BOOSTCOMPS filesystem serialization system)
87 if(ENABLE_TESTS)
88         list(APPEND BOOSTCOMPS unit_test_framework)
89 endif()
90 find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
91
92 # Find the platform's thread library (needed for C++11 threads).
93 # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
94 find_package(Threads REQUIRED)
95
96 # Check for explicit link against libatomic
97 #
98 # Depending on the toolchain, linking a program using atomic functions may need
99 # "-latomic" explicitly passed to the linker
100 #
101 # This check first tests if atomics are available in the C-library, if not and
102 # libatomic exists, then it runs the same test with -latomic added to the
103 # linker flags.
104
105 # Helper for checking for atomics
106 function(check_working_cxx_atomics varname additional_lib)
107   include(CheckCXXSourceCompiles)
108   include(CMakePushCheckState)
109   cmake_push_check_state()
110   set(CMAKE_REQUIRED_FLAGS "-std=c++11")
111   set(CMAKE_REQUIRED_LIBRARIES "${additional_lib}")
112   set(CMAKE_REQUIRED_QUIET 1)
113   CHECK_CXX_SOURCE_COMPILES("
114 #include <atomic>
115 std::atomic<int> x;
116 int main() {
117   return std::atomic_fetch_add_explicit(&x, 1, std::memory_order_seq_cst);
118 }
119 " ${varname})
120   cmake_pop_check_state()
121 endfunction(check_working_cxx_atomics)
122
123 # First check if atomics work without the library.
124 # If not, check if the library exists, and atomics work with it.
125 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB "")
126 if(HAVE_CXX_ATOMICS_WITHOUT_LIB)
127   message(STATUS "Atomics provided by the C-library - yes")
128 else()
129   message(STATUS "Atomics provided by the C-library - no")
130   find_library(LIBATOMIC_LIBRARY NAMES atomic PATH_SUFFIXES lib)
131   if(LIBATOMIC_LIBRARY)
132     check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB "${LIBATOMIC_LIBRARY}")
133     if (HAVE_CXX_ATOMICS_WITH_LIB)
134       message(STATUS "Atomics provided by libatomic - yes")
135     else()
136       message(STATUS "Atomics provided by libatomic - no")
137       message(FATAL_ERROR "Compiler must support std::atomic!")
138     endif()
139   else()
140     message(FATAL_ERROR "Compiler appears to require libatomic, but cannot find it.")
141   endif()
142 endif()
143
144 #===============================================================================
145 #= System Introspection
146 #-------------------------------------------------------------------------------
147
148 include(memaccess)
149 memaccess_check_unaligned_le(HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS)
150
151 #===============================================================================
152 #= Config Header
153 #-------------------------------------------------------------------------------
154
155 set(PV_TITLE PulseView)
156 set(PV_VERSION_STRING "0.5.0")
157
158 set(PV_GLIBMM_VERSION ${PKGDEPS_glibmm-2.4_VERSION})
159
160 include(GetGitRevisionDescription)
161
162 # Append the revision hash unless we are exactly on a tagged release.
163 git_describe(PV_TAG_VERSION_STRING --match "pulseview-${PV_VERSION_STRING}" --exact-match)
164 if(NOT PV_TAG_VERSION_STRING)
165         get_git_head_revision(PV_REVSPEC PV_HASH)
166         if(PV_HASH)
167                 string(SUBSTRING "${PV_HASH}" 0 7 PV_SHORTHASH)
168                 set(PV_VERSION_STRING "${PV_VERSION_STRING}-git-${PV_SHORTHASH}")
169         endif()
170 endif()
171
172 if(PV_VERSION_STRING MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-[-0-9a-z]*)?$")
173         set(PV_VERSION_MAJOR ${CMAKE_MATCH_1})
174         set(PV_VERSION_MINOR ${CMAKE_MATCH_2})
175         set(PV_VERSION_MICRO ${CMAKE_MATCH_3})
176         set(PV_VERSION_SUFFIX ${CMAKE_MATCH_4})
177 endif()
178
179 message("-- ${PV_TITLE} version: ${PV_VERSION_STRING}")
180
181 configure_file (
182         ${PROJECT_SOURCE_DIR}/config.h.in
183         ${PROJECT_BINARY_DIR}/config.h
184 )
185
186 #===============================================================================
187 #= Sources
188 #-------------------------------------------------------------------------------
189
190 set(pulseview_SOURCES
191         main.cpp
192         pv/application.cpp
193         pv/devicemanager.cpp
194         pv/globalsettings.cpp
195         pv/mainwindow.cpp
196         pv/session.cpp
197         pv/storesession.cpp
198         pv/util.cpp
199         pv/binding/binding.cpp
200         pv/binding/inputoutput.cpp
201         pv/binding/device.cpp
202         pv/data/analog.cpp
203         pv/data/analogsegment.cpp
204         pv/data/logic.cpp
205         pv/data/logicsegment.cpp
206         pv/data/signalbase.cpp
207         pv/data/signaldata.cpp
208         pv/data/segment.cpp
209         pv/devices/device.cpp
210         pv/devices/file.cpp
211         pv/devices/hardwaredevice.cpp
212         pv/devices/inputfile.cpp
213         pv/devices/sessionfile.cpp
214         pv/dialogs/connect.cpp
215         pv/dialogs/inputoutputoptions.cpp
216         pv/dialogs/settings.cpp
217         pv/dialogs/storeprogress.cpp
218         pv/popups/deviceoptions.cpp
219         pv/popups/channels.cpp
220         pv/prop/bool.cpp
221         pv/prop/double.cpp
222         pv/prop/enum.cpp
223         pv/prop/int.cpp
224         pv/prop/property.cpp
225         pv/prop/string.cpp
226         pv/toolbars/mainbar.cpp
227         pv/views/trace/analogsignal.cpp
228         pv/views/trace/cursor.cpp
229         pv/views/trace/cursorpair.cpp
230         pv/views/trace/flag.cpp
231         pv/views/trace/header.cpp
232         pv/views/trace/marginwidget.cpp
233         pv/views/trace/logicsignal.cpp
234         pv/views/trace/rowitem.cpp
235         pv/views/trace/ruler.cpp
236         pv/views/trace/signal.cpp
237         pv/views/trace/timeitem.cpp
238         pv/views/trace/timemarker.cpp
239         pv/views/trace/trace.cpp
240         pv/views/trace/tracegroup.cpp
241         pv/views/trace/tracepalette.cpp
242         pv/views/trace/tracetreeitem.cpp
243         pv/views/trace/tracetreeitemowner.cpp
244         pv/views/trace/triggermarker.cpp
245         pv/views/trace/view.cpp
246         pv/views/trace/viewitem.cpp
247         pv/views/trace/viewitemowner.cpp
248         pv/views/trace/viewitempaintparams.cpp
249         pv/views/trace/viewport.cpp
250         pv/views/trace/viewwidget.cpp
251         pv/views/viewbase.cpp
252         pv/views/trace/standardbar.cpp
253         pv/widgets/colourbutton.cpp
254         pv/widgets/colourpopup.cpp
255         pv/widgets/devicetoolbutton.cpp
256         pv/widgets/exportmenu.cpp
257         pv/widgets/importmenu.cpp
258         pv/widgets/popup.cpp
259         pv/widgets/popuptoolbutton.cpp
260         pv/widgets/sweeptimingwidget.cpp
261         pv/widgets/timestampspinbox.cpp
262         pv/widgets/wellarray.cpp
263 )
264
265 # This list includes only QObject derived class headers.
266 set(pulseview_HEADERS
267         pv/globalsettings.hpp
268         pv/mainwindow.hpp
269         pv/session.hpp
270         pv/storesession.hpp
271         pv/binding/device.hpp
272         pv/data/analog.hpp
273         pv/data/analogsegment.hpp
274         pv/data/logic.hpp
275         pv/data/logicsegment.hpp
276         pv/data/signalbase.hpp
277         pv/dialogs/connect.hpp
278         pv/dialogs/inputoutputoptions.hpp
279         pv/dialogs/settings.hpp
280         pv/dialogs/storeprogress.hpp
281         pv/popups/channels.hpp
282         pv/popups/deviceoptions.hpp
283         pv/prop/bool.hpp
284         pv/prop/double.hpp
285         pv/prop/enum.hpp
286         pv/prop/int.hpp
287         pv/prop/property.hpp
288         pv/prop/string.hpp
289         pv/toolbars/mainbar.hpp
290         pv/views/trace/analogsignal.hpp
291         pv/views/trace/cursor.hpp
292         pv/views/trace/flag.hpp
293         pv/views/trace/header.hpp
294         pv/views/trace/logicsignal.hpp
295         pv/views/trace/marginwidget.hpp
296         pv/views/trace/rowitem.hpp
297         pv/views/trace/ruler.hpp
298         pv/views/trace/signal.hpp
299         pv/views/trace/timeitem.hpp
300         pv/views/trace/timemarker.hpp
301         pv/views/trace/trace.hpp
302         pv/views/trace/tracegroup.hpp
303         pv/views/trace/tracetreeitem.hpp
304         pv/views/trace/triggermarker.hpp
305         pv/views/trace/view.hpp
306         pv/views/trace/viewitem.hpp
307         pv/views/trace/viewport.hpp
308         pv/views/trace/viewwidget.hpp
309         pv/views/viewbase.hpp
310         pv/views/trace/standardbar.hpp
311         pv/widgets/colourbutton.hpp
312         pv/widgets/colourpopup.hpp
313         pv/widgets/devicetoolbutton.hpp
314         pv/widgets/exportmenu.hpp
315         pv/widgets/importmenu.hpp
316         pv/widgets/popup.hpp
317         pv/widgets/popuptoolbutton.hpp
318         pv/widgets/sweeptimingwidget.hpp
319         pv/widgets/timestampspinbox.hpp
320         pv/widgets/wellarray.hpp
321 )
322
323 set(pulseview_RESOURCES
324         pulseview.qrc
325 )
326
327 if(ENABLE_SIGNALS)
328         list(APPEND pulseview_SOURCES signalhandler.cpp)
329         list(APPEND pulseview_HEADERS signalhandler.hpp)
330 endif()
331
332 if(ENABLE_DECODE)
333         list(APPEND pulseview_SOURCES
334                 pv/binding/decoder.cpp
335                 pv/data/decodesignal.cpp
336                 pv/data/decode/annotation.cpp
337                 pv/data/decode/decoder.cpp
338                 pv/data/decode/row.cpp
339                 pv/data/decode/rowdata.cpp
340                 pv/views/trace/decodetrace.cpp
341                 pv/widgets/decodergroupbox.cpp
342                 pv/widgets/decodermenu.cpp
343         )
344
345         list(APPEND pulseview_HEADERS
346                 pv/data/decodesignal.hpp
347                 pv/views/trace/decodetrace.hpp
348                 pv/widgets/decodergroupbox.hpp
349                 pv/widgets/decodermenu.hpp
350         )
351 endif()
352
353 if(WIN32)
354         # Use the sigrok icon for the pulseview.exe executable.
355         set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
356         enable_language(RC)
357         list(APPEND pulseview_SOURCES pulseviewico.rc)
358 endif()
359
360 if(ANDROID)
361         list(APPEND pulseview_SOURCES
362                 android/assetreader.cpp
363                 android/loghandler.cpp
364         )
365 endif()
366
367 qt5_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
368
369 #===============================================================================
370 #= Global Definitions
371 #-------------------------------------------------------------------------------
372
373 add_definitions(-DQT_NO_KEYWORDS)
374 add_definitions(-D__STDC_LIMIT_MACROS)
375 add_definitions(-Wall -Wextra)
376 add_definitions(-std=c++11)
377 add_definitions(-DBOOST_MATH_DISABLE_FLOAT128=1)
378
379 if(ENABLE_DECODE)
380         add_definitions(-DENABLE_DECODE)
381 endif()
382
383 if(NOT DISABLE_WERROR)
384         add_definitions(-Werror)
385 endif()
386
387 if(ENABLE_SIGNALS)
388         add_definitions(-DENABLE_SIGNALS)
389 endif()
390
391 #===============================================================================
392 #= Global Include Directories
393 #-------------------------------------------------------------------------------
394
395 include_directories(
396         ${CMAKE_CURRENT_BINARY_DIR}
397         ${CMAKE_CURRENT_SOURCE_DIR}
398         ${Boost_INCLUDE_DIRS}
399 )
400
401 if(STATIC_PKGDEPS_LIBS)
402         include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
403 else()
404         include_directories(${PKGDEPS_INCLUDE_DIRS})
405 endif()
406
407 #===============================================================================
408 #= Linker Configuration
409 #-------------------------------------------------------------------------------
410
411 link_directories(${Boost_LIBRARY_DIRS})
412
413 set(PULSEVIEW_LINK_LIBS
414         ${Boost_LIBRARIES}
415         ${QT_LIBRARIES}
416         ${CMAKE_THREAD_LIBS_INIT}
417         ${LIBATOMIC_LIBRARY}
418 )
419
420 if(STATIC_PKGDEPS_LIBS)
421         link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
422         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LDFLAGS})
423 else()
424         link_directories(${PKGDEPS_LIBRARY_DIRS})
425         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
426 endif()
427
428 if(WIN32)
429         # On Windows we need to statically link the libqsvg imageformat
430         # plugin (and the QtSvg component) for SVG graphics/icons to work.
431         # We also need QWindowsIntegrationPlugin, Qt5PlatformSupport, and all
432         # Qt libs and their dependencies.
433         add_definitions(-DQT_STATICPLUGIN)
434         list(APPEND PULSEVIEW_LINK_LIBS Qt5::QSvgPlugin)
435         list(APPEND PULSEVIEW_LINK_LIBS Qt5::QWindowsIntegrationPlugin)
436         list(APPEND PULSEVIEW_LINK_LIBS -lQt5PlatformSupport ${QT5ALL_LDFLAGS})
437 endif()
438
439 if(ANDROID)
440         list(APPEND PULSEVIEW_LINK_LIBS "-llog")
441 endif()
442
443 if(ANDROID)
444         add_library(${PROJECT_NAME} SHARED ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
445 else()
446         add_executable(${PROJECT_NAME} ${pulseview_SOURCES} ${pulseview_RESOURCES_RCC})
447 endif()
448
449 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
450
451 if(WIN32)
452         # Pass -mwindows so that no "DOS box" opens when PulseView is started.
453         set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
454 endif()
455
456 #===============================================================================
457 #= Installation
458 #-------------------------------------------------------------------------------
459
460 # Install the executable.
461 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
462
463 # Install the manpage.
464 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
465
466 # Install the desktop file.
467 install(FILES contrib/org.sigrok.PulseView.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
468
469 # Install the AppData/AppStream file.
470 install(FILES contrib/org.sigrok.PulseView.appdata.xml DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo)
471
472 # Install the PulseView icons.
473 install(FILES icons/pulseview.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps)
474 install(FILES icons/pulseview.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
475
476 # Generate Windows installer script.
477 configure_file(contrib/pulseview_cross.nsi.in contrib/pulseview_cross.nsi @ONLY)
478
479 #===============================================================================
480 #= Packaging (handled by CPack)
481 #-------------------------------------------------------------------------------
482
483 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
484 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
485 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
486 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
487 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
488 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
489 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PV_VERSION_STRING}")
490 set(CPACK_SOURCE_GENERATOR "TGZ")
491
492 include(CPack)
493
494 #===============================================================================
495 #= Tests
496 #-------------------------------------------------------------------------------
497
498 if(ENABLE_TESTS)
499         add_subdirectory(test)
500         enable_testing()
501         add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
502 endif()