obs-websocket/CMakeLists.txt

305 lines
8.9 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.16...3.20)
# Version variables
2021-03-08 11:56:43 +00:00
project(obs-websocket VERSION 5.0.0)
2021-04-27 21:52:48 +00:00
set(OBS_WEBSOCKET_RPC_VERSION 1)
2021-03-08 11:56:43 +00:00
# Set correct version string
if(DEFINED OBS_WEBSOCKET_VERSION_SUFFIX AND NOT OBS_WEBSOCKET_VERSION_SUFFIX STREQUAL "")
set(OBS_WEBSOCKET_VERSION "${CMAKE_PROJECT_VERSION}${OBS_WEBSOCKET_VERSION_SUFFIX}")
message(WARNING "-----------------------------------\nVersion Suffix provided. OBS_WEBSOCKET_VERSION is now ${OBS_WEBSOCKET_VERSION}\n-----------------------------------")
else()
set(OBS_WEBSOCKET_VERSION "${CMAKE_PROJECT_VERSION}")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Prohibit in-source builds
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" _LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR "obs-websocket: You cannot build in a source directory (or any directory with "
"CMakeLists.txt file). Please make a build subdirectory. Feel free to "
"remove CMakeCache.txt and CMakeFiles.")
endif()
unset(_LOC_PATH)
# Allow selection of common build types via UI
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
"OBS build type [Release, RelWithDebInfo, Debug, MinSizeRel]" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Release RelWithDebInfo Debug MinSizeRel)
endif()
# Qt build stuff
2021-03-08 11:56:43 +00:00
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
2021-03-08 11:56:43 +00:00
# Tell websocketpp not to use system boost
2021-03-08 11:56:43 +00:00
add_definitions(-DASIO_STANDALONE)
# Arm build fixes
2021-03-08 11:56:43 +00:00
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
set(CMAKE_CXX_FLAGS "-mfpu=neon")
2021-03-08 11:56:43 +00:00
endif()
# Find libobs
2021-03-08 11:56:43 +00:00
if (WIN32 OR APPLE)
include(cmake/FindLibObs.cmake)
2021-03-08 11:56:43 +00:00
endif()
find_package(LibObs REQUIRED)
# Find Qt5
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Svg Network)
# Find nlohmann
set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(deps/json)
# Configure files
configure_file(
src/plugin-macros.h.in
../src/plugin-macros.generated.h
)
configure_file(
installer/installer-windows.iss.in
../installer/installer-windows.generated.iss
)
# Inlude sources
2021-03-08 11:56:43 +00:00
set(obs-websocket_SOURCES
2021-04-27 02:59:50 +00:00
src/obs-websocket.cpp
2021-04-27 19:51:58 +00:00
src/Config.cpp
src/WebSocketServer.cpp
src/WebSocketServer_Protocol.cpp
Base: Add request batch execution types A new `executionType` field has been added to the `RequestBatch` Op Types added: - `OBS_WEBSOCKET_REQUEST_BATCH_EXECUTION_TYPE_SERIAL_REALTIME`(default) - `OBS_WEBSOCKET_REQUEST_BATCH_EXECUTION_TYPE_SERIAL_FRAME` - `OBS_WEBSOCKET_REQUEST_BATCH_EXECUTION_TYPE_PARALLEL` `OBS_WEBSOCKET_REQUEST_BATCH_EXECUTION_TYPE_SERIAL_REALTIME`: - Same as how request batches have always worked. - Requests are processed in-order - Requests are processed as soon as possible by one worker thread - The `Sleep` request blocks execution for a specified amount of real world time `OBS_WEBSOCKET_REQUEST_BATCH_EXECUTION_TYPE_SERIAL_FRAME`: - New! - Requests are processed in-order - Requests are processed on the graphics thread. BE VERY CAREFUL NOT TO OVERLOAD THE GRAPHICS THREAD WITH LARGE REQUESTS. A general rule of thumb is for your request batches to take a maximum of 2ms per frame of processing. - Requests processing starts right before the next frame is composited. This functionality is perfect for things like `SetSceneItemTransform` - The `Sleep` request will halt processing of the request batch for a specified number of frames (ticks) - To be clear: If you do not have any sleep requests, all requests in the batch will be processed in the span of a single frame - For developers: The execution of requests gets profiled by the OBS profiler under the `obs-websocket-request-batch-frame-tick` name. This value (shown in the OBS log after OBS shutdown) represents the amount of time that the graphics thread spent actively processing requests per frame. This tool can be used to determine the amount of load that your request batches are placing on the graphics thread. `OBS_WEBSOCKET_REQUEST_BATCH_EXECUTION_TYPE_PARALLEL`: - New! - Requests are processed asynchronously at the soonest possible time. - Requests are processed by the core obs-websocket thread pool, where the number of workers == the number of threads on your machine. - If you have 12 threads on your machine, obs-websocket will be able to process 12 requests at any given moment. - The `results` array is populated by order of request completion. Consider the order to be random. - The `Sleep` request will return an error if attempted to be used in this mode. - Note: This feature is experimental and can increase the chances of causing race conditions (crashes). While the implementation is fully thread-safe, OBS itself is not. Usage of this is only recommended if you are processing very large batches and need the performance benefit. - Example use case: Performing `SaveSourceScreenshot` on 8 sources at once.
2021-09-26 10:12:29 +00:00
src/WebSocketServer_RequestBatchProcessing.cpp
2021-06-15 06:00:33 +00:00
src/WebSocketSession.cpp
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
2021-04-27 19:51:58 +00:00
src/requesthandler/RequestHandler.cpp
2021-06-15 06:00:33 +00:00
src/requesthandler/RequestHandler_General.cpp
src/requesthandler/RequestHandler_Config.cpp
src/requesthandler/RequestHandler_Sources.cpp
src/requesthandler/RequestHandler_Scenes.cpp
2021-08-27 02:09:52 +00:00
src/requesthandler/RequestHandler_Inputs.cpp
2021-09-03 02:29:13 +00:00
src/requesthandler/RequestHandler_SceneItems.cpp
2021-08-27 02:09:52 +00:00
src/requesthandler/RequestHandler_Stream.cpp
2021-04-27 19:51:58 +00:00
src/requesthandler/rpc/Request.cpp
2021-06-15 06:00:33 +00:00
src/requesthandler/rpc/RequestResult.cpp
2021-04-27 19:51:58 +00:00
src/forms/SettingsDialog.cpp
2021-06-15 06:00:33 +00:00
src/forms/ConnectInfo.cpp
src/forms/resources.qrc
2021-08-27 02:09:52 +00:00
src/utils/Crypto.cpp
src/utils/Json.cpp
2021-06-15 06:00:33 +00:00
src/utils/Obs.cpp
2021-08-27 02:09:52 +00:00
src/utils/Platform.cpp
src/utils/Compat.cpp
2021-06-15 06:00:33 +00:00
deps/qr/cpp/QrCode.cpp)
2021-03-08 11:56:43 +00:00
set(obs-websocket_HEADERS
2021-04-27 02:59:50 +00:00
src/obs-websocket.h
2021-04-27 19:51:58 +00:00
src/Config.h
src/WebSocketServer.h
2021-06-15 06:00:33 +00:00
src/WebSocketSession.h
src/eventhandler/EventHandler.h
src/eventhandler/types/EventSubscription.h
2021-04-27 19:51:58 +00:00
src/requesthandler/RequestHandler.h
src/requesthandler/rpc/Request.h
2021-06-15 06:00:33 +00:00
src/requesthandler/rpc/RequestResult.h
src/requesthandler/rpc/RequestStatus.h
2021-04-27 19:51:58 +00:00
src/forms/SettingsDialog.h
2021-06-15 06:00:33 +00:00
src/forms/ConnectInfo.h
src/utils/Crypto.h
2021-08-27 02:09:52 +00:00
src/utils/Json.h
src/utils/Obs.h
src/utils/Platform.h
src/utils/Compat.h
src/utils/Utils.h
2021-06-15 06:00:33 +00:00
deps/qr/cpp/QrCode.hpp)
2021-03-08 11:56:43 +00:00
# Platform-independent build settings
2021-03-08 11:56:43 +00:00
add_library(obs-websocket MODULE
${obs-websocket_SOURCES}
${obs-websocket_HEADERS})
include_directories(
"${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api"
${Qt5Core_INCLUDES}
${Qt5Widgets_INCLUDES}
2021-06-15 06:00:33 +00:00
${Qt5Svg_INCLUDES}
${Qt5Network_INCLUDES}
2021-03-08 11:56:43 +00:00
"${CMAKE_SOURCE_DIR}/deps/asio/asio/include"
"${CMAKE_SOURCE_DIR}/deps/websocketpp")
target_link_libraries(obs-websocket
libobs
Qt5::Core
Qt5::Widgets
2021-06-15 06:00:33 +00:00
Qt5::Svg
Qt5::Network
2021-04-27 19:51:58 +00:00
nlohmann_json::nlohmann_json)
2021-03-08 11:56:43 +00:00
# Windows-specific build settings and tasks
2021-03-08 11:56:43 +00:00
if(WIN32)
if(NOT DEFINED OBS_FRONTEND_LIB)
set(OBS_FRONTEND_LIB "OBS_FRONTEND_LIB-NOTFOUND" CACHE FILEPATH "OBS frontend library")
message(FATAL_ERROR "Could not find OBS Frontend API's library!")
2021-03-08 11:56:43 +00:00
endif()
if(MSVC)
# Enable Multicore Builds and disable FH4 (to not depend on VCRUNTIME140_1.DLL)
add_definitions(/MP /d2FH4-)
endif()
2021-03-08 11:56:43 +00:00
add_definitions(-D_WEBSOCKETPP_CPP11_STL_)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH_NAME "64bit")
set(OBS_BUILDDIR_ARCH "build64")
else()
set(ARCH_NAME "32bit")
set(OBS_BUILDDIR_ARCH "build32")
endif()
include_directories(
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/UI"
)
target_link_libraries(obs-websocket
"${OBS_FRONTEND_LIB}")
# Release package helper
2021-03-08 11:56:43 +00:00
# The "release" folder has a structure similar OBS' one on Windows
set(RELEASE_DIR "${PROJECT_SOURCE_DIR}/release")
add_custom_command(TARGET obs-websocket POST_BUILD
# If config is Release or RelWithDebInfo, package release files
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
2021-03-08 11:56:43 +00:00
"${CMAKE_COMMAND}" -E make_directory
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)
2021-03-08 11:56:43 +00:00
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E copy_directory
2021-03-08 11:56:43 +00:00
"${PROJECT_SOURCE_DIR}/data"
"${RELEASE_DIR}/data/obs-plugins/obs-websocket"
)
2021-03-08 11:56:43 +00:00
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E copy
2021-03-08 11:56:43 +00:00
"$<TARGET_FILE:obs-websocket>"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)
2021-03-08 11:56:43 +00:00
# In Release or RelWithDebInfo mode, copy Qt image format plugins
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E make_directory
"${RELEASE_DIR}/bin/${ARCH_NAME}/imageformats"
)
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
2021-03-08 11:56:43 +00:00
"${CMAKE_COMMAND}" -E copy
"${QTDIR}/plugins/imageformats/qicns.dll"
"${QTDIR}/plugins/imageformats/qico.dll"
2021-03-08 11:56:43 +00:00
"${QTDIR}/plugins/imageformats/qjpeg.dll"
"${QTDIR}/plugins/imageformats/qtiff.dll"
"${QTDIR}/plugins/imageformats/qwbmp.dll"
"${QTDIR}/plugins/imageformats/qwebp.dll"
"${RELEASE_DIR}/bin/${ARCH_NAME}/imageformats"
)
2021-03-08 11:56:43 +00:00
# If config is RelWithDebInfo, package PDB file for target
2021-03-08 11:56:43 +00:00
COMMAND if $<CONFIG:RelWithDebInfo>==1 (
"${CMAKE_COMMAND}" -E copy
2021-03-08 11:56:43 +00:00
"$<TARGET_PDB_FILE:obs-websocket>"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)
2021-03-08 11:56:43 +00:00
# In the Debug configuration, copy to obs-studio dev environment for immediate testing
2021-03-08 11:56:43 +00:00
COMMAND if $<CONFIG:Debug>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:obs-websocket>"
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/obs-plugins/${ARCH_NAME}"
)
2021-03-08 11:56:43 +00:00
COMMAND if $<CONFIG:Debug>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_PDB_FILE:obs-websocket>"
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/obs-plugins/${ARCH_NAME}"
)
2021-03-08 11:56:43 +00:00
COMMAND if $<CONFIG:Debug>==1 (
"${CMAKE_COMMAND}" -E make_directory
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/data/obs-plugins/obs-websocket"
)
2021-03-08 11:56:43 +00:00
COMMAND if $<CONFIG:Debug>==1 (
"${CMAKE_COMMAND}" -E copy_directory
"${PROJECT_SOURCE_DIR}/data"
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/data/obs-plugins/obs-websocket"
)
2021-03-08 11:56:43 +00:00
)
endif()
# Linux-specific build settings and tasks
2021-03-08 11:56:43 +00:00
if(UNIX AND NOT APPLE)
include(GNUInstallDirs)
set_target_properties(obs-websocket PROPERTIES PREFIX "")
target_link_libraries(obs-websocket obs-frontend-api)
# Manually set permissions for locales
2021-03-08 11:56:43 +00:00
file(GLOB locale_files data/locale/*.ini)
set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
2021-03-08 11:56:43 +00:00
OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
# Manually set file permissions for binary
install(TARGETS obs-websocket LIBRARY
DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/obs-plugins"
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
# OBS on Ubuntu installs into a different directory than most linux distros
2021-03-08 11:56:43 +00:00
if(${USE_UBUNTU_FIX})
install(TARGETS obs-websocket LIBRARY
DESTINATION "/usr/lib/obs-plugins"
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endif()
install(FILES ${locale_files}
DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/obs/obs-plugins/obs-websocket/locale")
endif()
# MacOS-specific build settings and tasks
2021-03-08 11:56:43 +00:00
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fvisibility=default")
set(CMAKE_SKIP_RPATH TRUE)
set_target_properties(obs-websocket PROPERTIES PREFIX "")
target_link_libraries(obs-websocket "${OBS_FRONTEND_LIB}")
endif()