Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build-aux/com.obsproject.Studio.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"modules/40-usrsctp.json",
"modules/50-jansson.json",
"modules/50-libdatachannel.json",
"modules/50-libsecret.json",
"modules/50-ntv2.json",
"modules/50-pipewire.json",
"modules/50-swig.json",
Expand Down
23 changes: 23 additions & 0 deletions build-aux/modules/50-libsecret.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "libsecret",
"buildsystem": "meson",
"config-opts": [
"-Dmanpage=false",
"-Dvapi=false",
"-Dgtk_doc=false",
"-Dintrospection=false"
],
"cleanup": [
"/bin",
"/include",
"/lib/pkgconfig",
"/share/man"
],
"sources": [
{
"type": "archive",
"url": "https://download.gnome.org/sources/libsecret/0.20/libsecret-0.20.5.tar.xz",
"sha256": "3fb3ce340fcd7db54d87c893e69bfc2b1f6e4d4b279065ffe66dac9f0fd12b4d"
}
]
}
111 changes: 111 additions & 0 deletions cmake/Modules/FindLibsecret.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#[=======================================================================[.rst
FindLibsecret
-------------

FindModule for libsecret and the associated library

Imported Targets
^^^^^^^^^^^^^^^^

.. versionadded:: 2.0

This module defines the :prop_tgt:`IMPORTED` target ``Libsecret::Libsecret``.

Result Variables
^^^^^^^^^^^^^^^^

This module sets the following variables:

``Libsecret_FOUND``
True, if the library was found.
``Libsecret_VERSION``
Detected version of found Libsecret library.

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``Libsecret_INCLUDE_DIR``
Directory containing ``secret.h``.

#]=======================================================================]

include(FindPackageHandleStandardArgs)

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_search_module(PC_Libsecret QUIET libsecret-1)
endif()

# Libsecret_set_soname: Set SONAME on imported library target
macro(Libsecret_set_soname)
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
execute_process(
COMMAND sh -c "${CMAKE_OBJDUMP} -p '${Libsecret_LIBRARY}' | grep SONAME"
OUTPUT_VARIABLE _output
RESULT_VARIABLE _result)

if(_result EQUAL 0)
string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}")
set_property(TARGET Libsecret::Libsecret PROPERTY IMPORTED_SONAME "${_soname}")
unset(_soname)
endif()
endif()
unset(_output)
unset(_result)
endmacro()

find_path(
Libsecret_INCLUDE_DIR
NAMES libsecret/secret.h
HINTS ${PC_Libsecret_INCLUDE_DIRS}
PATHS /usr/include /usr/local/include
PATH_SUFFIXES libsecret-1
DOC "Libsecret include directory")

find_library(
Libsecret_LIBRARY
NAMES secret secret-1 libsecret libsecret-1
HINTS ${PC_Libsecret_LIBRARY_DIRS}
PATHS /usr/lib /usr/local/lib
DOC "Libsecret location")

if(PC_Libsecret_VERSION VERSION_GREATER 0)
set(Libsecret_VERSION ${PC_Libsecret_VERSION})
elseif(EXISTS "${Libsecret_INCLUDE_DIR}/secret-version.h")
file(STRINGS "${Libsecret_INCLUDE_DIR}/secret-version.h" _version_string)
string(REGEX REPLACE "SECRET_[A-Z]+_VERSION \\(([0-9]+)\\)" "\\1\\.\\2\\.\\3" Libsecret_VERSION "${_version_string}")
else()
if(NOT Libsecret_FIND_QUIETLY)
message(AUTHOR_WARNING "Failed to find Libsecret version.")
endif()
set(Libsecret_VERSION 0.0.0)
endif()

find_package_handle_standard_args(
Libsecret
REQUIRED_VARS Libsecret_INCLUDE_DIR Libsecret_LIBRARY
VERSION_VAR Libsecret_VERSION REASON_FAILURE_MESSAGE "Ensure libsecret-1 is installed on the system.")
mark_as_advanced(Libsecret_INCLUDE_DIR Libsecret_LIBRARY)

if(Libsecret_FOUND)
if(NOT TARGET Libsecret::Libsecret)
if(IS_ABSOLUTE "${Libsecret_LIBRARY}")
add_library(Libsecret::Libsecret UNKNOWN IMPORTED)
set_property(TARGET Libsecret::Libsecret PROPERTY IMPORTED_LOCATION "${Libsecret_LIBRARY}")
else()
add_library(Libsecret::Libsecret INTERFACE IMPORTED)
set_property(TARGET Libsecret::Libsecret PROPERTY IMPORTED_LIBNAME "${Libsecret_LIBRARY}")
endif()

