Skip to content

Commit

Permalink
cmake,lib,base: Export obs-websocket-api as a target
Browse files Browse the repository at this point in the history
This enables the installation of the header in the include directory
  • Loading branch information
tytan652 committed Jan 16, 2024
1 parent 6c67b27 commit 726dc92
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ legacy_check()
set(obs-websocket_VERSION 5.3.5)
set(OBS_WEBSOCKET_RPC_VERSION 1)

add_subdirectory(lib)

option(ENABLE_WEBSOCKET "Enable building OBS with websocket plugin" ON)
if(NOT ENABLE_WEBSOCKET)
target_disable(obs-websocket)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -154,6 +155,7 @@ target_link_libraries(
obs-websocket
PRIVATE OBS::libobs
OBS::frontend-api
OBS::websocket-api
Qt::Core
Qt::Widgets
Qt::Svg
Expand Down
4 changes: 3 additions & 1 deletion cmake/legacy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set(OBS_WEBSOCKET_RPC_VERSION 1)

option(ENABLE_WEBSOCKET "Enable building OBS with websocket plugin" ON)

add_subdirectory(lib)

if(NOT ENABLE_WEBSOCKET OR NOT ENABLE_UI)
message(STATUS "OBS: DISABLED obs-websocket")
return()
Expand Down Expand Up @@ -56,7 +58,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
Expand Down Expand Up @@ -133,6 +134,7 @@ target_link_libraries(
obs-websocket
PRIVATE OBS::libobs
OBS::frontend-api
OBS::websocket-api
Qt::Core
Qt::Widgets
Qt::Svg
Expand Down
22 changes: 22 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.22...3.25)

legacy_check()

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}/obs-websocket-api.h>
$<INSTALL_INTERFACE:${OBS_INCLUDE_DESTINATION}/obs-websocker-api.h>)

target_link_libraries(obs-websocket-api INTERFACE OBS::libobs)

target_include_directories(obs-websocket-api INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${OBS_INCLUDE_DESTINATION}>")

set_target_properties(
obs-websocket-api
PROPERTIES FOLDER websocket
PREFIX ""
PUBLIC_HEADER obs-websocket-api.h)

target_export(obs-websocket-api)
20 changes: 20 additions & 0 deletions lib/cmake/legacy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if(POLICY CMP0090)
cmake_policy(SET CMP0090 NEW)
endif()

project(obs-websocket-api)

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}/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}>
$<INSTALL_INTERFACE:${OBS_INCLUDE_DESTINATION}>)

set_target_properties(obs-websocket-api PROPERTIES FOLDER "websocket" PUBLIC_HEADER obs-websocket-api.h)

export_target(obs-websocket-api)
8 changes: 8 additions & 0 deletions lib/cmake/obs-websocket-apiConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

find_dependency(libobs REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
3 changes: 1 addition & 2 deletions src/WebSocketApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 726dc92

Please sign in to comment.