Skip to content

Commit

Permalink
cmake: Add changes for CMake build framework 3.0
Browse files Browse the repository at this point in the history
New code path only taken if OBS_CMAKE_VERSION is set to 3.0.0 or
greater, old functionality remains unchanged.

Minimum required CMake version: 3.22
  • Loading branch information
PatTheMav committed Mar 4, 2023
1 parent 994472f commit 8618ca3
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 75 deletions.
133 changes: 58 additions & 75 deletions CMakeLists.txt
@@ -1,52 +1,27 @@
project(obs-websocket VERSION 5.1.0)
set(OBS_WEBSOCKET_RPC_VERSION 1)
cmake_minimum_required(VERSION 3.16...3.25)

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

if(NOT ENABLE_WEBSOCKET OR NOT ENABLE_UI)
message(STATUS "OBS: DISABLED obs-websocket")
option(ENABLE_WEBSOCKET "Enable building OBS with websocket plugin" ON)
if(NOT ENABLE_WEBSOCKET)
target_disable(obs-websocket)
return()
endif()

# Submodule deps check
if(NOT
(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/deps/json/CMakeLists.txt
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/deps/websocketpp/CMakeLists.txt
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/deps/qr/cpp/QrCode.hpp
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/deps/asio/asio/include/asio.hpp))
obs_status(FATAL_ERROR "obs-websocket submodule deps not available.")
endif()

# Plugin tests flag
option(PLUGIN_TESTS "Enable plugin runtime tests" OFF)

# Qt build stuff
set(CMAKE_PREFIX_PATH "${QTDIR}")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON) # For resources.qrc
set(OBS_WEBSOCKET_RPC_VERSION 1)

# Find Qt
find_qt(COMPONENTS Core Widgets Svg Network)

# Find nlohmann
set(JSON_BuildTests
OFF
CACHE INTERNAL "")
add_subdirectory(deps/json)

# Tell websocketpp not to use system boost
add_definitions(-DASIO_STANDALONE)

# Configure files
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/plugin-macros.h.in
${CMAKE_CURRENT_SOURCE_DIR}/src/plugin-macros.generated.h)

# Setup target
add_library(obs-websocket MODULE)
add_library(OBS::websocket ALIAS obs-websocket)

target_sources(obs-websocket PRIVATE)

