make gdk-pixbuf dependency really optional

This commit is contained in:
progandy 2015-12-20 17:37:52 +01:00
parent 66554698a0
commit 21014e606b
9 changed files with 62 additions and 13 deletions

View file

@ -29,6 +29,7 @@ IF(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND)
# Report results # Report results
IF(GDK_PIXBUF_LIBRARIES AND GDK_PIXBUF_INCLUDE_DIRS) IF(GDK_PIXBUF_LIBRARIES AND GDK_PIXBUF_INCLUDE_DIRS)
SET(GDK_PIXBUF_FOUND 1) SET(GDK_PIXBUF_FOUND 1)
SET(GdkPixbuf_FOUND 1)
IF(NOT GdkPixbuf_FIND_QUIETLY) IF(NOT GdkPixbuf_FIND_QUIETLY)
MESSAGE(STATUS "Found GdkPixbuf: ${GDK_PIXBUF_LIBRARIES}") MESSAGE(STATUS "Found GdkPixbuf: ${GDK_PIXBUF_LIBRARIES}")
ENDIF(NOT GdkPixbuf_FIND_QUIETLY) ENDIF(NOT GdkPixbuf_FIND_QUIETLY)
@ -41,6 +42,8 @@ IF(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND)
ENDIF(NOT GdkPixbuf_FIND_QUIETLY) ENDIF(NOT GdkPixbuf_FIND_QUIETLY)
ENDIF(GdkPixbuf_FIND_REQUIRED) ENDIF(GdkPixbuf_FIND_REQUIRED)
ENDIF(GDK_PIXBUF_LIBRARIES AND GDK_PIXBUF_INCLUDE_DIRS) ENDIF(GDK_PIXBUF_LIBRARIES AND GDK_PIXBUF_INCLUDE_DIRS)
ELSE(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND)
SET(GdkPixbuf_FOUND 1)
ENDIF(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND) ENDIF(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND)
# Hide advanced variables from CMake GUIs # Hide advanced variables from CMake GUIs

View file

@ -46,6 +46,7 @@ option(enable-swaybg "Enables the wallpaper utility" YES)
option(enable-swaybar "Enables the swaybar utility" YES) option(enable-swaybar "Enables the swaybar utility" YES)
option(enable-swaygrab "Enables the swaygrab utility" YES) option(enable-swaygrab "Enables the swaygrab utility" YES)
option(enable-swaymsg "Enables the swaymsg utility" YES) option(enable-swaymsg "Enables the swaymsg utility" YES)
option(enable-gdk-pixbuf "Use Pixbuf to support more image formats" YES)
find_package(JsonC REQUIRED) find_package(JsonC REQUIRED)
find_package(PCRE REQUIRED) find_package(PCRE REQUIRED)
@ -60,6 +61,17 @@ find_package(PAM)
include(FeatureSummary) include(FeatureSummary)
include(Manpage) include(Manpage)
if (enable-gdk-pixbuf)
if (GDK_PIXBUF_FOUND)
set(WITH_GDK_PIXBUF YES)
add_definitions(-DWITH_GDK_PIXBUF)
else()
message(WARNING "gdk-pixbuf required but not found, only png images supported.")
endif()
else()
message(STATUS "Building without gdk-pixbuf, only png images supported.")
endif()
include_directories(include) include_directories(include)
add_subdirectory(protocols) add_subdirectory(protocols)
@ -68,10 +80,10 @@ add_subdirectory(wayland)
add_subdirectory(sway) add_subdirectory(sway)
if(enable-swaybg) if(enable-swaybg)
if(CAIRO_FOUND AND PANGO_FOUND AND GDK_PIXBUF_FOUND) if(CAIRO_FOUND AND PANGO_FOUND)
add_subdirectory(swaybg) add_subdirectory(swaybg)
else() else()
message(WARNING "Not building swaybg - cairo, pango, and gdk-pixbuf are required.") message(WARNING "Not building swaybg - cairo, and pango are required.")
endif() endif()
endif() endif()
if(enable-swaymsg) if(enable-swaymsg)
@ -81,17 +93,17 @@ if(enable-swaygrab)
add_subdirectory(swaygrab) add_subdirectory(swaygrab)
endif() endif()
if(enable-swaybar) if(enable-swaybar)
if(CAIRO_FOUND AND PANGO_FOUND AND GDK_PIXBUF_FOUND) if(CAIRO_FOUND AND PANGO_FOUND)
add_subdirectory(swaybar) add_subdirectory(swaybar)
else() else()
message(WARNING "Not building swaybar - cairo, pango, and gdk-pixbuf are required.") message(WARNING "Not building swaybar - cairo, and pango are required.")
endif() endif()
endif() endif()
if(enable-swaylock) if(enable-swaylock)
if(CAIRO_FOUND AND PANGO_FOUND AND GDK_PIXBUF_FOUND AND PAM_FOUND) if(CAIRO_FOUND AND PANGO_FOUND AND PAM_FOUND)
add_subdirectory(swaylock) add_subdirectory(swaylock)
else() else()
message(WARNING "Not building swaylock - cairo, pango, gdk-pixbuf, and PAM are required.") message(WARNING "Not building swaylock - cairo, pango, and PAM are required.")
endif() endif()
endif() endif()

View file

@ -1,8 +1,10 @@
#ifndef _SWAY_CAIRO_H #ifndef _SWAY_CAIRO_H
#define _SWAY_CAIRO_H #define _SWAY_CAIRO_H
#ifdef WITH_GDK_PIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf); cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf);
#endif //WITH_GDK_PIXBUF
#endif #endif