libsecret_set_soname()
set_target_properties(Libsecret::Libsecret PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Libsecret_INCLUDE_DIR}")
endif()
endif()

include(FeatureSummary)
set_package_properties(
Libsecret PROPERTIES
URL "https://gnome.pages.gitlab.gnome.org/libsecret/index.html"
DESCRIPTION "Secret Service D-Bus client library")
111 changes: 111 additions & 0 deletions cmake/finders/FindLibsecret.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#[=======================================================================[.rst
FindLibsecret
-------------

FindModule for libsecret and the associated library

Imported Targets
^^^^^^^^^^^^^^^^

.. versionadded:: 2.0

This module defines the :prop_tgt:`IMPORTED` target ``Libsecret::Libsecret``.

Result Variables
^^^^^^^^^^^^^^^^

This module sets the following variables:

``Libsecret_FOUND``
True, if the library was found.
``Libsecret_VERSION``
Detected version of found Libsecret library.

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``Libsecret_INCLUDE_DIR``
Directory containing ``secret.h``.

#]=======================================================================]

include(FindPackageHandleStandardArgs)

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_search_module(PC_Libsecret QUIET libsecret-1)
endif()

# Libsecret_set_soname: Set SONAME on imported library target
macro(Libsecret_set_soname)
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
execute_process(
COMMAND sh -c "${CMAKE_OBJDUMP} -p '${Libsecret_LIBRARY}' | grep SONAME"
OUTPUT_VARIABLE _output
RESULT_VARIABLE _result)

if(_result EQUAL 0)
string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}")
set_property(TARGET Libsecret::Libsecret PROPERTY IMPORTED_SONAME "${_soname}")
unset(_soname)
endif()
endif()
unset(_output)
unset(_result)
endmacro()

find_path(
Libsecret_INCLUDE_DIR
NAMES libsecret/secret.h
HINTS ${PC_Libsecret_INCLUDE_DIRS}
PATHS /usr/include /usr/local/include
PATH_SUFFIXES libsecret-1
DOC "Libsecret include directory")

find_library(
Libsecret_LIBRARY
NAMES secret secret-1 libsecret libsecret-1
HINTS ${PC_Libsecret_LIBRARY_DIRS}
PATHS /usr/lib /usr/local/lib
DOC "Libsecret location")

if(PC_Libsecret_VERSION VERSION_GREATER 0)
set(Libsecret_VERSION ${PC_Libsecret_VERSION})
elseif(EXISTS "${Libsecret_INCLUDE_DIR}/secret-version.h")
file(STRINGS "${Libsecret_INCLUDE_DIR}/secret-version.h" _version_string)
string(REGEX REPLACE "SECRET_[A-Z]+_VERSION \\(([0-9]+)\\)" "\\1\\.\\2\\.\\3" Libsecret_VERSION "${_version_string}")
else()
if(NOT Libsecret_FIND_QUIETLY)
message(AUTHOR_WARNING "Failed to find Libsecret version.")
endif()
set(Libsecret_VERSION 0.0.0)
endif()

find_package_handle_standard_args(
Libsecret
REQUIRED_VARS Libsecret_INCLUDE_DIR Libsecret_LIBRARY
VERSION_VAR Libsecret_VERSION REASON_FAILURE_MESSAGE "Ensure libsecret-1 is installed on the system.")
mark_as_advanced(Libsecret_INCLUDE_DIR Libsecret_LIBRARY)

if(Libsecret_FOUND)
if(NOT TARGET Libsecret::Libsecret)
if(IS_ABSOLUTE "${Libsecret_LIBRARY}")
add_library(Libsecret::Libsecret UNKNOWN IMPORTED)
set_property(TARGET Libsecret::Libsecret PROPERTY IMPORTED_LOCATION "${Libsecret_LIBRARY}")
else()
add_library(Libsecret::Libsecret INTERFACE IMPORTED)
set_property(TARGET Libsecret::Libsecret PROPERTY IMPORTED_LIBNAME "${Libsecret_LIBRARY}")
endif()

libsecret_set_soname()
set_target_properties(Libsecret::Libsecret PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Libsecret_INCLUDE_DIR}")
endif()
endif()

include(FeatureSummary)
set_package_properties(
Libsecret PROPERTIES
URL "https://gnome.pages.gitlab.gnome.org/libsecret/index.html"
DESCRIPTION "Secret Service D-Bus client library")
31 changes: 31 additions & 0 deletions docs/sphinx/reference-libobs-util-platform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,34 @@ Other Functions
Must be freed with :c:func:`bfree()`.

