|
|
@@ -1,216 +1,181 @@
|
|
|
-cmake_minimum_required(VERSION 2.8.12)
|
|
|
+option(ENABLE_SCRIPTING_LUA "Enable Lua scripting support" ON)
|
|
|
+option(ENABLE_SCRIPTING_PYTHON "Enable Python scripting support" ON)
|
|
|
|
|
|
if(NOT ENABLE_SCRIPTING)
|
|
|
- message(STATUS "Scripting plugin disabled")
|
|
|
- return()
|
|
|
+ message(STATUS "OBS: DISABLED obs-scripting")
|
|
|
+ return()
|
|
|
endif()
|
|
|
|
|
|
project(obs-scripting)
|
|
|
|
|
|
-if(POLICY CMP0068)
|
|
|
- # RPATH settings on macOS do not affect install_name.
|
|
|
- cmake_policy(SET CMP0068 NEW)
|
|
|
+if(ENABLE_SCRIPTING_LUA)
|
|
|
+ add_subdirectory(obslua)
|
|
|
+ find_package(Luajit)
|
|
|
+
|
|
|
+ if(NOT TARGET Luajit::Luajit)
|
|
|
+ message(FATAL_ERROR "OBS: - Luajit not found")
|
|
|
+ return()
|
|
|
+ else()
|
|
|
+ message(STATUS "OBS: - Luajit found")
|
|
|
+ endif()
|
|
|
+else()
|
|
|
+ message(STATUS "OBS: DISABLED Luajit support")
|
|
|
+endif()
|
|
|
+
|
|
|
+if(ENABLE_SCRIPTING_PYTHON)
|
|
|
+ add_subdirectory(obspython)
|
|
|
+ if(OS_WINDOWS)
|
|
|
+ find_package(PythonWindows)
|
|
|
+ else()
|
|
|
+ find_package(Python COMPONENTS Interpreter Development)
|
|
|
+ endif()
|
|
|
+
|
|
|
+ if(NOT TARGET Python::Python)
|
|
|
+ message(FATAL_ERROR "OBS: - Python not found")
|
|
|
+ return()
|
|
|
+ else()
|
|
|
+ message(STATUS "OBS: - Python ${Python_VERSION} found")
|
|
|
+ endif()
|
|
|
+else()
|
|
|
+ message(STATUS "OBS: DISABLED Python support")
|
|
|
endif()
|
|
|
|
|
|
-if(MSVC)
|
|
|
- set(obs-scripting_PLATFORM_DEPS
|
|
|
- w32-pthreads)
|
|
|
+if(NOT TARGET Luajit::Luajit AND NOT TARGET Python::Python)
|
|
|
+ message(
|
|
|
+ WARNING
|
|
|
+ "OBS: DISABLED obs-scripting - no supported scripting libraries found")
|
|
|
+ return()
|
|
|
endif()
|
|
|
|
|
|
-if(APPLE)
|
|
|
- set(obs-scripting_PLATFORM_DEPS
|
|
|
- objc)
|
|
|
+if(OS_MACOS)
|
|
|
+ find_package(SWIG 4 REQUIRED)
|
|
|
+elseif(OS_POSIX)
|
|
|
+ find_package(SWIG 3 REQUIRED)
|
|
|
+elseif(OS_WINDOWS)
|
|
|
+ find_package(SwigWindows 3 REQUIRED)
|
|
|
endif()
|
|
|
|
|
|
-option(DISABLE_LUA "Disable Lua scripting support" OFF)
|
|
|
-option(DISABLE_PYTHON "Disable Python scripting support" OFF)
|
|
|
+add_library(obs-scripting SHARED)
|
|
|
+add_library(OBS::scripting ALIAS obs-scripting)
|
|
|
|
|
|
-set(COMPILE_PYTHON FALSE CACHE BOOL "" FORCE)
|
|
|
-set(COMPILE_LUA FALSE CACHE BOOL "" FORCE)
|
|
|
+target_sources(
|
|
|
+ obs-scripting
|
|
|
+ PUBLIC obs-scripting.h
|
|
|
+ PRIVATE obs-scripting.c cstrcache.cpp cstrcache.h obs-scripting-logging.c
|
|
|
+ obs-scripting-callback.h)
|
|
|
|
|
|
-if(NOT DISABLE_LUA)
|
|
|
- find_package(Luajit QUIET)
|
|
|
+target_link_libraries(obs-scripting PRIVATE OBS::libobs)
|
|
|
|
|
|
- if(NOT DISABLE_LUA AND NOT LUAJIT_FOUND)
|
|
|
- message(STATUS "Luajit support not found.")
|
|
|
- set(LUAJIT_FOUND FALSE)
|
|
|
- else()
|
|
|
- message(STATUS "Scripting: Luajit supported")
|
|
|
- set(COMPILE_LUA TRUE CACHE BOOL "" FORCE)
|
|
|
- endif()
|
|
|
-else()
|
|
|
- message(STATUS "Scripting: Luajit support disabled")
|
|
|
- set(LUAJIT_FOUND FALSE)
|
|
|
-endif()
|
|
|
+target_compile_features(obs-scripting PRIVATE cxx_auto_type)
|
|
|
|
|
|
-if(NOT DISABLE_PYTHON)
|
|
|
- find_package(PythonDeps QUIET)
|
|
|
-
|
|
|
- if(NOT DISABLE_PYTHON AND NOT PYTHONLIBS_FOUND)
|
|
|
- message(STATUS "Python support not found.")
|
|
|
- set(PYTHON_FOUND FALSE)
|
|
|
- set(PYTHONLIBS_FOUND FALSE)
|
|
|
- else()
|
|
|
- message(STATUS "Scripting: Python 3 supported")
|
|
|
- set(PYTHON_FOUND TRUE)
|
|
|
- set(COMPILE_PYTHON TRUE CACHE BOOL "" FORCE)
|
|
|
-
|
|
|
- get_filename_component(PYTHON_LIB "${PYTHON_LIBRARIES}" NAME)
|
|
|
- string(REGEX REPLACE "\\.[^.]*$" "" PYTHON_LIB ${PYTHON_LIB})
|
|
|
-
|
|
|
- if(WIN32)
|
|
|
- string(REGEX REPLACE "_d" "" PYTHON_LIB "${PYTHON_LIB}")
|
|
|
- endif()
|
|
|
- endif()
|
|
|
-else()
|
|
|
- message(STATUS "Scripting: Python 3 support disabled")
|
|
|
- set(PYTHON_FOUND FALSE)
|
|
|
- set(PYTHONLIBS_FOUND FALSE)
|
|
|
-endif()
|
|
|
+target_include_directories(obs-scripting PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
+ ${CMAKE_BINARY_DIR}/config)
|
|
|
|
|
|
-find_package(SwigDeps QUIET 2)
|
|
|
+if(OS_WINDOWS)
|
|
|
+ set(MODULE_DESCRIPTION "OBS Studio scripting module")
|
|
|
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/bundle/windows/obs-module.rc.in
|
|
|
+ obs-scripting.rc)
|
|
|
|
|
|
-if(NOT SWIG_FOUND)
|
|
|
- message(STATUS "Scripting: SWIG not found; scripting disabled")
|
|
|
- return()
|
|
|
-endif()
|
|
|
+ target_sources(obs-scripting PRIVATE obs-scripting.rc)
|
|
|
+
|
|
|
+ target_link_libraries(obs-scripting PRIVATE OBS::w32-pthreads)
|
|
|
|
|
|
-if(NOT PYTHONLIBS_FOUND AND NOT LUAJIT_FOUND)
|
|
|
- message(STATUS "Scripting: Neither Python 3 nor Luajit was found; scripting plugin disabled")
|
|
|
- return()
|
|
|
+elseif(OS_MACOS)
|
|
|
+ target_link_libraries(obs-scripting PRIVATE objc)
|
|
|
endif()
|
|
|
|
|
|
-set(SCRIPTING_ENABLED ON CACHE BOOL "Internal global cmake variable" FORCE)
|
|
|
+set_target_properties(
|
|
|
+ obs-scripting
|
|
|
+ PROPERTIES FOLDER "scripting"
|
|
|
+ VERSION "${OBS_VERSION_MAJOR}"
|
|
|
+ SOVERSION "1")
|
|
|
|
|
|
-if(UI_ENABLED)
|
|
|
- set(EXTRA_LIBS obs-frontend-api)
|
|
|
- include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/UI/obs-frontend-api")
|
|
|
-endif()
|
|
|
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/swig)
|
|
|
|
|
|
-configure_file(
|
|
|
- "${CMAKE_CURRENT_SOURCE_DIR}/obs-scripting-config.h.in"
|
|
|
- "${CMAKE_CURRENT_BINARY_DIR}/obs-scripting-config.h")
|
|
|
-
|
|
|
-include(${SWIG_USE_FILE})
|
|
|
-
|
|
|
-include_directories(${CMAKE_SOURCE_DIR}/libobs)
|
|
|
-include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
|
|
-
|
|
|
-if(PYTHONLIBS_FOUND)
|
|
|
- include_directories(${PYTHON_INCLUDE_DIR})
|
|
|
-
|
|
|
- set(obs-scripting-python_SOURCES
|
|
|
- obs-scripting-python.c
|
|
|
- )
|
|
|
- set(obs-scripting-python_HEADERS
|
|
|
- obs-scripting-python.h
|
|
|
- obs-scripting-python-import.h
|
|
|
- )
|
|
|
-
|
|
|
- if(UI_ENABLED)
|
|
|
- set(obs-scripting-python_SOURCES
|
|
|
- ${obs-scripting-python_SOURCES}
|
|
|
- obs-scripting-python-frontend.c
|
|
|
- )
|
|
|
- endif()
|
|
|
- if(WIN32 OR APPLE)
|
|
|
- set(obs-scripting-python_SOURCES
|
|
|
- ${obs-scripting-python_SOURCES}
|
|
|
- obs-scripting-python-import.c
|
|
|
- )
|
|
|
- else()
|
|
|
- set(EXTRA_LIBS ${EXTRA_LIBS} ${PYTHON_LIBRARIES})
|
|
|
- endif()
|
|
|
-endif()
|
|
|
+if(TARGET Luajit::Luajit)
|
|
|
+ add_custom_command(
|
|
|
+ OUTPUT swig/swigluarun.h
|
|
|
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
+ PRE_BUILD
|
|
|
+ COMMAND ${SWIG_EXECUTABLE} -lua -external-runtime swig/swigluarun.h
|
|
|
+ COMMENT "obs-scripting - generating Luajit SWIG interface headers")
|
|
|
|
|
|
-if(LUAJIT_FOUND)
|
|
|
- include_directories(${LUAJIT_INCLUDE_DIR})
|
|
|
-
|
|
|
- set(obs-scripting-lua_SOURCES
|
|
|
- obs-scripting-lua.c
|
|
|
- obs-scripting-lua-source.c
|
|
|
- )
|
|
|
- set(obs-scripting-lua_HEADERS
|
|
|
- obs-scripting-lua.h
|
|
|
- )
|
|
|
- if(UI_ENABLED)
|
|
|
- set(obs-scripting-lua_SOURCES
|
|
|
- ${obs-scripting-lua_SOURCES}
|
|
|
- obs-scripting-lua-frontend.c
|
|
|
- )
|
|
|
- endif()
|
|
|
-endif()
|
|
|
+ set_source_files_properties(swig/swigluarun.h PROPERTIES GENERATED ON)
|
|
|
|
|
|
-set(obs-scripting_SOURCES
|
|
|
- obs-scripting.c
|
|
|
- obs-scripting-logging.c
|
|
|
- cstrcache.cpp
|
|
|
- )
|
|
|
-set(obs-scripting_HEADERS
|
|
|
- ${CMAKE_CURRENT_BINARY_DIR}/obs-scripting-config.h
|
|
|
- obs-scripting.h
|
|
|
- obs-scripting-callback.h
|
|
|
- cstrcache.h
|
|
|
- )
|
|
|
-
|
|
|
-if(WIN32)
|
|
|
- set(MODULE_DESCRIPTION "OBS Studio scripting module")
|
|
|
- configure_file(${CMAKE_SOURCE_DIR}/cmake/winrc/obs-module.rc.in obs-scripting.rc)
|
|
|
- list(APPEND obs-scripting_SOURCES
|
|
|
- obs-scripting.rc)
|
|
|
-endif()
|
|
|
+ target_link_libraries(obs-scripting PRIVATE Luajit::Luajit)
|
|
|
|
|
|
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/swig)
|
|
|
+ target_sources(
|
|
|
+ obs-scripting
|
|
|
+ PRIVATE obs-scripting-lua.c obs-scripting-lua.h obs-scripting-lua-source.c
|
|
|
+ ${CMAKE_CURRENT_BINARY_DIR}/swig/swigluarun.h)
|
|
|
|
|
|
-if(PYTHONLIBS_FOUND)
|
|
|
- set(SWIG_PY_RUNTIME swig/swigpyrun.h)
|
|
|
- add_custom_command(OUTPUT ${SWIG_PY_RUNTIME}
|
|
|
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
- PRE_BUILD
|
|
|
- COMMAND ${SWIG_EXECUTABLE} -python -external-runtime ${SWIG_PY_RUNTIME}
|
|
|
- COMMENT "Scripting plugin: Building Python SWIG interface header"
|
|
|
- )
|
|
|
- set_source_files_properties(${SWIG_PY_RUNTIME} PROPERTIES GENERATED TRUE)
|
|
|
-endif()
|
|
|
+ target_include_directories(obs-scripting PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
|
-if(LUAJIT_FOUND)
|
|
|
- set(SWIG_LUA_RUNTIME swig/swigluarun.h)
|
|
|
- add_custom_command(OUTPUT ${SWIG_LUA_RUNTIME}
|
|
|
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
- PRE_BUILD
|
|
|
- COMMAND ${SWIG_EXECUTABLE} -lua -external-runtime ${SWIG_LUA_RUNTIME}
|
|
|
- COMMENT "Scripting: Building Lua SWIG interface header"
|
|
|
- )
|
|
|
- set_source_files_properties(${SWIG_LUA_RUNTIME} PROPERTIES GENERATED TRUE)
|
|
|
-endif()
|
|
|
+ if(ENABLE_UI)
|
|
|
+ target_link_libraries(obs-scripting PRIVATE OBS::frontend-api)
|
|
|
+
|
|
|
+ target_sources(obs-scripting PRIVATE obs-scripting-lua-frontend.c)
|
|
|
+
|
|
|
+ target_compile_definitions(obs-scripting PRIVATE UI_ENABLED=ON)
|
|
|
+ endif()
|
|
|
|
|
|
-add_library(obs-scripting SHARED
|
|
|
- ${obs-scripting_SOURCES}
|
|
|
- ${obs-scripting_HEADERS}
|
|
|
- ${obs-scripting-python_SOURCES}
|
|
|
- ${obs-scripting-python_HEADERS}
|
|
|
- ${obs-scripting-lua_SOURCES}
|
|
|
- ${obs-scripting-lua_HEADERS}
|
|
|
- ${SWIG_PY_RUNTIME}
|
|
|
- ${SWIG_LUA_RUNTIME}
|
|
|
- )
|
|
|
-
|
|
|
-target_link_libraries(obs-scripting
|
|
|
- libobs
|
|
|
- ${LUAJIT_LIBRARIES}
|
|
|
- ${EXTRA_LIBS}
|
|
|
- ${obs-scripting_PLATFORM_DEPS}
|
|
|
- )
|
|
|
-
|
|
|
-set_target_properties(obs-scripting PROPERTIES FOLDER "scripting")
|
|
|
-
|
|
|
-if(PYTHONLIBS_FOUND)
|
|
|
- add_subdirectory(obspython)
|
|
|
endif()
|
|
|
|
|
|
-if(LUAJIT_FOUND)
|
|
|
- add_subdirectory(obslua)
|
|
|
+if(TARGET Python::Python)
|
|
|
+ add_custom_command(
|
|
|
+ OUTPUT swig/swigpyrun.h
|
|
|
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
+ PRE_BUILD
|
|
|
+ COMMAND ${SWIG_EXECUTABLE} -python -external-runtime swig/swigpyrun.h
|
|
|
+ COMMENT "obs-scripting - generating Python 3 SWIG interface headers")
|
|
|
+
|
|
|
+ set_source_files_properties(swig/swigpyrun.h PROPERTIES GENERATED ON)
|
|
|
+
|
|
|
+ target_sources(
|
|
|
+ obs-scripting
|
|
|
+ PRIVATE obs-scripting-python.c obs-scripting-python.h
|
|
|
+ obs-scripting-python-import.h
|
|
|
+ ${CMAKE_CURRENT_BINARY_DIR}/swig/swigpyrun.h)
|
|
|
+
|
|
|
+ target_include_directories(obs-scripting PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
+
|
|
|
+ get_filename_component(_PYTHON_PATH "${Python_LIBRARIES}" PATH)
|
|
|
+ get_filename_component(_PYTHON_FILE "${Python_LIBRARIES}" NAME)
|
|
|
+
|
|
|
+ string(REGEX REPLACE "\\.[^.]*$" "" _PYTHON_FILE ${_PYTHON_FILE})
|
|
|
+
|
|
|
+ if(OS_WINDOWS)
|
|
|
+ string(REGEX REPLACE "_d" "" _PYTHON_FILE ${_PYTHON_FILE})
|
|
|
+ endif()
|
|
|
+ set(OBS_SCRIPT_PYTHON_PATH "${_PYTHON_FILE}")
|
|
|
+
|
|
|
+ unset(_PYTHON_FILE)
|
|
|
+ unset(_PYTHON_PATH)
|
|
|
+
|
|
|
+ if(OS_WINDOWS OR OS_MACOS)
|
|
|
+ target_include_directories(obs-scripting PRIVATE ${Python_INCLUDE_DIRS})
|
|
|
+
|
|
|
+ target_sources(obs-scripting PRIVATE obs-scripting-python-import.c)
|
|
|
+ if(OS_MACOS)
|
|
|
+ target_link_options(obs-scripting PRIVATE -undefined dynamic_lookup)
|
|
|
+ endif()
|
|
|
+ else()
|
|
|
+ target_link_libraries(obs-scripting PRIVATE Python::Python)
|
|
|
+ endif()
|
|
|
+
|
|
|
+ if(ENABLE_UI)
|
|
|
+ target_link_libraries(obs-scripting PRIVATE OBS::frontend-api)
|
|
|
+
|
|
|
+ target_sources(obs-scripting PRIVATE obs-scripting-python-frontend.c)
|
|
|
+
|
|
|
+ target_compile_definitions(obs-scripting PRIVATE UI_ENABLED=ON)
|
|
|
+ endif()
|
|
|
endif()
|
|
|
|
|
|
-install_obs_core(obs-scripting)
|
|
|
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/obs-scripting-config.h.in
|
|
|
+ ${CMAKE_BINARY_DIR}/config/obs-scripting-config.h)
|
|
|
+
|
|
|
+target_sources(obs-scripting
|
|
|
+ PUBLIC ${CMAKE_BINARY_DIR}/config/obs-scripting-config.h)
|
|
|
+
|
|
|
+setup_binary_target(obs-scripting)
|