diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,22 +21,36 @@ include(FindPkgConfig) -pkg_check_modules(PIPEWIRE libpipewire-0.1) -pkg_check_modules(SPA libspa-0.1) -pkg_check_modules(GLIB glib-2.0) +find_package(glib) +set_package_properties(glib PROPERTIES + TYPE OPTIONAL + PURPOSE "Required for screencast portal" +) + +find_package(spa) +set_package_properties(spa PROPERTIES + TYPE OPTIONAL + PURPOSE "Required for screencast portal" +) + +find_package(pipewire) +set_package_properties(pipewire PROPERTIES + TYPE OPTIONAL + PURPOSE "Required for screencast portal" +) find_package(gbm) -set_package_properties(gbm PROPERTIES DESCRIPTION "GBM - Generic Buffer Management" +set_package_properties(gbm PROPERTIES TYPE OPTIONAL - PURPOSE "Required for egl ouput of drm backend." + PURPOSE "Required for screencast portal" ) find_package(epoxy) include_directories(${epoxy_INCLUDE_DIRS}) set_package_properties(epoxy PROPERTIES DESCRIPTION "libepoxy" URL "http://github.com/anholt/libepoxy" TYPE OPTIONAL - PURPOSE "OpenGL dispatch library for GBM backend" + PURPOSE "Required for screencast portal" ) if (${PIPEWIRE_FOUND} AND ${SPA_FOUND} AND ${GLIB_FOUND} AND ${GBM_FOUND} AND ${EPOXY_FOUND}) diff --git a/cmake/modules/Findglib.cmake b/cmake/modules/Findglib.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/Findglib.cmake @@ -0,0 +1,122 @@ +# - Try to find Glib and its components (gio, gobject etc) +# Once done, this will define +# +# GLIB_FOUND - system has Glib +# GLIB_INCLUDE_DIRS - the Glib include directories +# GLIB_LIBRARIES - link these to use Glib +# +# Optionally, the COMPONENTS keyword can be passed to find_package() +# and Glib components can be looked for. Currently, the following +# components can be used, and they define the following variables if +# found: +# +# gio: GLIB_GIO_LIBRARIES +# gobject: GLIB_GOBJECT_LIBRARIES +# gmodule: GLIB_GMODULE_LIBRARIES +# gthread: GLIB_GTHREAD_LIBRARIES +# +# Note that the respective _INCLUDE_DIR variables are not set, since +# all headers are in the same directory as GLIB_INCLUDE_DIRS. +# +# Copyright (C) 2012 Raphael Kubo da Costa +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS +# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +find_package(PkgConfig) +pkg_check_modules(PC_GLIB QUIET glib-2.0) + +find_library(GLIB_LIBRARIES + NAMES glib-2.0 + HINTS ${PC_GLIB_LIBDIR} + ${PC_GLIB_LIBRARY_DIRS} +) + +# Files in glib's main include path may include glibconfig.h, which, +# for some odd reason, is normally in $LIBDIR/glib-2.0/include. +get_filename_component(_GLIB_LIBRARY_DIR ${GLIB_LIBRARIES} PATH) +find_path(GLIBCONFIG_INCLUDE_DIR + NAMES glibconfig.h + HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${_GLIB_LIBRARY_DIR} + ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0/include +) + +find_path(GLIB_INCLUDE_DIR + NAMES glib.h + HINTS ${PC_GLIB_INCLUDEDIR} + ${PC_GLIB_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0 +) + +set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIBCONFIG_INCLUDE_DIR}) + +# Version detection +if (EXISTS "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h") + file(READ "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" GLIBCONFIG_H_CONTENTS) + string(REGEX MATCH "#define GLIB_MAJOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") + set(GLIB_VERSION_MAJOR "${CMAKE_MATCH_1}") + string(REGEX MATCH "#define GLIB_MINOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") + set(GLIB_VERSION_MINOR "${CMAKE_MATCH_1}") + string(REGEX MATCH "#define GLIB_MICRO_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") + set(GLIB_VERSION_MICRO "${CMAKE_MATCH_1}") + set(GLIB_VERSION "${GLIB_VERSION_MAJOR}.${GLIB_VERSION_MINOR}.${GLIB_VERSION_MICRO}") +endif () + +# Additional Glib components. We only look for libraries, as not all of them +# have corresponding headers and all headers are installed alongside the main +# glib ones. +foreach (_component ${GLIB_FIND_COMPONENTS}) + if (${_component} STREQUAL "gio") + find_library(GLIB_GIO_LIBRARIES NAMES gio-2.0 HINTS ${_GLIB_LIBRARY_DIR}) + set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GIO_LIBRARIES) + elseif (${_component} STREQUAL "gobject") + find_library(GLIB_GOBJECT_LIBRARIES NAMES gobject-2.0 HINTS ${_GLIB_LIBRARY_DIR}) + set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GOBJECT_LIBRARIES) + elseif (${_component} STREQUAL "gmodule") + find_library(GLIB_GMODULE_LIBRARIES NAMES gmodule-2.0 HINTS ${_GLIB_LIBRARY_DIR}) + set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GMODULE_LIBRARIES) + elseif (${_component} STREQUAL "gthread") + find_library(GLIB_GTHREAD_LIBRARIES NAMES gthread-2.0 HINTS ${_GLIB_LIBRARY_DIR}) + set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GTHREAD_LIBRARIES) + elseif (${_component} STREQUAL "gio-unix") + # gio-unix is compiled as part of the gio library, but the include paths + # are separate from the shared glib ones. Since this is currently only used + # by WebKitGTK+ we don't go to extraordinary measures beyond pkg-config. + pkg_check_modules(GIO_UNIX QUIET gio-unix-2.0) + endif () +endforeach () + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LIBRARIES ${ADDITIONAL_REQUIRED_VARS} + VERSION_VAR GLIB_VERSION) + +mark_as_advanced( + GLIBCONFIG_INCLUDE_DIR + GLIB_GIO_LIBRARIES + GLIB_GIO_UNIX_LIBRARIES + GLIB_GMODULE_LIBRARIES + GLIB_GOBJECT_LIBRARIES + GLIB_GTHREAD_LIBRARIES + GLIB_INCLUDE_DIR + GLIB_INCLUDE_DIRS + GLIB_LIBRARIES +) diff --git a/cmake/modules/Findpipewire.cmake b/cmake/modules/Findpipewire.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/Findpipewire.cmake @@ -0,0 +1,124 @@ +#.rst: +# Findpipewire +# ------- +# +# Try to find pipewire on a Unix system. +# +# This will define the following variables: +# +# ``pipewire_FOUND`` +# True if (the requested version of) pipewire is available +# ``pipewire_VERSION`` +# The version of pipewire +# ``pipewire_LIBRARIES`` +# This can be passed to target_link_libraries() instead of the ``pipewire::pipewire`` +# target +# ``pipewire_INCLUDE_DIRS`` +# This should be passed to target_include_directories() if the target is not +# used for linking +# ``pipewire_DEFINITIONS`` +# This should be passed to target_compile_options() if the target is not +# used for linking +# +# If ``pipewire_FOUND`` is TRUE, it will also define the following imported target: +# +# ``pipewire::pipewire`` +# The pipewire library +# +# In general we recommend using the imported target, as it is easier to use. +# Bear in mind, however, that if the target is in the link interface of an +# exported library, it must be made available by the package config file. + +#============================================================================= +# Copyright 2014 Alex Merry +# Copyright 2014 Martin Gräßlin +# Copyright 2018 Jan Grulich +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + + +if(CMAKE_VERSION VERSION_LESS 2.8.12) + message(FATAL_ERROR "CMake 2.8.12 is required by Findpipewire.cmake") +endif() +if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.12) + message(AUTHOR_WARNING "Your project should require at least CMake 2.8.12 to use Findpipewire.cmake") +endif() + +if(NOT WIN32) + # Use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + find_package(PkgConfig) + pkg_check_modules(PKG_pipewire QUIET libpipewire-0.1) + + set(pipewire_DEFINITIONS ${PKG_pipewire_CFLAGS_OTHER}) + set(pipewire_VERSION ${PKG_pipewire_VERSION}) + + find_path(pipewire_INCLUDE_DIR + NAMES + pipewire/pipewire.h + HINTS + ${PKG_pipewire_INCLUDE_DIRS} + ) + + find_library(pipewire_LIBRARY + NAMES + pipewire-0.1 + HINTS + ${PKG_pipewire_LIBRARY_DIRS} + ) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(pipewire + FOUND_VAR + pipewire_FOUND + REQUIRED_VARS + pipewire_LIBRARY + pipewire_INCLUDE_DIR + VERSION_VAR + pipewire_VERSION + ) + + if(pipewire_FOUND AND NOT TARGET pipewire::pipewire) + add_library(pipewire::pipewire UNKNOWN IMPORTED) + set_target_properties(pipewire::pipewire PROPERTIES + IMPORTED_LOCATION "${pipewire_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${pipewire_DEFINITIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${pipewire_INCLUDE_DIR}" + ) + endif() + + mark_as_advanced(pipewire_LIBRARY pipewire_INCLUDE_DIR) + + # compatibility variables + set(pipewire_LIBRARIES ${pipewire_LIBRARY}) + set(pipewire_INCLUDE_DIRS ${pipewire_INCLUDE_DIR}) + set(pipewire_VERSION_STRING ${pipewire_VERSION}) +endif() + +include(FeatureSummary) +set_package_properties(pipewire PROPERTIES + URL "http://www.pipewire.org" + DESCRIPTION "Pipewire - multimedia processing" +) diff --git a/cmake/modules/Findspa.cmake b/cmake/modules/Findspa.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/Findspa.cmake @@ -0,0 +1,123 @@ +#.rst: +# Findspa +# ------- +# +# Try to find spa on a Unix system. +# +# This will define the following variables: +# +# ``spa_FOUND`` +# True if (the requested version of) spa is available +# ``spa_VERSION`` +# The version of spa +# ``spa_LIBRARIES`` +# This can be passed to target_link_libraries() instead of the ``spa::spa`` +# target +# ``spa_INCLUDE_DIRS`` +# This should be passed to target_include_directories() if the target is not +# used for linking +# ``spa_DEFINITIONS`` +# This should be passed to target_compile_options() if the target is not +# used for linking +# +# If ``spa_FOUND`` is TRUE, it will also define the following imported target: +# +# ``spa::spa`` +# The spa library +# +# In general we recommend using the imported target, as it is easier to use. +# Bear in mind, however, that if the target is in the link interface of an +# exported library, it must be made available by the package config file. + +#============================================================================= +# Copyright 2014 Alex Merry +# Copyright 2014 Martin Gräßlin +# Copyright 2018 Jan Grulich + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + + +if(CMAKE_VERSION VERSION_LESS 2.8.12) + message(FATAL_ERROR "CMake 2.8.12 is required by Findspa.cmake") +endif() +if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.12) + message(AUTHOR_WARNING "Your project should require at least CMake 2.8.12 to use Findspa.cmake") +endif() + +if(NOT WIN32) + # Use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + find_package(PkgConfig) + pkg_check_modules(PKG_spa QUIET libspa-0.1) + + set(spa_DEFINITIONS ${PKG_spa_CFLAGS_OTHER}) + set(spa_VERSION ${PKG_spa_VERSION}) + + find_path(spa_INCLUDE_DIR + NAMES + spa/pod/pod.h + HINTS + ${PKG_spa_INCLUDE_DIRS} + ) + + find_library(spa_LIBRARY + NAMES + spa-lib + HINTS + ${PKG_spa_LIBRARY_DIRS} + ) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(spa + FOUND_VAR + spa_FOUND + REQUIRED_VARS + spa_LIBRARY + spa_INCLUDE_DIR + VERSION_VAR + spa_VERSION + ) + + if(spa_FOUND AND NOT TARGET spa::spa) + add_library(spa::spa UNKNOWN IMPORTED) + set_target_properties(spa::spa PROPERTIES + IMPORTED_LOCATION "${spa_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${spa_DEFINITIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${spa_INCLUDE_DIR}" + ) + endif() + + mark_as_advanced(spa_LIBRARY spa_INCLUDE_DIR) + + # compatibility variables + set(spa_LIBRARIES ${spa_LIBRARY}) + set(spa_INCLUDE_DIRS ${spa_INCLUDE_DIR}) + set(spa_VERSION_STRING ${spa_VERSION}) +endif() + +include(FeatureSummary) +set_package_properties(spa PROPERTIES + DESCRIPTION "Simple Plugin API" +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,10 @@ add_definitions(-DTRANSLATION_DOMAIN="xdg-desktop-portal-kde") -include_directories( - ${Qt5PrintSupport_PRIVATE_INCLUDE_DIRS} - ${PIPEWIRE_INCLUDE_DIRS} ${SPA_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS} - ${gbm_INCLUDE_DIRS} -) +include_directories(${Qt5PrintSupport_PRIVATE_INCLUDE_DIRS}) + +if (SCREENCAST_ENABLED) + include_directories(${PIPEWIRE_INCLUDE_DIRS} ${SPA_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS} ${gbm_INCLUDE_DIRS}) +endif() set(xdg_desktop_portal_kde_SRCS xdg-desktop-portal-kde.cpp @@ -53,11 +53,11 @@ if (SCREENCAST_ENABLED) target_link_libraries(xdg-desktop-portal-kde - ${PIPEWIRE_LIBRARIES} - ${SPA_LIBRARIES} - ${GLIB_LIBRARIES} + ${pipewire_LIBRARY} + ${spa_LIBRARY} + ${glib_LIBRARY} ${epoxy_LIBRARY} - gbm::gbm) + ${gbm_LIBRARY}) endif() install(TARGETS xdg-desktop-portal-kde DESTINATION ${KDE_INSTALL_LIBEXECDIR})