.. versionadded:: 29.1

---------------------

.. function:: bool *os_keychain_available(void)

Indicates whether or not the keychain APIs are implemented on this platform.

On Windows/macOS this will always return `true` and the keychain is guaranteed to be available.
On Linux it will return `true` if OBS is compiled with libsecret, but keychain operations may still fail if no Secret Service (e.g. kwaller or gnome-keyring) is available.

---------------------

.. function:: bool os_keychain_save(const char *label, const char *key, const char *data)

Saves the string `data` into the OS keychain as key `key` with user-visible name `label`.

`label` should be a short descriptor of the kind of data being saved (e.g. "OBS Studio OAuth Credentials"), must not be translated, and must be identical when attempting to save/load/delete the same `key`.

---------------------

.. function:: bool os_keychain_load(const char *label, const char *key, char **data)

Attempt to read the string saved with key `key` in and with label `label` from the keychain.

If successful, `data´ must be freed with :c:func:`bfree()`.

---------------------

.. function:: bool os_keychain_delete(const char *label, const char *key)

Deletes an item from the keychain.
10 changes: 9 additions & 1 deletion libobs/cmake/legacy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ if(OS_WINDOWS)
target_compile_definitions(libobs PRIVATE UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS)
set_source_files_properties(obs-win-crash-handler.c PROPERTIES COMPILE_DEFINITIONS
OBS_VERSION="${OBS_VERSION_CANONICAL}")
target_link_libraries(libobs PRIVATE dxgi Avrt Dwmapi winmm Rpcrt4)
target_link_libraries(libobs PRIVATE dxgi Advapi32 Avrt Dwmapi winmm Rpcrt4)

if(MSVC)
target_link_libraries(libobs PUBLIC OBS::w32-pthreads)
Expand Down Expand Up @@ -424,6 +424,14 @@ elseif(OS_POSIX)
target_link_libraries(libobs PRIVATE GIO::GIO)

target_sources(libobs PRIVATE util/platform-nix-dbus.c util/platform-nix-portal.c)

find_package(Libsecret)
if(TARGET Libsecret::Libsecret)
obs_status(STATUS "-> libsecret found, enabling keychain API")
target_link_libraries(libobs PRIVATE Libsecret::Libsecret)
target_compile_definitions(libobs PRIVATE USE_LIBSECRET)
target_sources(libobs PRIVATE util/platform-nix-libsecret.c)
endif()
endif()

if(TARGET XCB::XINPUT)
Expand Down
10 changes: 10 additions & 0 deletions libobs/cmake/os-linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ find_package(x11-xcb REQUIRED)
find_package(xcb COMPONENTS xcb OPTIONAL_COMPONENTS xcb-xinput QUIET)
# cmake-format: on
find_package(gio)
find_package(Libsecret)

target_sources(
libobs
Expand Down Expand Up @@ -43,6 +44,15 @@ endif()
if(TARGET gio::gio)
target_sources(libobs PRIVATE util/platform-nix-dbus.c util/platform-nix-portal.c)
target_link_libraries(libobs PRIVATE gio::gio)

if(TARGET Libsecret::Libsecret)
target_compile_definitions(libobs PRIVATE USE_LIBSECRET)
target_sources(libobs PRIVATE util/platform-nix-libsecret.c)
target_link_libraries(libobs PRIVATE Libsecret::Libsecret)
target_enable_feature(libobs "Libsecret Keychain API (Linux)")
else()
target_disable_feature(libobs "Libsecret Keychain API (Linux)")
endif()
endif()

if(ENABLE_WAYLAND)
Expand Down
3 changes: 2 additions & 1 deletion libobs/cmake/os-macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ target_link_libraries(
"$<LINK_LIBRARY:FRAMEWORK,AudioUnit.framework>"
"$<LINK_LIBRARY:FRAMEWORK,AppKit.framework>"
"$<LINK_LIBRARY:FRAMEWORK,IOKit.framework>"
"$<LINK_LIBRARY:FRAMEWORK,Carbon.framework>")
"$<LINK_LIBRARY:FRAMEWORK,Carbon.framework>"
"$<LINK_LIBRARY:FRAMEWORK,Security.framework>")

target_sources(
libobs
Expand Down
1 change: 1 addition & 0 deletions libobs/cmake/os-windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ set_source_files_properties(obs-win-crash-handler.c PROPERTIES COMPILE_DEFINITIO
target_link_libraries(
libobs
PRIVATE Avrt
Advapi32
Dwmapi
Dxgi
winmm
Expand Down
Loading