View file

@ -3,7 +3,6 @@ include_directories(
${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_CLIENT_INCLUDE_DIR}
${CAIRO_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS}
${PANGO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS}
${GDK_PIXBUF_INCLUDE_DIRS}
) )
add_executable(swaybg add_executable(swaybg
@ -17,10 +16,18 @@ target_link_libraries(swaybg
${WAYLAND_CURSOR_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES}
${CAIRO_LIBRARIES} ${CAIRO_LIBRARIES}
${PANGO_LIBRARIES} ${PANGO_LIBRARIES}
${GDK_PIXBUF_LIBRARIES}
m m
) )
if (WITH_GDK_PIXBUF)
include_directories(
${GDK_PIXBUF_INCLUDE_DIRS}
)
target_link_libraries(swaybg
${GDK_PIXBUF_LIBRARIES}
)
endif()
install( install(
TARGETS swaybg TARGETS swaybg
RUNTIME RUNTIME

View file

@ -56,6 +56,7 @@ int main(int argc, const char **argv) {
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface); desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
list_add(surfaces, window); list_add(surfaces, window);
#ifdef WITH_GDK_PIXBUF
GError *err = NULL; GError *err = NULL;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[2], &err); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[2], &err);
if (!pixbuf) { if (!pixbuf) {
@ -63,6 +64,9 @@ int main(int argc, const char **argv) {
} }
cairo_surface_t *image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf); cairo_surface_t *image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf);
g_object_unref(pixbuf); g_object_unref(pixbuf);
#else
cairo_surface_t *image = cairo_image_surface_create_from_png(argv[2]);
#endif //WITH_GDK_PIXBUF
if (!image) { if (!image) {
sway_abort("Failed to read background image."); sway_abort("Failed to read background image.");
} }

View file

@ -2,7 +2,6 @@ include_directories(
${PROTOCOLS_INCLUDE_DIRS} ${PROTOCOLS_INCLUDE_DIRS}
${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_CLIENT_INCLUDE_DIR}
${CAIRO_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS}
${GDK_PIXBUF_INCLUDE_DIRS}
${PANGO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS}
${PAM_INCLUDE_DIRS} ${PAM_INCLUDE_DIRS}
) )
@ -17,12 +16,20 @@ target_link_libraries(swaylock
${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES}
${WAYLAND_CURSOR_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES}
${CAIRO_LIBRARIES} ${CAIRO_LIBRARIES}
${GDK_PIXBUF_LIBRARIES}
${PANGO_LIBRARIES} ${PANGO_LIBRARIES}
${PAM_LIBRARIES} ${PAM_LIBRARIES}
m m
) )
if (WITH_GDK_PIXBUF)
include_directories(
${GDK_PIXBUF_INCLUDE_DIRS}
)
target_link_libraries(swaylock
${GDK_PIXBUF_LIBRARIES}
)
endif()
install( install(
TARGETS swaylock TARGETS swaylock
RUNTIME RUNTIME

View file

@ -113,6 +113,7 @@ int main(int argc, char **argv) {
registry->input->notify = notify_key; registry->input->notify = notify_key;
#ifdef WITH_GDK_PIXBUF
GError *err = NULL; GError *err = NULL;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[1], &err); // TODO: Parse i3lock arguments
if (!pixbuf) { if (!pixbuf) {
@ -120,6 +121,9 @@ int main(int argc, char **argv) {
} }
cairo_surface_t *image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf); cairo_surface_t *image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf);
g_object_unref(pixbuf); g_object_unref(pixbuf);
#else
cairo_surface_t *image = cairo_image_surface_create_from_png(argv[1]);
#endif //WITH_GDK_PIXBUF
if (!image) { if (!image) {
sway_abort("Failed to read background image."); sway_abort("Failed to read background image.");
} }

View file

@ -1,7 +1,6 @@
include_directories( include_directories(
${PROTOCOLS_INCLUDE_DIRS} ${PROTOCOLS_INCLUDE_DIRS}
${PANGO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS}
${GDK_PIXBUF_INCLUDE_DIRS}
${XKBCOMMON_INCLUDE_DIRS} ${XKBCOMMON_INCLUDE_DIRS}
) )
@ -17,6 +16,14 @@ target_link_libraries(sway-wayland
sway-common sway-common
sway-protocols sway-protocols
${PANGO_LIBRARIES} ${PANGO_LIBRARIES}
${GDK_PIXBUF_LIBRARIES}
${XKBCOMMON_LIBRARIES} ${XKBCOMMON_LIBRARIES}
) )
if (WITH_GDK_PIXBUF)
include_directories(
${GDK_PIXBUF_INCLUDE_DIRS}
)
target_link_libraries(sway-wayland
${GDK_PIXBUF_LIBRARIES}
)
endif()

View file

@ -1,7 +1,9 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <cairo/cairo.h> #include <cairo/cairo.h>
#include "client/cairo.h" #include "client/cairo.h"
#ifdef WITH_GDK_PIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h>
#ifndef GDK_PIXBUF_CHECK_VERSION #ifndef GDK_PIXBUF_CHECK_VERSION
#define GDK_PIXBUF_CHECK_VERSION(major,minor,micro) \ #define GDK_PIXBUF_CHECK_VERSION(major,minor,micro) \
(GDK_PIXBUF_MAJOR > (major) || \ (GDK_PIXBUF_MAJOR > (major) || \
@ -103,3 +105,4 @@ cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdk
cairo_surface_mark_dirty(cs); cairo_surface_mark_dirty(cs);
return cs; return cs;
} }
#endif //WITH_GDK_PIXBUF