cmake,lib,base: Export obs-websocket-api as a target

This enables the installation of the header in the include directory
This commit is contained in:
tytan652 2024-01-13 15:48:16 +01:00 committed by tt2468
parent d2d4bfb3e7
commit c8cf2d94ac
5 changed files with 42 additions and 4 deletions

View File

@ -5,6 +5,8 @@ legacy_check()
set(obs-websocket_VERSION 5.4.2)
set(OBS_WEBSOCKET_RPC_VERSION 1)
include(cmake/obs-websocket-api.cmake)
option(ENABLE_WEBSOCKET "Enable building OBS with websocket plugin" ON)
if(NOT ENABLE_WEBSOCKET)
target_disable(obs-websocket)
@ -34,7 +36,6 @@ add_library(OBS::websocket ALIAS obs-websocket)
target_sources(
obs-websocket
PRIVATE # cmake-format: sortable
lib/obs-websocket-api.h
src/Config.cpp
src/Config.h
src/forms/ConnectInfo.cpp
@ -154,6 +155,7 @@ target_link_libraries(
obs-websocket
PRIVATE OBS::libobs
OBS::frontend-api
OBS::websocket-api
Qt::Core
Qt::Widgets
Qt::Svg

View File

@ -3,6 +3,21 @@ set(OBS_WEBSOCKET_RPC_VERSION 1)
option(ENABLE_WEBSOCKET "Enable building OBS with websocket plugin" ON)
add_library(obs-websocket-api INTERFACE)
add_library(OBS::websocket-api ALIAS obs-websocket-api)
target_sources(obs-websocket-api INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/obs-websocket-api.h>
$<INSTALL_INTERFACE:${OBS_INCLUDE_DESTINATION}/obs-websocket-api.h>)
target_link_libraries(obs-websocket-api INTERFACE OBS::libobs)
target_include_directories(obs-websocket-api INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib>
$<INSTALL_INTERFACE:${OBS_INCLUDE_DESTINATION}>)
set_target_properties(obs-websocket-api PROPERTIES PUBLIC_HEADER lib/obs-websocket-api.h)
export_target(obs-websocket-api)
if(NOT ENABLE_WEBSOCKET OR NOT ENABLE_UI)
message(STATUS "OBS: DISABLED obs-websocket")
return()
@ -56,7 +71,6 @@ target_sources(
src/obs-websocket.h
src/Config.cpp
src/Config.h
lib/obs-websocket-api.h
src/forms/SettingsDialog.cpp
src/forms/SettingsDialog.h
src/forms/ConnectInfo.cpp
@ -133,6 +147,7 @@ target_link_libraries(
obs-websocket
PRIVATE OBS::libobs
OBS::frontend-api
OBS::websocket-api
Qt::Core
Qt::Widgets
Qt::Svg

View File

@ -0,0 +1,14 @@
add_library(obs-websocket-api INTERFACE)
add_library(OBS::websocket-api ALIAS obs-websocket-api)
target_sources(obs-websocket-api INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/obs-websocket-api.h>
$<INSTALL_INTERFACE:${OBS_INCLUDE_DESTINATION}/obs-websocket-api.h>)
target_link_libraries(obs-websocket-api INTERFACE OBS::libobs)
target_include_directories(obs-websocket-api INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib>"
"$<INSTALL_INTERFACE:${OBS_INCLUDE_DESTINATION}>")
set_target_properties(obs-websocket-api PROPERTIES PREFIX "" PUBLIC_HEADER lib/obs-websocket-api.h)
target_export(obs-websocket-api)

View File

@ -0,0 +1,8 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(libobs REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")

View File

@ -24,8 +24,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <mutex>
#include <shared_mutex>
#include <obs.h>
#include "../lib/obs-websocket-api.h"
#include <obs-websocket-api.h>
class WebSocketApi {
public: