update release generator (add more git mirrors)
[tint2-nick87720z.git] / CMakeLists.txt
blob336dff99851d67bf6ce2ac4f520b6e2e8e174135
1 project( tint2 )
2 cmake_minimum_required( VERSION 2.8.5 )
4 option( ENABLE_BATTERY "Enable battery status plugin" ON )
5 option( ENABLE_TINT2CONF "Enable tint2conf build, a GTK+3 theme configurator for tint2" ON )
6 option( ENABLE_EXTRA_THEMES "Install additional tint2 themes" ON )
7 option( ENABLE_RSVG "Rsvg support (launcher only)" ON )
8 option( ENABLE_SN "Startup notification support" ON )
9 option( ENABLE_TRACING "Build tint2 with tracing instrumentation" OFF )
10 option( ENABLE_ASAN "Build tint2 with AddressSanitizer" OFF )
11 option( ENABLE_BACKTRACE "Dump a backtrace in case of fatal errors (e.g. X11 I/O error)" OFF )
12 option( ENABLE_BACKTRACE_ON_SIGNAL "Dump a backtrace also when receiving signals such as SIGSEGV" OFF )
13 if( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
14   option( ENABLE_UEVENT "Kernel event handling support" ON )
15 endif( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
17 include( GNUInstallDirs )
18 if(NOT docdir)
19   set(docdir ${CMAKE_INSTALL_DOCDIR})
20 endif()
21 if(NOT htmldir)
22   set(htmldir ${docdir}/html)
23 endif()
25 include( FindPkgConfig )
26 include( CheckLibraryExists )
27 include( CheckCSourceCompiles )
28 pkg_check_modules( X11 REQUIRED x11 xcomposite xdamage xinerama xext xrender xrandr>=1.3 )
29 pkg_check_modules( PANGOCAIRO REQUIRED pangocairo )
30 pkg_check_modules( PANGO REQUIRED pango )
31 pkg_check_modules( CAIRO REQUIRED cairo )
32 pkg_check_modules( GLIB2 REQUIRED glib-2.0 )
33 pkg_check_modules( GOBJECT2 REQUIRED gobject-2.0 )
34 pkg_check_modules( IMLIB2 REQUIRED imlib2>=1.4.2 )
36 if(ENABLE_BACKTRACE)
37         check_c_source_compiles(
38                 "#include <stdlib.h>\n#include <execinfo.h>\nint main () { backtrace(NULL, 0); }"
39                 BACKTRACE_LIBC)
41         if(BACKTRACE_LIBC)
42                 set(BACKTRACE_LIBC_FOUND TRUE)
43                 set(BACKTRACE_L_FLAGS "-rdynamic")
44         else()
45                 pkg_check_modules( UNWIND libunwind )
46                 find_library(EXECINFO_LIBRARIES NAMES execinfo)
47                 if(EXECINFO_LIBRARIES OR EXECINFO_LIBRARIES_FOUND)
48                         set(EXECINFO_FOUND TRUE)
49                         set(EXECINFO_LIBRARIES "-lexecinfo")
50                         set(BACKTRACE_L_FLAGS "-rdynamic")
51                 else()
52                         set(EXECINFO_LIBRARIES "")
53                         set(BACKTRACE_L_FLAGS "")
54                 endif()
55         endif()
57         if( NOT BACKTRACE_LIBC_FOUND AND NOT UNWIND_FOUND AND NOT EXECINFO_FOUND )
58           message( WARNING "Backtrace support not available. You can enable it by installing libexecinfo or libunwind." )
59         endif()
60 else()
61         set(EXECINFO_LIBRARIES "")
62         set(BACKTRACE_L_FLAGS "")
63 endif()
65 check_c_source_compiles(
66     "#define print(x) _Generic((x), default : print_unknown)(x) \n void print_unknown(){} \n int main () { print(0); }"
67     HAS_GENERIC)
69 if(HAS_GENERIC)
70     add_definitions(-DHAS_GENERIC)
71     set(CSTD "c11")
72 else()
73     set(CSTD "c99")
74 endif(HAS_GENERIC)
76 if( ENABLE_RSVG )
77 pkg_check_modules( RSVG librsvg-2.0>=2.14.0 )
78 endif( ENABLE_RSVG )
80 if( ENABLE_SN )
81 pkg_check_modules( SN libstartup-notification-1.0>=0.12 )
82 endif(ENABLE_SN)
84 find_library( RT_LIBRARY rt )
86 if( NOT X11_FOUND OR NOT PANGOCAIRO_FOUND OR NOT PANGO_FOUND OR NOT CAIRO_FOUND OR NOT GLIB2_FOUND OR NOT GOBJECT2_FOUND OR NOT IMLIB2_FOUND )
87   message( FATAL_ERROR "Not all dependencies fulfilled. See https://gitlab.com/o9000/tint2/wikis/Install" )
88 endif( NOT X11_FOUND OR NOT PANGOCAIRO_FOUND OR NOT PANGO_FOUND OR NOT CAIRO_FOUND OR NOT GLIB2_FOUND OR NOT GOBJECT2_FOUND OR NOT IMLIB2_FOUND )
90 string( REPLACE ";" " " FLAGS_REPLACED "${IMLIB2_LDFLAGS}" )
91 set( CMAKE_REQUIRED_FLAGS "${FLAGS_REPLACED}" )
92 check_library_exists( "${IMLIB2_LIBRARIES}" "imlib_context_set_display" "${IMLIB2_LIBRARY_DIRS}" IMLIB_BUILD_WITH_X )
93 if( NOT IMLIB_BUILD_WITH_X )
94   message( FATAL_ERROR "Imlib is not built with X support" )
95 endif( NOT IMLIB_BUILD_WITH_X )
98 add_definitions( -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_WITH_GETLINE )
100 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
101   add_definitions( -D_POSIX_C_SOURCE=200809L )
102 endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
105 include_directories( ${PROJECT_BINARY_DIR}
106                      src
107                      src/battery
108                      src/clock
109                      src/systray
110                      src/taskbar
111                      src/launcher
112                      src/tooltip
113                      src/util
114                      src/execplugin
115                      src/button
116                      src/freespace
117                      src/separator
118                      ${X11_INCLUDE_DIRS}
119                      ${PANGOCAIRO_INCLUDE_DIRS}
120                      ${PANGO_INCLUDE_DIRS}
121                      ${CAIRO_INCLUDE_DIRS}
122                      ${GLIB2_INCLUDE_DIRS}
123                      ${GOBJECT2_INCLUDE_DIRS}
124                      ${IMLIB2_INCLUDE_DIRS}
125                      ${RSVG_INCLUDE_DIRS}
126                      ${SN_INCLUDE_DIRS} )
128 set( SOURCES src/config-keys.c
129              src/config.c
130              src/panel.c
131              src/util/server.c
132              src/main.c
133              src/init.c
134              src/util/signals.c
135              src/util/tracing.c
136              src/mouse_actions.c
137              src/drag_and_drop.c
138              src/default_icon.c
139              src/clock/clock.c
140              src/systray/systraybar.c
141              src/launcher/launcher.c
142              src/launcher/apps-common.c
143              src/launcher/icon-theme-common.c
144              src/launcher/xsettings-client.c
145              src/launcher/xsettings-common.c
146              src/taskbar/task.c
147              src/taskbar/taskbar.c
148              src/taskbar/taskbarname.c
149              src/tooltip/tooltip.c
150              src/execplugin/execplugin.c
151              src/button/button.c
152              src/freespace/freespace.c
153              src/separator/separator.c
154              src/tint2rc.c
155              src/util/area.c
156              src/util/bt.c
157              src/util/common.c
158              src/util/fps_distribution.c
159              src/util/strnatcmp.c
160              src/util/timer.c
161              src/util/cache.c
162              src/util/color.c
163              src/util/strlcat.c
164              src/util/print.c
165              src/util/gradient.c
166              src/util/test.c
167              src/util/uevent.c
168              src/util/window.c )
170 if( ENABLE_BATTERY )
171   set( SOURCES ${SOURCES} src/battery/battery.c)
173   if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
174     set( SOURCES ${SOURCES} src/battery/linux.c)
175   elseif(CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
176     set( SOURCES ${SOURCES} src/battery/freebsd.c)
177   elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
178     set( SOURCES ${SOURCES} src/battery/freebsd.c)
179   elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
180     set( SOURCES ${SOURCES} src/battery/openbsd.c)
181   elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
182     set( SOURCES ${SOURCES} src/battery/openbsd.c)
183   else(CMAKE_SYSTEM_NAME STREQUAL "Linux")
184     set( SOURCES ${SOURCES} src/battery/dummy.c)
185   endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
187   add_definitions( -DENABLE_BATTERY )
188 endif( ENABLE_BATTERY )
190 if( ENABLE_RSVG )
191   if( RSVG_FOUND )
192         add_definitions( -DHAVE_RSVG )
193   else()
194     message( FATAL_ERROR "SVG support enabled yet dependency not fulfilled: librsvg-2.0" )
195   endif( RSVG_FOUND )
196 endif( ENABLE_RSVG )
198 if( ENABLE_SN )
199   if( SN_FOUND )
200     add_definitions( -DHAVE_SN -DSN_API_NOT_YET_FROZEN )
201   else()
202     message( FATAL_ERROR "Startup notification support enabled yet dependency not fulfilled: libstartup-notification-1.0" )
203   endif( SN_FOUND )
204 endif( ENABLE_SN)
206 if( ENABLE_UEVENT )
207   add_definitions( -DENABLE_UEVENT )
208 endif( ENABLE_UEVENT )
210 if(ENABLE_BACKTRACE)
211         if(BACKTRACE_LIBC_FOUND)
212           add_definitions( -DENABLE_EXECINFO )
213         endif()
215         if( UNWIND_FOUND )
216           add_definitions( -DENABLE_LIBUNWIND )
217         endif( UNWIND_FOUND )
219         if( EXECINFO_FOUND )
220           add_definitions( -DENABLE_EXECINFO )
221         endif( EXECINFO_FOUND )
223         if(ENABLE_BACKTRACE_ON_SIGNAL)
224                 add_definitions( -DBACKTRACE_ON_SIGNAL )
225         endif()
226 else()
227         add_definitions( -DDISABLE_BACKTRACE )
228 endif()
230 if( ENABLE_TINT2CONF )
231   add_definitions( -DHAVE_VERSION_H )
232   add_subdirectory( src/tint2conf )
233   add_dependencies( tint2conf version )
234 endif( ENABLE_TINT2CONF )
236 if( ENABLE_ASAN )
237   SET(ASAN_C_FLAGS " -O0 -g3 -fsanitize=address -fno-common -fno-omit-frame-pointer -rdynamic -Wshadow")
238   SET(ASAN_L_FLAGS " -O0 -g3 -fsanitize=address -fno-common -fno-omit-frame-pointer -rdynamic -fuse-ld=gold ")
239 else()
240   SET(ASAN_C_FLAGS "")
241   SET(ASAN_L_FLAGS "")
242 endif()
244 if( ENABLE_TRACING )
245   add_definitions( -DHAVE_TRACING )
246   SET(TRACING_C_FLAGS " -finstrument-functions -finstrument-functions-exclude-file-list=tracing.c -finstrument-functions-exclude-function-list=get_time,gettime -O0 -g3 -fno-common -fno-omit-frame-pointer -rdynamic")
247   SET(TRACING_L_FLAGS " -O0 -g3 -fno-common -fno-omit-frame-pointer -rdynamic")
248 else()
249   SET(TRACING_C_FLAGS "")
250   SET(TRACING_L_FLAGS "")
251 endif()
253 add_custom_target( version ALL "${PROJECT_SOURCE_DIR}/get_version.sh" )
255 #~ SET(CONFIG_KEYS_FILENAME_BASE "${PROJECT_SOURCE_DIR}/src/config-keys")
256 #~ add_custom_command( OUTPUT  "${CONFIG_KEYS_FILENAME_BASE}.c"    "${CONFIG_KEYS_FILENAME_BASE}.h"
257                     #~ DEPENDS "${CONFIG_KEYS_FILENAME_BASE}-list" "${CONFIG_KEYS_FILENAME_BASE}.c.in" "${CONFIG_KEYS_FILENAME_BASE}.h.in"
258                     #~ COMMAND codegen/srcpp LIST2CODE_CMD src/config-keys.c src/config-keys.h
259                     #~ VERBATIM
260                     #~ WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" )
262 link_directories( ${X11_LIBRARY_DIRS}
263                   ${PANGOCAIRO_LIBRARY_DIRS}
264                   ${PANGO_LIBRARY_DIRS}
265                   ${CAIRO_LIBRARY_DIRS}
266                   ${GLIB2_LIBRARY_DIRS}
267                   ${GOBJECT2_LIBRARY_DIRS}
268                   ${IMLIB2_LIBRARY_DIRS}
269                   ${RSVG_LIBRARY_DIRS}
270                   ${SN_LIBRARY_DIRS} )
271 add_executable(tint2 ${SOURCES})
272 target_link_libraries( tint2 ${X11_LIBRARIES}
273                              ${PANGOCAIRO_LIBRARIES}
274                              ${PANGO_LIBRARIES}
275                              ${CAIRO_LIBRARIES}
276                              ${GLIB2_LIBRARIES}
277                              ${GOBJECT2_LIBRARIES}
278                                                          ${IMLIB2_LIBRARIES}
279                                                          ${UNWIND_LIBRARIES}
280                                                          ${EXECINFO_LIBRARIES} )
281 if( ENABLE_RSVG )
282   target_link_libraries( tint2 ${RSVG_LIBRARIES} )
283 endif( ENABLE_RSVG )
284 if( ENABLE_SN )
285   target_link_libraries( tint2 ${SN_LIBRARIES} )
286 endif( ENABLE_SN )
287 if( RT_LIBRARY )
288   target_link_libraries( tint2 ${RT_LIBRARY} )
289 endif( RT_LIBRARY )
291 target_link_libraries( tint2 m )
293 add_dependencies( tint2 version )
294 set_target_properties( tint2 PROPERTIES COMPILE_FLAGS "-Wall -Wpointer-arith -fno-strict-aliasing -pthread -std=${CSTD} ${ASAN_C_FLAGS} ${TRACING_C_FLAGS}" )
295 set_target_properties( tint2 PROPERTIES LINK_FLAGS "-pthread -fno-strict-aliasing ${ASAN_L_FLAGS} ${BACKTRACE_L_FLAGS}  ${TRACING_L_FLAGS}" )
297 add_executable(tint2-send src/tint2-send/tint2-send.c)
298 target_link_libraries(tint2-send ${X11_LIBRARIES})
300 install( TARGETS tint2 DESTINATION bin )
301 install( TARGETS tint2-send DESTINATION bin )
302 install( FILES tint2.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps )
303 install( FILES tint2.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications )
304 install( FILES themes/tint2rc DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/xdg/tint2 )
305 install( FILES default_icon.png DESTINATION ${CMAKE_INSTALL_DATADIR}/tint2 )
306 install( FILES AUTHORS ChangeLog README.md doc/tint2.md DESTINATION ${docdir} )
307 install( FILES doc/manual.html doc/readme.html DESTINATION ${htmldir} )
308 install( DIRECTORY doc/images DESTINATION ${htmldir} )
309 install( FILES doc/tint2.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 )
310 if( ENABLE_EXTRA_THEMES )
311   add_subdirectory(themes)
312 endif( ENABLE_EXTRA_THEMES )