From 4252c8a069e1aceab3956996c72f66e7bed6c078 Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Sat, 16 Jul 2022 23:15:50 +0200 Subject: [PATCH] cmake: Fix pkgconfig generation Existing code didn't check for possible "empty" linked libraries (e.g. Threads::Threads when compiler has built-in pthreads support). Also adds support for compile options defined on linked dependencies. --- cmake/Modules/ObsHelpers_Linux.cmake | 16 ++++++++++++---- libobs/pkgconfig/libobs.pc.in | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmake/Modules/ObsHelpers_Linux.cmake b/cmake/Modules/ObsHelpers_Linux.cmake index 36f67196d..a4c663eb9 100644 --- a/cmake/Modules/ObsHelpers_Linux.cmake +++ b/cmake/Modules/ObsHelpers_Linux.cmake @@ -25,21 +25,30 @@ function(export_target_pkgconf target) get_target_property(_TARGET_DEPENDENCIES ${target} INTERFACE_LINK_LIBRARIES) get_target_property(_TARGET_DEFINITIONS ${target} INTERFACE_COMPILE_DEFINITIONS) - get_target_property(_TARGET_OPTIONS ${target} INTERFACE_LINK_OPTIONS) + get_target_property(_TARGET_OPTIONS ${target} INTERFACE_COMPILE_OPTIONS) foreach(_LIBRARY IN LISTS _TARGET_DEPENDENCIES) get_target_property(_LINK_LIBRARY ${_LIBRARY} INTERFACE_LINK_LIBRARIES) get_target_property(_LINK_DEFINITIONS ${_LIBRARY} INTERFACE_COMPILE_DEFINITIONS) - list(APPEND _LINKED_LIBRARIES "${_LINK_LIBRARY}") + get_target_property(_LINK_OPTIONS ${_LIBRARY} INTERFACE_COMPILE_OPTIONS) + + if(NOT "${_LINK_LIBRARY}" STREQUAL "_LINK_LIBRARY-NOTFOUND") + list(APPEND _LINKED_LIBRARIES "${_LINK_LIBRARY}") + endif() if(NOT "${_LINK_DEFINITIONS}" STREQUAL "_LINK_DEFINITIONS-NOTFOUND") list(APPEND _LINKED_DEFINITIONS "${_LINK_DEFINITIONS}") endif() + + if(NOT "${_LINK_OPTIONS}" STREQUAL "_LINK_OPTIONS-NOTFOUND") + list(APPEND _LINKED_OPTIONS "${_LINK_OPTIONS}") + endif() endforeach() string(REPLACE ";" " " _LINKED_LIBRARIES "${_LINKED_LIBRARIES}") string(REPLACE ";" " " _LINKED_DEFINITIONS "${_LINKED_DEFINITIONS}") + string(REPLACE ";" " " _LINKED_OPTIONS "${_LINKED_OPTIONS}") if(NOT "${_TARGET_DEFINITIONS}" STREQUAL "_TARGET_DEFINITIONS-NOTFOUND") list(JOIN _TARGET_DEFINITIONS "-D" _TARGET_DEFINITIONS) @@ -49,8 +58,7 @@ function(export_target_pkgconf target) endif() if(NOT "${_TARGET_OPTIONS}" STREQUAL "_TARGET_OPTIONS-NOTFOUND") - list(JOIN _TARGET_OPTIONS "-" _TARGET_OPTIONS) - set(_TARGET_OPTIONS "-${_TARGET_OPTIONS}") + list(JOIN _TARGET_OPTIONS " " _TARGET_OPTIONS) else() set(_TARGET_OPTIONS "") endif() diff --git a/libobs/pkgconfig/libobs.pc.in b/libobs/pkgconfig/libobs.pc.in index c32e0cb70..af1458e5d 100644 --- a/libobs/pkgconfig/libobs.pc.in +++ b/libobs/pkgconfig/libobs.pc.in @@ -6,5 +6,5 @@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@/obs Name: libobs Description: OBS Studio Library Version: @OBS_VERSION_CANONICAL@ -Cflags: -I${includedir} @_TARGET_DEFINITIONS@ @_TARGET_OPTIONS@ @_LINKED_DEFINITIONS@ -Libs: -L${libdir} @_LINKED_LIBRARIES@ +Cflags: -I${includedir} @_TARGET_DEFINITIONS@ @_TARGET_OPTIONS@ @_LINKED_DEFINITIONS@ @_LINKED_OPTIONS@ +Libs: -L${libdir} -lobs @_LINKED_LIBRARIES@