mingw: Add the sigrok icon for pulseview.exe.
[pulseview.git] / CMakeLists.txt
blob8302b4828cc3fff1cfaca42926ba0481c0c50996
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.
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.
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/>.
21 cmake_minimum_required(VERSION 2.8.6)
23 include(FindPkgConfig)
24 include(GNUInstallDirs)
26 set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
28 project(pulseview)
30 #===============================================================================
31 #= User Options
32 #-------------------------------------------------------------------------------
34 option(DISABLE_WERROR "Build without -Werror" FALSE)
35 option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
36 option(ENABLE_DECODE "Build with libsigrokdecode" FALSE)
37 option(ENABLE_COTIRE "Enable cotire" FALSE)
38 option(ENABLE_TESTS "Enable unit tests" FALSE)
39 option(STATIC_PKGDEPS_LIBS "Statically link to (pkgconfig) libraries" FALSE)
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)
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)
50         # Windows does not support UNIX signals.
51         set(ENABLE_SIGNALS FALSE)
52 endif()
54 #===============================================================================
55 #= Dependencies
56 #-------------------------------------------------------------------------------
58 list(APPEND PKGDEPS libsigrok>=0.2.0)
60 if(ENABLE_DECODE)
61         list(APPEND PKGDEPS libsigrokdecode>=0.2.0)
62 endif()
64 find_package(PkgConfig)
65 pkg_check_modules(PKGDEPS REQUIRED ${PKGDEPS})
67 FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 qmake-mac)
68 find_package(Qt4 REQUIRED)
70 # Find the platform's thread library (needed for boost-thread).
71 # This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
72 find_package(Threads)
74 if(WIN32)
75 # On Windows/MinGW the we need to use 'thread_win32' instead of 'thread'.
76 # The library is named libboost_thread_win32* (not libboost_thread*).
77 find_package(Boost 1.42 COMPONENTS system thread_win32 REQUIRED)
78 else()
79 find_package(Boost 1.42 COMPONENTS system thread REQUIRED)
80 endif()
82 #===============================================================================
83 #= Config Header
84 #-------------------------------------------------------------------------------
86 set(PV_TITLE PulseView)
87 set(PV_DESCRIPTION "A GUI for sigrok")
89 set(PV_VERSION_MAJOR 0)
90 set(PV_VERSION_MINOR 1)
91 set(PV_VERSION_MICRO 0)
92 set(PV_VERSION_STRING
93         ${PV_VERSION_MAJOR}.${PV_VERSION_MINOR}.${PV_VERSION_MICRO}
96 configure_file (
97         ${PROJECT_SOURCE_DIR}/config.h.in
98         ${PROJECT_BINARY_DIR}/config.h
101 #===============================================================================
102 #= Sources
103 #-------------------------------------------------------------------------------
105 set(pulseview_SOURCES
106         main.cpp
107         pv/devicemanager.cpp
108         pv/mainwindow.cpp
109         pv/sigsession.cpp
110         pv/data/analog.cpp
111         pv/data/analogsnapshot.cpp
112         pv/data/logic.cpp
113         pv/data/logicsnapshot.cpp
114         pv/data/signaldata.cpp
115         pv/data/snapshot.cpp
116         pv/dialogs/about.cpp
117         pv/dialogs/connect.cpp
118         pv/popups/deviceoptions.cpp
119         pv/popups/probes.cpp
120         pv/prop/bool.cpp
121         pv/prop/double.cpp
122         pv/prop/enum.cpp
123         pv/prop/int.cpp
124         pv/prop/property.cpp
125         pv/prop/string.cpp
126         pv/prop/binding/binding.cpp
127         pv/prop/binding/deviceoptions.cpp
128         pv/toolbars/samplingbar.cpp
129         pv/view/analogsignal.cpp
130         pv/view/cursor.cpp
131         pv/view/cursorpair.cpp
132         pv/view/header.cpp
133         pv/view/marginwidget.cpp
134         pv/view/logicsignal.cpp
135         pv/view/ruler.cpp
136         pv/view/selectableitem.cpp
137         pv/view/signal.cpp
138         pv/view/timemarker.cpp
139         pv/view/trace.cpp
140         pv/view/tracepalette.cpp
141         pv/view/view.cpp
142         pv/view/viewport.cpp
143         pv/widgets/colourbutton.cpp
144         pv/widgets/colourpopup.cpp
145         pv/widgets/popup.cpp
146         pv/widgets/popuptoolbutton.cpp
147         pv/widgets/wellarray.cpp
150 # This list includes only QObject derived class headers.
151 set(pulseview_HEADERS
152         pv/mainwindow.h
153         pv/sigsession.h
154         pv/dialogs/about.h
155         pv/dialogs/connect.h
156         pv/popups/probes.h
157         pv/popups/deviceoptions.h
158         pv/prop/bool.h
159         pv/prop/double.h
160         pv/prop/enum.h
161         pv/prop/int.h
162         pv/prop/property.h
163         pv/prop/string.h
164         pv/toolbars/samplingbar.h
165         pv/view/cursor.h
166         pv/view/header.h
167         pv/view/logicsignal.h
168         pv/view/marginwidget.h
169         pv/view/ruler.h
170         pv/view/selectableitem.h
171         pv/view/signal.h
172         pv/view/timemarker.h
173         pv/view/trace.h
174         pv/view/view.h
175         pv/view/viewport.h
176         pv/widgets/colourbutton.h
177         pv/widgets/colourpopup.h
178         pv/widgets/popup.h
179         pv/widgets/popuptoolbutton.h
180         pv/widgets/wellarray.h
183 set(pulseview_FORMS
184         pv/dialogs/about.ui
187 set(pulseview_RESOURCES
188         pulseview.qrc
191 if(ENABLE_SIGNALS)
192         list(APPEND pulseview_SOURCES signalhandler.cpp)
193         list(APPEND pulseview_HEADERS signalhandler.h)
194 endif()
196 if(ENABLE_DECODE)
197         list(APPEND pulseview_SOURCES
198                 pv/data/decoderstack.cpp
199                 pv/data/decode/annotation.cpp
200                 pv/data/decode/decoder.cpp
201                 pv/prop/binding/decoderoptions.cpp
202                 pv/view/decodetrace.cpp
203                 pv/widgets/decodergroupbox.cpp
204                 pv/widgets/decodermenu.cpp
205                 pv/widgets/wellarray.cpp
206         )
208         list(APPEND pulseview_HEADERS
209                 pv/data/decoderstack.h
210                 pv/view/decodetrace.h
211                 pv/widgets/decodergroupbox.h
212                 pv/widgets/decodermenu.h
213         )
214 endif()
216 if(WIN32)
217         # Use the sigrok icon for the pulseview.exe executable.
218         set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_RC_COMPILER} -O coff -I${CMAKE_CURRENT_SOURCE_DIR} <SOURCE> <OBJECT>")
219         enable_language(RC)
220         list(APPEND pulseview_SOURCES pulseviewico.rc)
221 endif()
223 qt4_wrap_cpp(pulseview_HEADERS_MOC ${pulseview_HEADERS})
224 qt4_wrap_ui(pulseview_FORMS_HEADERS ${pulseview_FORMS})
225 qt4_add_resources(pulseview_RESOURCES_RCC ${pulseview_RESOURCES})
227 include(${QT_USE_FILE})
229 #===============================================================================
230 #= Global Definitions
231 #-------------------------------------------------------------------------------
233 add_definitions(${QT_DEFINITIONS})
234 add_definitions(-D__STDC_LIMIT_MACROS)
235 add_definitions(-Wall -Wextra)
237 if(ENABLE_DECODE)
238         add_definitions(-DENABLE_DECODE)
239 endif()
241 if(NOT DISABLE_WERROR)
242         add_definitions(-Werror)
243 endif()
245 #===============================================================================
246 #= Global Include Directories
247 #-------------------------------------------------------------------------------
249 include_directories(
250         ${CMAKE_CURRENT_BINARY_DIR}
251         ${CMAKE_CURRENT_SOURCE_DIR}
252         ${Boost_INCLUDE_DIRS}
255 if(STATIC_PKGDEPS_LIBS)
256         include_directories(${PKGDEPS_STATIC_INCLUDE_DIRS})
257 else()
258         include_directories(${PKGDEPS_INCLUDE_DIRS})
259 endif()
261 #===============================================================================
262 #= Linker Configuration
263 #-------------------------------------------------------------------------------
265 link_directories(${Boost_LIBRARY_DIRS})
267 set(PULSEVIEW_LINK_LIBS
268         ${Boost_LIBRARIES}
269         ${CMAKE_THREAD_LIBS_INIT}
270         ${QT_LIBRARIES}
273 if(STATIC_PKGDEPS_LIBS)
274         link_directories(${PKGDEPS_STATIC_LIBRARY_DIRS})
275         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_STATIC_LIBRARIES})
276 else()
277         link_directories(${PKGDEPS_LIBRARY_DIRS})
278         list(APPEND PULSEVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
279 endif()
281 add_executable(${PROJECT_NAME}
282         ${pulseview_SOURCES}
283         ${pulseview_HEADERS_MOC}
284         ${pulseview_FORMS_HEADERS}
285         ${pulseview_RESOURCES_RCC}
288 target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
290 if(WIN32)
291 # Pass -mwindows so that no "DOS box" will open when PulseView is started.
292 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-mwindows")
293 endif()
295 if(ENABLE_COTIRE)
296         include(cotire)
297         cotire(${PROJECT_NAME})
298 endif()
300 #===============================================================================
301 #= Installation
302 #-------------------------------------------------------------------------------
304 # Install the executable.
305 install(TARGETS ${PROJECT_NAME} DESTINATION bin/)
307 # Install the manpage.
308 install(FILES doc/pulseview.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc)
310 #===============================================================================
311 #= Packaging (handled by CPack)
312 #-------------------------------------------------------------------------------
314 set(CPACK_PACKAGE_VERSION_MAJOR ${PV_VERSION_MAJOR})
315 set(CPACK_PACKAGE_VERSION_MINOR ${PV_VERSION_MINOR})
316 set(CPACK_PACKAGE_VERSION_PATCH ${PV_VERSION_MICRO})
317 set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README)
318 set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
319 set(CPACK_SOURCE_IGNORE_FILES ${CMAKE_CURRENT_BINARY_DIR} ".gitignore" ".git")
320 set(CPACK_SOURCE_PACKAGE_FILE_NAME
321         "${CMAKE_PROJECT_NAME}-${PV_VERSION_MAJOR}.${PV_VERSION_MINOR}.${PV_VERSION_MICRO}")
322 set(CPACK_SOURCE_GENERATOR "TGZ")
324 include(CPack)
326 #===============================================================================
327 #= Tests
328 #-------------------------------------------------------------------------------
330 if(ENABLE_TESTS)
331         add_subdirectory(test)
332         enable_testing()
333         add_test(test ${CMAKE_CURRENT_BINARY_DIR}/test/pulseview-test)
334 endif()