target_sources(
obs-websocket
PRIVATE src/obs-websocket.cpp
Expand All @@ -60,15 +35,21 @@ target_sources(
src/forms/ConnectInfo.h
src/forms/resources.qrc
src/WebSocketApi.cpp
src/WebSocketApi.h
src/websocketserver/WebSocketServer.cpp
src/WebSocketApi.h)

target_sources(
obs-websocket
PRIVATE src/websocketserver/WebSocketServer.cpp
src/websocketserver/WebSocketServer_Protocol.cpp
src/websocketserver/WebSocketServer.h
src/websocketserver/rpc/WebSocketSession.cpp
src/websocketserver/rpc/WebSocketSession.h
src/websocketserver/types/WebSocketCloseCode.h
src/websocketserver/types/WebSocketOpCode.h
src/eventhandler/EventHandler.cpp
src/websocketserver/types/WebSocketOpCode.h)

target_sources(
obs-websocket
PRIVATE src/eventhandler/EventHandler.cpp
src/eventhandler/EventHandler_General.cpp
src/eventhandler/EventHandler_Config.cpp
src/eventhandler/EventHandler_Scenes.cpp
Expand All @@ -80,8 +61,11 @@ target_sources(
src/eventhandler/EventHandler_MediaInputs.cpp
src/eventhandler/EventHandler_Ui.cpp
src/eventhandler/EventHandler.h
src/eventhandler/types/EventSubscription.h
src/requesthandler/RequestHandler.cpp
src/eventhandler/types/EventSubscription.h)

target_sources(
obs-websocket
PRIVATE src/requesthandler/RequestHandler.cpp
src/requesthandler/RequestHandler_General.cpp
src/requesthandler/RequestHandler_Config.cpp
src/requesthandler/RequestHandler_Sources.cpp
Expand All @@ -105,8 +89,11 @@ target_sources(
src/requesthandler/rpc/RequestResult.cpp
src/requesthandler/rpc/RequestResult.h
src/requesthandler/types/RequestStatus.h
src/requesthandler/types/RequestBatchExecutionType.h
src/utils/Crypto.cpp
src/requesthandler/types/RequestBatchExecutionType.h)

target_sources(
obs-websocket
PRIVATE src/utils/Crypto.cpp
src/utils/Crypto.h
src/utils/Json.cpp
src/utils/Json.h
Expand All @@ -125,14 +112,31 @@ target_sources(
src/utils/Platform.h
src/utils/Compat.cpp
src/utils/Compat.h
src/utils/Utils.h
deps/qr/cpp/QrCode.cpp
deps/qr/cpp/QrCode.hpp)
src/utils/Utils.h)

target_sources(obs-websocket PRIVATE deps/qr/cpp/QrCode.cpp deps/qr/cpp/QrCode.hpp)

configure_file(src/plugin-macros.h.in src/plugin-macros.generated.h)
target_sources(obs-websocket PRIVATE src/plugin-macros.generated.h)

target_include_directories(
target_compile_definitions(
obs-websocket
PRIVATE ${Qt5Core_INCLUDES} ${Qt5Widgets_INCLUDES} ${Qt5Svg_INCLUDES}
${Qt5Network_INCLUDES} "deps/asio/asio/include" "deps/websocketpp")
PRIVATE ASIO_STANDALONE $<$<BOOL:PLUGIN_TESTS>:PLUGIN_TESTS>
$<$<PLATFORM_ID:Windows>:_WEBSOCKETPP_CPP11_STL_>
$<$<PLATFORM_ID:Windows>:_WIN32_WINNT=0x0603>)
target_compile_features(obs-websocket PRIVATE cxx_std_17)
target_compile_options(
obs-websocket
PRIVATE
$<$<PLATFORM_ID:Windows>:/wd4267>
$<$<PLATFORM_ID:Windows>:/wd4996>
$<$<PLATFORM_ID:Darwin,Linux,FreeBSD>:-Wall>
$<$<COMPILE_LANG_AND_ID:CXX,GNU,AppleClang,Clang>:-Wno-error=float-conversion;-Wno-error=shadow>
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wno-error=format-overflow;-Wno-error=int-conversion;-Wno-error=comment>
$<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:-Wno-error=null-pointer-subtraction;-Wno-error=deprecated-declarations;-Wno-error=implicit-int-conversion;-Wno-error=shorten-64-to-32>
)

target_include_directories(obs-websocket PRIVATE deps/asio/asio/include deps/websocketpp)

target_link_libraries(
obs-websocket
Expand All @@ -144,31 +148,10 @@ target_link_libraries(
Qt::Network
nlohmann_json::nlohmann_json)

target_compile_features(obs-websocket PRIVATE cxx_std_17)

set_target_properties(obs-websocket PROPERTIES FOLDER "plugins/obs-websocket")

if(PLUGIN_TESTS)
target_compile_definitions(obs-websocket PRIVATE PLUGIN_TESTS)
endif()

# Random other things
if(WIN32)
add_definitions(-D_WEBSOCKETPP_CPP11_STL_)
endif()

if(MSVC)
target_compile_options(obs-websocket PRIVATE /wd4267 /wd4996)
else()
target_compile_options(
obs-websocket
PRIVATE
-Wall
"$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wno-error=format-overflow>"
"$<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:-Wno-error=null-pointer-subtraction;-Wno-error=deprecated-declarations>"
)
endif()

# Final CMake helpers
setup_plugin_target(obs-websocket)
setup_target_resources(obs-websocket "obs-plugins/obs-websocket")
set_target_properties_obs(
obs-websocket
PROPERTIES FOLDER plugins
PREFIX ""
AUTOMOC ON
AUTOUIC ON
AUTORCC ON)
173 changes: 173 additions & 0 deletions cmake/legacy.cmake
@@ -0,0 +1,173 @@
project(obs-websocket VERSION 5.1.0)
set(OBS_WEBSOCKET_RPC_VERSION 1)

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

if(NOT ENABLE_WEBSOCKET OR NOT ENABLE_UI)
message(STATUS "OBS: DISABLED obs-websocket")
return()
endif()

# Submodule deps check
if(NOT
(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/deps/json/CMakeLists.txt
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/deps/websocketpp/CMakeLists.txt
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/deps/qr/cpp/QrCode.hpp
AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/deps/asio/asio/include/asio.hpp))
obs_status(FATAL_ERROR "obs-websocket submodule deps not available.")
endif()

# Plugin tests flag
option(PLUGIN_TESTS "Enable plugin runtime tests" OFF)

# Qt build stuff
set(CMAKE_PREFIX_PATH "${QTDIR}")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON) # For resources.qrc

# Find Qt
find_qt(COMPONENTS Core Widgets Svg Network)

# Find nlohmann
set(JSON_BuildTests
OFF
CACHE INTERNAL "")
add_subdirectory(deps/json)

# Tell websocketpp not to use system boost
add_definitions(-DASIO_STANDALONE)

# Configure files
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/plugin-macros.h.in
${CMAKE_CURRENT_SOURCE_DIR}/src/plugin-macros.generated.h)

# Setup target
add_library(obs-websocket MODULE)
add_library(OBS::websocket ALIAS obs-websocket)

target_sources(
obs-websocket
PRIVATE src/obs-websocket.cpp
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
src/forms/ConnectInfo.h
src/forms/resources.qrc
src/WebSocketApi.cpp
src/WebSocketApi.h
src/websocketserver/WebSocketServer.cpp
src/websocketserver/WebSocketServer_Protocol.cpp
src/websocketserver/WebSocketServer.h
src/websocketserver/rpc/WebSocketSession.cpp
src/websocketserver/rpc/WebSocketSession.h
src/websocketserver/types/WebSocketCloseCode.h
src/websocketserver/types/WebSocketOpCode.h
src/eventhandler/EventHandler.cpp
src/eventhandler/EventHandler_General.cpp
src/eventhandler/EventHandler_Config.cpp
src/eventhandler/EventHandler_Scenes.cpp
src/eventhandler/EventHandler_Inputs.cpp
src/eventhandler/EventHandler_Transitions.cpp
src/eventhandler/EventHandler_Filters.cpp
src/eventhandler/EventHandler_Outputs.cpp
src/eventhandler/EventHandler_SceneItems.cpp
src/eventhandler/EventHandler_MediaInputs.cpp
src/eventhandler/EventHandler_Ui.cpp
src/eventhandler/EventHandler.h
src/eventhandler/types/EventSubscription.h
src/requesthandler/RequestHandler.cpp
src/requesthandler/RequestHandler_General.cpp
src/requesthandler/RequestHandler_Config.cpp
src/requesthandler/RequestHandler_Sources.cpp
src/requesthandler/RequestHandler_Scenes.cpp
src/requesthandler/RequestHandler_Inputs.cpp
src/requesthandler/RequestHandler_Transitions.cpp
src/requesthandler/RequestHandler_Filters.cpp
src/requesthandler/RequestHandler_SceneItems.cpp
src/requesthandler/RequestHandler_Outputs.cpp
src/requesthandler/RequestHandler_Stream.cpp
src/requesthandler/RequestHandler_Record.cpp
src/requesthandler/RequestHandler_MediaInputs.cpp
src/requesthandler/RequestHandler_Ui.cpp
src/requesthandler/RequestHandler.h
src/requesthandler/RequestBatchHandler.cpp
src/requesthandler/RequestBatchHandler.h
src/requesthandler/rpc/Request.cpp
src/requesthandler/rpc/Request.h
src/requesthandler/rpc/RequestBatchRequest.cpp
src/requesthandler/rpc/RequestBatchRequest.h
src/requesthandler/rpc/RequestResult.cpp
src/requesthandler/rpc/RequestResult.h
src/requesthandler/types/RequestStatus.h
src/requesthandler/types/RequestBatchExecutionType.h
src/utils/Crypto.cpp
src/utils/Crypto.h
src/utils/Json.cpp
src/utils/Json.h
src/utils/Obs.cpp
src/utils/Obs_StringHelper.cpp
src/utils/Obs_NumberHelper.cpp
src/utils/Obs_ArrayHelper.cpp
src/utils/Obs_ObjectHelper.cpp
src/utils/Obs_SearchHelper.cpp
src/utils/Obs_ActionHelper.cpp
src/utils/Obs.h
src/utils/Obs_VolumeMeter.cpp
src/utils/Obs_VolumeMeter.h
src/utils/Obs_VolumeMeter_Helpers.h
src/utils/Platform.cpp
src/utils/Platform.h
src/utils/Compat.cpp
src/utils/Compat.h
src/utils/Utils.h
deps/qr/cpp/QrCode.cpp
deps/qr/cpp/QrCode.hpp)

target_include_directories(
obs-websocket PRIVATE ${Qt5Core_INCLUDES} ${Qt5Widgets_INCLUDES} ${Qt5Svg_INCLUDES}
${Qt5Network_INCLUDES} "deps/asio/asio/include" "deps/websocketpp")

target_link_libraries(
obs-websocket
PRIVATE OBS::libobs
OBS::frontend-api
Qt::Core
Qt::Widgets
Qt::Svg
Qt::Network
nlohmann_json::nlohmann_json)

target_compile_features(obs-websocket PRIVATE cxx_std_17)

set_target_properties(obs-websocket PROPERTIES FOLDER "plugins/obs-websocket")

if(PLUGIN_TESTS)
target_compile_definitions(obs-websocket PRIVATE PLUGIN_TESTS)
endif()

# Random other things
if(WIN32)
add_definitions(-D_WEBSOCKETPP_CPP11_STL_)
endif()

if(MSVC)
target_compile_options(obs-websocket PRIVATE /wd4267 /wd4996)
else()
target_compile_options(
obs-websocket
PRIVATE
-Wall
"$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wno-error=format-overflow;-Wno-comment>"
"$<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:-Wno-error=null-pointer-subtraction;-Wno-error=deprecated-declarations>"
)
endif()

# Final CMake helpers
setup_plugin_target(obs-websocket)
setup_target_resources(obs-websocket "obs-plugins/obs-websocket")
28 changes: 28 additions & 0 deletions cmake/macos/Info.plist.in
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>obs-websocket</string>
<key>CFBundleIdentifier</key>
<string>com.obsproject.obs-websocket</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleExecutable</key>
<string>obs-websocket</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>LSMinimumSystemVersion</key>
<string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
<string>(c) 2016-${CURRENT_YEAR} Stéphane Lepin, Kyle Manning</string>
</dict>
</plist>

0 comments on commit 8618ca3

Please sign in to comment.