From da26d69cb1b21d582a81af0cad7342fab6596eed Mon Sep 17 00:00:00 2001 From: Greg V Date: Thu, 8 Dec 2016 15:34:08 +0300 Subject: [PATCH] Fix build on FreeBSD - Make sure CMake always finds absolute paths for Cairo, Pango and GdkPixbuf - Add forgotten json-c include path to swaymsg/CMakeLists.txt - Disable -Werror because of assert warnings - Add correct /proc/pid/file path for FreeBSD - Use libepoll-shim on FreeBSD - Only use Linux capabilities on, well, Linux --- CMake/FindCairo.cmake | 61 +++++++++++++++++------------------- CMake/FindEpollShim.cmake | 17 ++++++++++ CMake/FindGdkPixbuf.cmake | 65 +++++++++++++++++---------------------- CMake/FindPango.cmake | 61 +++++++++++++++++------------------- CMakeLists.txt | 4 +++ sway/CMakeLists.txt | 5 ++- sway/ipc-server.c | 5 +++ sway/main.c | 2 ++ sway/security.c | 4 +++ swaymsg/CMakeLists.txt | 4 +++ wayland/CMakeLists.txt | 2 ++ 11 files changed, 127 insertions(+), 103 deletions(-) create mode 100644 CMake/FindEpollShim.cmake diff --git a/CMake/FindCairo.cmake b/CMake/FindCairo.cmake index 36c28095..10ab8fb0 100644 --- a/CMake/FindCairo.cmake +++ b/CMake/FindCairo.cmake @@ -8,40 +8,35 @@ # Define CAIRO_MIN_VERSION for which version desired. # -INCLUDE(FindPkgConfig) +find_package(PkgConfig) -IF(Cairo_FIND_REQUIRED) - SET(_pkgconfig_REQUIRED "REQUIRED") -ELSE(Cairo_FIND_REQUIRED) - SET(_pkgconfig_REQUIRED "") -ENDIF(Cairo_FIND_REQUIRED) +if(Cairo_FIND_REQUIRED) + set(_pkgconfig_REQUIRED "REQUIRED") +else(Cairo_FIND_REQUIRED) + set(_pkgconfig_REQUIRED "") +endif(Cairo_FIND_REQUIRED) -IF(CAIRO_MIN_VERSION) - PKG_SEARCH_MODULE(CAIRO ${_pkgconfig_REQUIRED} cairo>=${CAIRO_MIN_VERSION}) -ELSE(CAIRO_MIN_VERSION) - PKG_SEARCH_MODULE(CAIRO ${_pkgconfig_REQUIRED} cairo) -ENDIF(CAIRO_MIN_VERSION) +if(CAIRO_MIN_VERSION) + pkg_check_modules(CAIRO ${_pkgconfig_REQUIRED} cairo>=${CAIRO_MIN_VERSION}) +else(CAIRO_MIN_VERSION) + pkg_check_modules(CAIRO ${_pkgconfig_REQUIRED} cairo) +endif(CAIRO_MIN_VERSION) -IF(NOT CAIRO_FOUND AND NOT PKG_CONFIG_FOUND) - FIND_PATH(CAIRO_INCLUDE_DIRS cairo.h) - FIND_LIBRARY(CAIRO_LIBRARIES cairo) +if(NOT CAIRO_FOUND AND NOT PKG_CONFIG_FOUND) + find_path(CAIRO_INCLUDE_DIRS cairo.h) + find_library(CAIRO_LIBRARIES cairo) +else(NOT CAIRO_FOUND AND NOT PKG_CONFIG_FOUND) + # Make paths absolute https://stackoverflow.com/a/35476270 + # Important on FreeBSD because /usr/local/lib is not on /usr/bin/ld's default path + set(CAIRO_LIBS_ABSOLUTE) + foreach(lib ${CAIRO_LIBRARIES}) + set(var_name CAIRO_${lib}_ABS) + find_library(${var_name} ${lib} ${CAIRO_LIBRARY_DIRS}) + list(APPEND CAIRO_LIBS_ABSOLUTE ${${var_name}}) + endforeach() + set(CAIRO_LIBRARIES ${CAIRO_LIBS_ABSOLUTE}) +endif(NOT CAIRO_FOUND AND NOT PKG_CONFIG_FOUND) - # Report results - IF(CAIRO_LIBRARIES AND CAIRO_INCLUDE_DIRS) - SET(CAIRO_FOUND 1) - IF(NOT Cairo_FIND_QUIETLY) - MESSAGE(STATUS "Found Cairo: ${CAIRO_LIBRARIES}") - ENDIF(NOT Cairo_FIND_QUIETLY) - ELSE(CAIRO_LIBRARIES AND CAIRO_INCLUDE_DIRS) - IF(Cairo_FIND_REQUIRED) - MESSAGE(SEND_ERROR "Could not find Cairo") - ELSE(Cairo_FIND_REQUIRED) - IF(NOT Cairo_FIND_QUIETLY) - MESSAGE(STATUS "Could not find Cairo") - ENDIF(NOT Cairo_FIND_QUIETLY) - ENDIF(Cairo_FIND_REQUIRED) - ENDIF(CAIRO_LIBRARIES AND CAIRO_INCLUDE_DIRS) -ENDIF(NOT CAIRO_FOUND AND NOT PKG_CONFIG_FOUND) - -# Hide advanced variables from CMake GUIs -MARK_AS_ADVANCED(CAIRO_LIBRARIES CAIRO_INCLUDE_DIRS) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CAIRO DEFAULT_MSG CAIRO_LIBRARIES CAIRO_INCLUDE_DIRS) +mark_as_advanced(CAIRO_LIBRARIES CAIRO_INCLUDE_DIRS) diff --git a/CMake/FindEpollShim.cmake b/CMake/FindEpollShim.cmake new file mode 100644 index 00000000..b6bed142 --- /dev/null +++ b/CMake/FindEpollShim.cmake @@ -0,0 +1,17 @@ +# - Find EpollShim +# Once done, this will define +# +# EPOLLSHIM_FOUND - System has EpollShim +# EPOLLSHIM_INCLUDE_DIRS - The EpollShim include directories +# EPOLLSHIM_LIBRARIES - The libraries needed to use EpollShim + +find_path(EPOLLSHIM_INCLUDE_DIRS NAMES sys/epoll.h sys/timerfd.h HINTS /usr/local/include/libepoll-shim) +find_library(EPOLLSHIM_LIBRARIES NAMES epoll-shim libepoll-shim HINTS /usr/local/lib) + +if (EPOLLSHIM_INCLUDE_DIRS AND EPOLLSHIM_LIBRARIES) + set(EPOLLSHIM_FOUND TRUE) +endif (EPOLLSHIM_INCLUDE_DIRS AND EPOLLSHIM_LIBRARIES) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(EPOLLSHIM DEFAULT_MSG EPOLLSHIM_LIBRARIES EPOLLSHIM_INCLUDE_DIRS) +mark_as_advanced(EPOLLSHIM_INCLUDE_DIRS EPOLLSHIM_LIBRARIES) diff --git a/CMake/FindGdkPixbuf.cmake b/CMake/FindGdkPixbuf.cmake index 4ea1d5b9..9cad4f92 100644 --- a/CMake/FindGdkPixbuf.cmake +++ b/CMake/FindGdkPixbuf.cmake @@ -8,43 +8,36 @@ # Define GDK_PIXBUF_MIN_VERSION for which version desired. # -INCLUDE(FindPkgConfig) +find_package(PkgConfig) -IF(GdkPixbuf_FIND_REQUIRED) - SET(_pkgconfig_REQUIRED "REQUIRED") -ELSE(GdkPixbuf_FIND_REQUIRED) - SET(_pkgconfig_REQUIRED "") -ENDIF(GdkPixbuf_FIND_REQUIRED) +if(GdkPixbuf_FIND_REQUIRED) + set(_pkgconfig_REQUIRED "REQUIRED") +else(GdkPixbuf_FIND_REQUIRED) + set(_pkgconfig_REQUIRED "") +endif(GdkPixbuf_FIND_REQUIRED) -IF(GDK_PIXBUF_MIN_VERSION) - PKG_SEARCH_MODULE(GDK_PIXBUF ${_pkgconfig_REQUIRED} "gdk-pixbuf-2.0>=${GDK_PIXBUF_MIN_VERSION}") -ELSE(GDK_PIXBUF_MIN_VERSION) - PKG_SEARCH_MODULE(GDK_PIXBUF ${_pkgconfig_REQUIRED} "gdk-pixbuf-2.0") -ENDIF(GDK_PIXBUF_MIN_VERSION) +if(GDK_PIXBUF_MIN_VERSION) + pkg_check_modules(GDK_PIXBUF ${_pkgconfig_REQUIRED} "gdk-pixbuf-2.0>=${GDK_PIXBUF_MIN_VERSION}") +else(GDK_PIXBUF_MIN_VERSION) + pkg_check_modules(GDK_PIXBUF ${_pkgconfig_REQUIRED} "gdk-pixbuf-2.0") +endif(GDK_PIXBUF_MIN_VERSION) -IF(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND) - FIND_PATH(GDK_PIXBUF_INCLUDE_DIRS gdk-pixbuf/gdk-pixbuf.h) - FIND_LIBRARY(GDK_PIXBUF_LIBRARIES gdk_pixbuf-2.0) +if(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND) + find_path(GDK_PIXBUF_INCLUDE_DIRS gdk-pixbuf/gdk-pixbuf.h) + find_library(GDK_PIXBUF_LIBRARIES gdk_pixbuf-2.0) +else(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND) + SET(GdkPixbuf_FOUND 1) + # Make paths absolute https://stackoverflow.com/a/35476270 + # Important on FreeBSD because /usr/local/lib is not on /usr/bin/ld's default path + set(GDK_PIXBUF_LIBS_ABSOLUTE) + foreach(lib ${GDK_PIXBUF_LIBRARIES}) + set(var_name GDK_PIXBUF_${lib}_ABS) + find_library(${var_name} ${lib} ${GDK_PIXBUF_LIBRARY_DIRS}) + list(APPEND GDK_PIXBUF_LIBS_ABSOLUTE ${${var_name}}) + endforeach() + set(GDK_PIXBUF_LIBRARIES ${GDK_PIXBUF_LIBS_ABSOLUTE}) +endif(NOT GDK_PIXBUF_FOUND AND NOT PKG_CONFIG_FOUND) - # Report results - IF(GDK_PIXBUF_LIBRARIES AND GDK_PIXBUF_INCLUDE_DIRS) - SET(GDK_PIXBUF_FOUND 1) - SET(GdkPixbuf_FOUND 1) - IF(NOT GdkPixbuf_FIND_QUIETLY) - MESSAGE(STATUS "Found GdkPixbuf: ${GDK_PIXBUF_LIBRARIES}") - ENDIF(NOT GdkPixbuf_FIND_QUIETLY) - ELSE(GDK_PIXBUF_LIBRARIES AND GDK_PIXBUF_INCLUDE_DIRS) - IF(GdkPixbuf_FIND_REQUIRED) - MESSAGE(SEND_ERROR "Could not find GdkPixbuf") - ELSE(GdkPixbuf_FIND_REQUIRED) - IF(NOT GdkPixbuf_FIND_QUIETLY) - MESSAGE(STATUS "Could not find GdkPixbuf") - ENDIF(NOT GdkPixbuf_FIND_QUIETLY) - ENDIF(GdkPixbuf_FIND_REQUIRED) - 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) - -# Hide advanced variables from CMake GUIs -MARK_AS_ADVANCED(GDK_PIXBUF_LIBRARIES GDK_PIXBUF_INCLUDE_DIRS) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GDK_PIXBUF DEFAULT_MSG GDK_PIXBUF_LIBRARIES GDK_PIXBUF_INCLUDE_DIRS) +mark_as_advanced(GDK_PIXBUF_LIBRARIES GDK_PIXBUF_INCLUDE_DIRS) diff --git a/CMake/FindPango.cmake b/CMake/FindPango.cmake index 64bf9ac4..eb296d75 100644 --- a/CMake/FindPango.cmake +++ b/CMake/FindPango.cmake @@ -8,40 +8,35 @@ # Define PANGO_MIN_VERSION for which version desired. # -INCLUDE(FindPkgConfig) +find_package(PkgConfig) -IF(Pango_FIND_REQUIRED) - SET(_pkgconfig_REQUIRED "REQUIRED") -ELSE(Pango_FIND_REQUIRED) - SET(_pkgconfig_REQUIRED "") -ENDIF(Pango_FIND_REQUIRED) +if(Pango_FIND_REQUIRED) + set(_pkgconfig_REQUIRED "REQUIRED") +else(Pango_FIND_REQUIRED) + set(_pkgconfig_REQUIRED "") +endif(Pango_FIND_REQUIRED) -IF(PANGO_MIN_VERSION) - PKG_SEARCH_MODULE(PANGO ${_pkgconfig_REQUIRED} "pango>=${PANGO_MIN_VERSION} pangocairo>=${PANGO_MIN_VERSION}") -ELSE(PANGO_MIN_VERSION) - PKG_SEARCH_MODULE(PANGO ${_pkgconfig_REQUIRED} "pango pangocairo") -ENDIF(PANGO_MIN_VERSION) +if(PANGO_MIN_VERSION) + pkg_check_modules(PANGO ${_pkgconfig_REQUIRED} "pango>=${PANGO_MIN_VERSION}" "pangocairo>=${PANGO_MIN_VERSION}") +else(PANGO_MIN_VERSION) + pkg_check_modules(PANGO ${_pkgconfig_REQUIRED} pango pangocairo) +endif(PANGO_MIN_VERSION) -IF(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND) - FIND_PATH(PANGO_INCLUDE_DIRS pango.h) - FIND_LIBRARY(PANGO_LIBRARIES pango pangocairo) +if(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND) + find_path(PANGO_INCLUDE_DIRS pango.h) + find_library(PANGO_LIBRARIES pango pangocairo) +else(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND) + # Make paths absolute https://stackoverflow.com/a/35476270 + # Important on FreeBSD because /usr/local/lib is not on /usr/bin/ld's default path + set(PANGO_LIBS_ABSOLUTE) + foreach(lib ${PANGO_LIBRARIES}) + set(var_name PANGO_${lib}_ABS) + find_library(${var_name} ${lib} ${PANGO_LIBRARY_DIRS}) + list(APPEND PANGO_LIBS_ABSOLUTE ${${var_name}}) + endforeach() + set(PANGO_LIBRARIES ${PANGO_LIBS_ABSOLUTE}) +endif(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND) - # Report results - IF(PANGO_LIBRARIES AND PANGO_INCLUDE_DIRS) - SET(PANGO_FOUND 1) - IF(NOT Pango_FIND_QUIETLY) - MESSAGE(STATUS "Found Pango: ${PANGO_LIBRARIES}") - ENDIF(NOT Pango_FIND_QUIETLY) - ELSE(PANGO_LIBRARIES AND PANGO_INCLUDE_DIRS) - IF(Pango_FIND_REQUIRED) - MESSAGE(SEND_ERROR "Could not find Pango") - ELSE(Pango_FIND_REQUIRED) - IF(NOT Pango_FIND_QUIETLY) - MESSAGE(STATUS "Could not find Pango") - ENDIF(NOT Pango_FIND_QUIETLY) - ENDIF(Pango_FIND_REQUIRED) - ENDIF(PANGO_LIBRARIES AND PANGO_INCLUDE_DIRS) -ENDIF(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND) - -# Hide advanced variables from CMake GUIs -MARK_AS_ADVANCED(PANGO_LIBRARIES PANGO_INCLUDE_DIRS) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PANGO DEFAULT_MSG PANGO_LIBRARIES PANGO_INCLUDE_DIRS) +mark_as_advanced(PANGO_LIBRARIES PANGO_INCLUDE_DIRS) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5796168..f55fadae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,10 @@ if(Backtrace_FOUND) set(SWAY_Backtrace_HEADER "${Backtrace_HEADER}") endif() +if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + find_package(EpollShim REQUIRED) +endif (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + include(FeatureSummary) include(Manpage) include(GNUInstallDirs) diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt index d1afadb6..4532a6c3 100644 --- a/sway/CMakeLists.txt +++ b/sway/CMakeLists.txt @@ -55,9 +55,12 @@ target_link_libraries(sway ${PANGO_LIBRARIES} ${JSONC_LIBRARIES} m - cap ) +if (CMAKE_SYSTEM_NAME STREQUAL Linux) + target_link_libraries(sway cap) +endif (CMAKE_SYSTEM_NAME STREQUAL Linux) + install( TARGETS sway RUNTIME diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 815b232b..de72beca 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -126,6 +126,8 @@ struct sockaddr_un *ipc_user_sockaddr(void) { } static pid_t get_client_pid(int client_fd) { +// FreeBSD supports getting uid/gid, but not pid +#ifdef __linux__ struct ucred ucred; socklen_t len = sizeof(struct ucred); @@ -134,6 +136,9 @@ static pid_t get_client_pid(int client_fd) { } return ucred.pid; +#else + return -1; +#endif } int ipc_handle_connection(int fd, uint32_t mask, void *data) { diff --git a/sway/main.c b/sway/main.c index eb103a1e..157c61b3 100644 --- a/sway/main.c +++ b/sway/main.c @@ -152,6 +152,7 @@ static void security_sanity_check() { sway_log(L_ERROR, "!! DANGER !! /proc is not available - sway CANNOT enforce security rules!"); } +#ifdef __linux__ cap_flag_value_t v; cap_t cap = cap_get_proc(); if (!cap || cap_get_flag(cap, CAP_SYS_PTRACE, CAP_PERMITTED, &v) != 0 || v != CAP_SET) { @@ -161,6 +162,7 @@ static void security_sanity_check() { if (cap) { cap_free(cap); } +#endif if (!stat(SYSCONFDIR "/sway", &s)) { if (s.st_uid != 0 || s.st_gid != 0 || (s.st_mode & S_IWGRP) || (s.st_mode & S_IWOTH)) { diff --git a/sway/security.c b/sway/security.c index f16fdd1f..9cccd62e 100644 --- a/sway/security.c +++ b/sway/security.c @@ -28,7 +28,11 @@ struct command_policy *alloc_command_policy(const char *command) { } enum secure_feature get_feature_policy(pid_t pid) { +#ifdef __FreeBSD__ + const char *fmt = "/proc/%d/file"; +#else const char *fmt = "/proc/%d/exe"; +#endif int pathlen = snprintf(NULL, 0, fmt, pid); char *path = malloc(pathlen + 1); snprintf(path, pathlen + 1, fmt, pid); diff --git a/swaymsg/CMakeLists.txt b/swaymsg/CMakeLists.txt index a4989b9c..f23919b8 100644 --- a/swaymsg/CMakeLists.txt +++ b/swaymsg/CMakeLists.txt @@ -2,6 +2,10 @@ add_executable(swaymsg main.c ) +include_directories( + ${JSONC_INCLUDE_DIRS} +) + target_link_libraries(swaymsg sway-common ${JSONC_LIBRARIES} diff --git a/wayland/CMakeLists.txt b/wayland/CMakeLists.txt index 54fe3e23..91fd7fff 100644 --- a/wayland/CMakeLists.txt +++ b/wayland/CMakeLists.txt @@ -3,6 +3,7 @@ include_directories( ${PANGO_INCLUDE_DIRS} ${XKBCOMMON_INCLUDE_DIRS} ${WAYLAND_INCLUDE_DIR} + ${EPOLLSHIM_INCLUDE_DIRS} ) add_library(sway-wayland STATIC @@ -18,6 +19,7 @@ target_link_libraries(sway-wayland sway-protocols ${PANGO_LIBRARIES} ${XKBCOMMON_LIBRARIES} + ${EPOLLSHIM_LIBRARIES} ) if (WITH_GDK_PIXBUF)