obs-scripting: Update CMakeLists.txt for scripting modules

master
PatTheMav 2022-02-14 18:46:40 +01:00
parent dba1041034
commit dbdf5c7f7a
No known key found for this signature in database
GPG Key ID: CEFD5D83C12A66B3
9 changed files with 379 additions and 387 deletions

View File

@ -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)
endif()
if(ENABLE_SCRIPTING_LUA)
add_subdirectory(obslua)
find_package(Luajit)
if(MSVC)
set(obs-scripting_PLATFORM_DEPS
w32-pthreads)
endif()
if(APPLE)
set(obs-scripting_PLATFORM_DEPS
objc)
endif()
option(DISABLE_LUA "Disable Lua scripting support" OFF)
option(DISABLE_PYTHON "Disable Python scripting support" OFF)
set(COMPILE_PYTHON FALSE CACHE BOOL "" FORCE)
set(COMPILE_LUA FALSE CACHE BOOL "" FORCE)
if(NOT DISABLE_LUA)
find_package(Luajit QUIET)
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()
if(NOT TARGET Luajit::Luajit)
message(FATAL_ERROR "OBS: - Luajit not found")
return()
else()
message(STATUS "OBS: - Luajit found")
endif()
else()
message(STATUS "Scripting: Luajit support disabled")
set(LUAJIT_FOUND FALSE)
message(STATUS "OBS: DISABLED Luajit support")
endif()
if(NOT DISABLE_PYTHON)
find_package(PythonDeps QUIET)
if(ENABLE_SCRIPTING_PYTHON)
add_subdirectory(obspython)
if(OS_WINDOWS)
find_package(PythonWindows)
else()
find_package(Python COMPONENTS Interpreter Development)
endif()
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()
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 "Scripting: Python 3 support disabled")
set(PYTHON_FOUND FALSE)
set(PYTHONLIBS_FOUND FALSE)
message(STATUS "OBS: DISABLED Python support")
endif()
find_package(SwigDeps QUIET 2)
if(NOT SWIG_FOUND)
message(STATUS "Scripting: SWIG not found; scripting disabled")
return()
if(NOT TARGET Luajit::Luajit AND NOT TARGET Python::Python)
message(
WARNING
"OBS: DISABLED obs-scripting - no supported scripting libraries found")
return()
endif()
if(NOT PYTHONLIBS_FOUND AND NOT LUAJIT_FOUND)
message(STATUS "Scripting: Neither Python 3 nor Luajit was found; scripting plugin disabled")
return()
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()
set(SCRIPTING_ENABLED ON CACHE BOOL "Internal global cmake variable" FORCE)
add_library(obs-scripting SHARED)
add_library(OBS::scripting ALIAS obs-scripting)
if(UI_ENABLED)
set(EXTRA_LIBS obs-frontend-api)
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/UI/obs-frontend-api")
target_sources(
obs-scripting
PUBLIC obs-scripting.h
PRIVATE obs-scripting.c cstrcache.cpp cstrcache.h obs-scripting-logging.c
obs-scripting-callback.h)
target_link_libraries(obs-scripting PRIVATE OBS::libobs)
target_compile_features(obs-scripting PRIVATE cxx_auto_type)
target_include_directories(obs-scripting PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/config)
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)
target_sources(obs-scripting PRIVATE obs-scripting.rc)
target_link_libraries(obs-scripting PRIVATE OBS::w32-pthreads)
elseif(OS_MACOS)
target_link_libraries(obs-scripting PRIVATE objc)
endif()
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(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(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()
set_target_properties(
obs-scripting
PROPERTIES FOLDER "scripting"
VERSION "${OBS_VERSION_MAJOR}"
SOVERSION "1")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/swig)
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)
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")
set_source_files_properties(swig/swigluarun.h PROPERTIES GENERATED ON)
target_link_libraries(obs-scripting PRIVATE Luajit::Luajit)
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)
target_include_directories(obs-scripting PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
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()
endif()
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)
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()
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}
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/obs-scripting-config.h.in
${CMAKE_BINARY_DIR}/config/obs-scripting-config.h)
target_link_libraries(obs-scripting
libobs
${LUAJIT_LIBRARIES}
${EXTRA_LIBS}
${obs-scripting_PLATFORM_DEPS}
)
target_sources(obs-scripting
PUBLIC ${CMAKE_BINARY_DIR}/config/obs-scripting-config.h)
set_target_properties(obs-scripting PROPERTIES FOLDER "scripting")
if(PYTHONLIBS_FOUND)
add_subdirectory(obspython)
endif()
if(LUAJIT_FOUND)
add_subdirectory(obslua)
endif()
install_obs_core(obs-scripting)
setup_binary_target(obs-scripting)

View File

@ -16,8 +16,10 @@
#define OFF 0
#endif
#cmakedefine LUAJIT_FOUND
#cmakedefine Python_FOUND
#define SCRIPT_DIR "@OBS_SCRIPT_PLUGIN_PATH@"
#define PYTHON_LIB "@PYTHON_LIB@"
#define COMPILE_LUA @LUAJIT_FOUND@
#define COMPILE_PYTHON @PYTHON_FOUND@
#define UI_ENABLED @UI_ENABLED@
#define PYTHON_LIB "@OBS_SCRIPT_PYTHON_PATH@"
#define UI_ENABLED @ENABLE_UI@

View File

@ -32,19 +32,21 @@
#endif
#ifdef __APPLE__
#define SO_EXT "dylib"
#define SO_EXT "so"
#elif _WIN32
#include <windows.h>
#define SO_EXT "dll"
#else
#define SO_EXT "so"
#endif
static const char *startup_script_template = "\
static const char *startup_script_template =
"\
for val in pairs(package.preload) do\n\
package.preload[val] = nil\n\
end\n\
package.cpath = package.cpath .. \";\" .. \"%s/Contents/MacOS/?.so\" .. \";\" .. \"%s\" .. \"/?." SO_EXT
"\"\n\
package.cpath = package.cpath .. \";\" .. \"%s/?." SO_EXT
"\" .. \";\" .. \"%s\" .. \"/?." SO_EXT "\"\n\
require \"obslua\"\n";
static const char *get_script_path_func = "\
@ -1312,7 +1314,6 @@ void obs_lua_script_save(obs_script_t *s)
void obs_lua_load(void)
{
struct dstr dep_paths = {0};
struct dstr tmp = {0};
pthread_mutex_init(&tick_mutex, NULL);
@ -1322,34 +1323,29 @@ void obs_lua_load(void)
/* ---------------------------------------------- */
/* Initialize Lua startup script */
char *bundlePath = "./";
#ifdef __APPLE__
Class nsRunningApplication = objc_lookUpClass("NSRunningApplication");
SEL currentAppSel = sel_getUid("currentApplication");
typedef id (*running_app_func)(Class, SEL);
running_app_func operatingSystemName = (running_app_func)objc_msgSend;
id app = operatingSystemName(nsRunningApplication, currentAppSel);
typedef id (*bundle_url_func)(id, SEL);
bundle_url_func bundleURL = (bundle_url_func)objc_msgSend;
id url = bundleURL(app, sel_getUid("bundleURL"));
typedef id (*url_path_func)(id, SEL);
url_path_func urlPath = (url_path_func)objc_msgSend;
id path = urlPath(url, sel_getUid("path"));
typedef id (*string_func)(id, SEL);
string_func utf8String = (string_func)objc_msgSend;
bundlePath = (char *)utf8String(path, sel_registerName("UTF8String"));
#if _WIN32
#define PATH_MAX MAX_PATH
#endif
dstr_printf(&tmp, startup_script_template, bundlePath, SCRIPT_DIR);
startup_script = tmp.array;
char import_path[PATH_MAX];
dstr_free(&dep_paths);
#ifdef __APPLE__
struct dstr bundle_path;
dstr_init_move_array(&bundle_path, os_get_executable_path_ptr(""));
dstr_cat(&bundle_path, "../PlugIns");
char *absolute_plugin_path = os_get_abs_path_ptr(bundle_path.array);
if(absolute_plugin_path != NULL) {
strcpy(import_path, absolute_plugin_path);
bfree(absolute_plugin_path);
}
dstr_free(&bundle_path);
#else
strcpy(import_path, "./");
#endif
dstr_printf(&tmp, startup_script_template, import_path, SCRIPT_DIR);
startup_script = tmp.array;
obs_add_tick_callback(lua_tick, NULL);
}

View File

@ -1671,17 +1671,24 @@ bool obs_scripting_load_python(const char *python_path)
/* ---------------------------------------------- */
/* Load main interface module */
#ifdef __APPLE__
struct dstr bundle_path;
dstr_init_move_array(&bundle_path, os_get_executable_path_ptr(""));
dstr_cat(&bundle_path, "../PlugIns");
char *absolute_plugin_path = os_get_abs_path_ptr(bundle_path.array);
if(absolute_plugin_path != NULL) {
add_to_python_path(absolute_plugin_path);
bfree(absolute_plugin_path);
}
dstr_free(&bundle_path);
#endif
char *absolute_script_path = os_get_abs_path_ptr(SCRIPT_DIR);
add_to_python_path(absolute_script_path);
bfree(absolute_script_path);
#if __APPLE__
char *exec_path = os_get_executable_path_ptr("");
if (exec_path)
add_to_python_path(exec_path);
bfree(exec_path);
#endif
py_obspython = PyImport_ImportModule("obspython");
bool success = !py_error();
if (!success) {

View File

@ -25,7 +25,7 @@
#include "obs-scripting-callback.h"
#include "obs-scripting-config.h"
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
extern obs_script_t *obs_lua_script_create(const char *path,
obs_data_t *settings);
extern bool obs_lua_script_load(obs_script_t *s);
@ -39,7 +39,7 @@ extern void obs_lua_script_update(obs_script_t *script, obs_data_t *settings);
extern void obs_lua_script_save(obs_script_t *script);
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
extern obs_script_t *obs_python_script_create(const char *path,
obs_data_t *settings);
extern bool obs_python_script_load(obs_script_t *s);
@ -61,10 +61,10 @@ static struct dstr file_filter = {0};
static bool scripting_loaded = false;
static const char *supported_formats[] = {
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
"lua",
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
"py",
#endif
NULL};
@ -144,13 +144,15 @@ bool obs_scripting_load(void)
return false;
}
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
obs_lua_load();
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
obs_python_load();
#ifndef _WIN32 /* don't risk python startup load issues on windows */
#if !defined(_WIN32) && \
!defined( \
__APPLE__) /* Win32 and macOS need user-provided Python library paths */
obs_scripting_load_python(NULL);
#endif
#endif
@ -166,11 +168,11 @@ void obs_scripting_unload(void)
/* ---------------------- */
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
obs_lua_unload();
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
obs_python_unload();
#endif
@ -249,12 +251,12 @@ obs_script_t *obs_script_create(const char *path, obs_data_t *settings)
if (!ext)
return NULL;
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
if (strcmp(ext, ".lua") == 0) {
script = obs_lua_script_create(path, settings);
} else
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
if (strcmp(ext, ".py") == 0) {
script = obs_python_script_create(path, settings);
} else
@ -306,13 +308,13 @@ obs_properties_t *obs_script_get_properties(obs_script_t *script)
if (!ptr_valid(script))
return NULL;
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
if (script->type == OBS_SCRIPT_LANG_LUA) {
props = obs_lua_script_get_properties(script);
goto out;
}
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
if (script->type == OBS_SCRIPT_LANG_PYTHON) {
props = obs_python_script_get_properties(script);
goto out;
@ -332,13 +334,13 @@ obs_data_t *obs_script_save(obs_script_t *script)
if (!ptr_valid(script))
return NULL;
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
if (script->type == OBS_SCRIPT_LANG_LUA) {
obs_lua_script_save(script);
goto out;
}
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
if (script->type == OBS_SCRIPT_LANG_PYTHON) {
obs_python_script_save(script);
goto out;
@ -373,12 +375,12 @@ void obs_script_update(obs_script_t *script, obs_data_t *settings)
{
if (!ptr_valid(script))
return;
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
if (script->type == OBS_SCRIPT_LANG_LUA) {
obs_lua_script_update(script, settings);
}
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
if (script->type == OBS_SCRIPT_LANG_PYTHON) {
obs_python_script_update(script, settings);
}
@ -392,7 +394,7 @@ bool obs_script_reload(obs_script_t *script)
if (!ptr_valid(script))
return false;
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
if (script->type == OBS_SCRIPT_LANG_LUA) {
obs_lua_script_unload(script);
clear_call_queue();
@ -400,7 +402,7 @@ bool obs_script_reload(obs_script_t *script)
goto out;
}
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
if (script->type == OBS_SCRIPT_LANG_PYTHON) {
obs_python_script_unload(script);
clear_call_queue();
@ -423,14 +425,14 @@ void obs_script_destroy(obs_script_t *script)
if (!script)
return;
#if COMPILE_LUA
#if defined(LUAJIT_FOUND)
if (script->type == OBS_SCRIPT_LANG_LUA) {
obs_lua_script_unload(script);
obs_lua_script_destroy(script);
return;
}
#endif
#if COMPILE_PYTHON
#if defined(Python_FOUND)
if (script->type == OBS_SCRIPT_LANG_PYTHON) {
obs_python_script_unload(script);
obs_python_script_destroy(script);
@ -439,7 +441,7 @@ void obs_script_destroy(obs_script_t *script)
#endif
}
#if !COMPILE_PYTHON
#if !defined(Python_FOUND)
bool obs_scripting_load_python(const char *python_path)
{
UNUSED_PARAMETER(python_path);

View File

@ -1,62 +1,61 @@
cmake_minimum_required(VERSION 2.8.12)
project(obslua)
if(POLICY CMP0086)
cmake_policy(SET CMP0086 NEW)
endif()
if(POLICY CMP0078)
# UseSWIG generates standard target names.
cmake_policy(SET CMP0078 OLD)
endif()
if(POLICY CMP0086)
# UseSWIG honors SWIG_MODULE_NAME via -module flag.
cmake_policy(SET CMP0086 OLD)
cmake_policy(SET CMP0078 NEW)
endif()
find_package(SWIG 2 REQUIRED)
include(${SWIG_USE_FILE})
project(obslua)
add_definitions(-DSWIG_TYPE_TABLE=obslua -DSWIG_LUA_INTERPRETER_NO_DEBUG)
find_package(Luajit REQUIRED)
if(MSVC)
add_compile_options("/wd4054")
add_compile_options("/wd4197")
add_compile_options("/wd4244")
add_compile_options("/wd4267")
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()
include(UseSWIG)
set_source_files_properties(obslua.i PROPERTIES USE_TARGET_INCLUDE_DIRECTORIES
TRUE)
swig_add_library(
obslua
LANGUAGE lua
TYPE MODULE
SOURCES obslua.i ../cstrcache.cpp ../cstrcache.h)
target_link_libraries(obslua PRIVATE OBS::scripting OBS::libobs Luajit::Luajit)
set_target_properties(
obslua PROPERTIES SWIG_COMPILE_DEFINITIONS
"SWIG_TYPE_TABLE=obslua;SWIG_LUA_INTERPRETER_NO_DEBUG")
set_target_properties(
obslua
PROPERTIES FOLDER "scripting"
VERSION "${OBS_VERSION_MAJOR}"
SOVERSION "${OBS_VERSION_CANONICAL}")
target_compile_definitions(obslua PRIVATE SWIG_TYPE_TABLE=obslua
SWIG_LUA_INTERPRETER_NO_DEBUG)
if(ENABLE_UI)
target_link_libraries(obslua PRIVATE OBS::frontend-api)
target_compile_definitions(obslua PRIVATE ENABLE_UI)
endif()
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs")
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if(CMAKE_VERSION VERSION_GREATER 3.7.2)
SWIG_ADD_LIBRARY(obslua
LANGUAGE lua
TYPE MODULE
SOURCES obslua.i ../cstrcache.cpp ../cstrcache.h)
else()
SWIG_ADD_MODULE(obslua lua obslua.i ../cstrcache.cpp ../cstrcache.h)
if(OS_WINDOWS)
if(MSVC)
target_compile_options(obslua PRIVATE /wd4054 /wd4197 /wd4244 /wd4267)
endif()
elseif(OS_MACOS)
set_target_properties(obslua PROPERTIES MACHO_CURRENT_VERSION 0
MACHO_COMPATIBILITY_VERSION 0)
endif()
SWIG_LINK_LIBRARIES(obslua obs-scripting libobs ${LUA_LIBRARIES} ${EXTRA_LIBS})
set_target_properties(obslua PROPERTIES FOLDER "scripting")
function(install_plugin_bin_swig target additional_target)
if(APPLE)
set(_bit_suffix "")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_bit_suffix "64bit/")
else()
set(_bit_suffix "32bit/")
endif()
set_target_properties(${additional_target} PROPERTIES
PREFIX "")
install(TARGETS "${additional_target}"
LIBRARY DESTINATION "${OBS_SCRIPT_PLUGIN_DESTINATION}")
add_custom_command(TARGET ${additional_target} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:${additional_target}>"
"${OBS_OUTPUT_DIR}/$<CONFIGURATION>/data/obs-scripting/${_bit_suffix}$<TARGET_FILE_NAME:${additional_target}>"
VERBATIM)
endfunction()
install_plugin_bin_swig(obs-scripting obslua)
setup_script_plugin_target(obslua)

View File

@ -26,7 +26,7 @@
#include "obs-scripting-config.h"
#include <util/platform.h>
#if UI_ENABLED
#if defined(ENABLE_UI)
#include "obs-frontend-api.h"
#endif
@ -104,6 +104,6 @@ static inline void wrap_blog(int log_level, const char *message)
%include "util/base.h"
%include "util/platform.h"
#if UI_ENABLED
#if defined(ENABLE_UI)
%include "obs-frontend-api.h"
#endif

View File

@ -1,92 +1,113 @@
cmake_minimum_required(VERSION 2.8.12)
if(POLICY CMP0078)
cmake_policy(SET CMP0078 NEW)
endif()
if(POLICY CMP0086)
cmake_policy(SET CMP0086 NEW)
endif()
project(obspython)
if(POLICY CMP0078)
# UseSWIG generates standard target names.
cmake_policy(SET CMP0078 OLD)
if(OS_MACOS)
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(SWIG 4 REQUIRED)
elseif(OS_POSIX)
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(SWIG 3 REQUIRED)
elseif(OS_WINDOWS)
find_package(PythonWindows REQUIRED)
find_package(SwigWindows 3 REQUIRED)
endif()
if(POLICY CMP0086)
# UseSWIG honors SWIG_MODULE_NAME via -module flag.
cmake_policy(SET CMP0086 OLD)
include(UseSWIG)
set_source_files_properties(
obspython.i PROPERTIES USE_TARGET_INCLUDE_DIRECTORIES TRUE SWIG_FLAGS
"-builtin;-py3")
swig_add_library(
obspython
LANGUAGE python
TYPE MODULE
SOURCES obspython.i ../cstrcache.cpp ../cstrcache.h)
target_link_libraries(obspython PRIVATE OBS::scripting OBS::libobs)
set_target_properties(
obspython
PROPERTIES
SWIG_COMPILE_DEFINITIONS
"SWIG_TYPE_TABLE=obspython;Py_ENABLE_SHARED=1;SWIG_PYTHON_INTERPRETER_NO_DEBUG"
)
target_compile_features(obspython PRIVATE cxx_auto_type c_std_11)
target_compile_definitions(
obspython PRIVATE SWIG_TYPE_TABLE=obspython Py_ENABLE_SHARED=1
SWIG_PYTHON_INTERPRETER_NO_DEBUG)
if(ENABLE_UI)
target_link_libraries(obspython PRIVATE OBS::frontend-api)
target_compile_definitions(obspython PRIVATE ENABLE_UI)
endif()
find_package(SWIG 2 REQUIRED)
include(${SWIG_USE_FILE})
if(OS_WINDOWS)
set_target_properties(
obspython
PROPERTIES
SWIG_COMPILE_DEFINITIONS
"SWIG_TYPE_TABLE=obspython;Py_ENABLE_SHARED=1;SWIG_PYTHON_INTERPRETER_NO_DEBUG;MS_NO_COREDLL"
)
add_definitions(-DSWIG_TYPE_TABLE=obspython -DMS_NO_COREDLL -DPy_ENABLE_SHARED=1 -DSWIG_PYTHON_INTERPRETER_NO_DEBUG)
target_link_libraries(obspython PRIVATE Python::Python)
target_compile_options(obspython PRIVATE /wd4100)
if(MSVC)
add_custom_command(
TARGET obspython
POST_BUILD
COMMAND
"${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_BINARY_DIR}/obspython.py"
"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/obspython.py"
VERBATIM)
endif()
elseif(OS_MACOS)
get_target_property(_PYTHON_INCLUDE_DIRECTORY Python::Python
INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(obspython PRIVATE ${_PYTHON_INCLUDE_DIRECTORY})
target_link_options(obspython PRIVATE -undefined dynamic_lookup)
target_compile_options(obspython PRIVATE -Wno-unused-parameter)
if(XCODE)
add_custom_command(
TARGET obspython
POST_BUILD
COMMAND
"${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_BINARY_DIR}/obspython.py"
"${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/obspython.py"
VERBATIM)
endif()
set_target_properties(obspython PROPERTIES MACHO_CURRENT_VERSION 0
MACHO_COMPATIBILITY_VERSION 0)
elseif(OS_POSIX)
target_link_libraries(obspython PRIVATE Python::Python)
target_compile_options(obspython PRIVATE -Wno-unused-parameter)
set_target_properties(obspython PROPERTIES PREFIX "")
if(MSVC)
add_compile_options("/wd4054")
add_compile_options("/wd4100")
add_compile_options("/wd4115")
add_compile_options("/wd4197")
add_compile_options("/wd4701")
endif()
include_directories(${PYTHON_INCLUDE_DIR})
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs")
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(
obspython
PROPERTIES FOLDER "scripting"
VERSION "${OBS_VERSION_MAJOR}"
SOVERSION "${OBS_VERSION_CANONICAL}")
#add_definitions( -DSWIG_TYPE_TABLE=libobs )
SET_SOURCE_FILES_PROPERTIES(obspython.i PROPERTIES SWIG_FLAGS "-modern")
SET_SOURCE_FILES_PROPERTIES(obspython.i PROPERTIES SWIG_FLAGS "-builtin")
SET_SOURCE_FILES_PROPERTIES(obspython.i PROPERTIES SWIG_FLAGS "-modernargs")
SET_SOURCE_FILES_PROPERTIES(obspython.i PROPERTIES SWIG_FLAGS "-includeall")
SET_SOURCE_FILES_PROPERTIES(obspython.i PROPERTIES SWIG_FLAGS "-importall")
SET_SOURCE_FILES_PROPERTIES(obspython.i PROPERTIES SWIG_FLAGS "-py3")
if(WIN32)
string(REGEX REPLACE "_d" "" PYTHON_LIBRARIES "${PYTHON_LIBRARIES}")
endif()
if(CMAKE_VERSION VERSION_GREATER 3.7.2)
SWIG_ADD_LIBRARY(obspython
LANGUAGE python
TYPE MODULE
SOURCES obspython.i ../cstrcache.cpp ../cstrcache.h)
else()
SWIG_ADD_MODULE(obspython python obspython.i ../cstrcache.cpp ../cstrcache.h)
endif()
IF(APPLE)
SWIG_LINK_LIBRARIES(obspython obs-scripting libobs)
ELSE()
SWIG_LINK_LIBRARIES(obspython obs-scripting libobs ${PYTHON_LIBRARIES})
ENDIF()
set_target_properties(_obspython PROPERTIES FOLDER "scripting")
function(install_plugin_bin_swig target additional_target)
if(APPLE)
set(_bit_suffix "")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_bit_suffix "64bit/")
else()
set(_bit_suffix "32bit/")
endif()
set_target_properties(${additional_target} PROPERTIES
PREFIX "")
if (APPLE)
SET_TARGET_PROPERTIES(${additional_target} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/obspython.py"
DESTINATION "${OBS_SCRIPT_PLUGIN_DESTINATION}")
install(TARGETS "${additional_target}"
LIBRARY DESTINATION "${OBS_SCRIPT_PLUGIN_DESTINATION}")
add_custom_command(TARGET ${additional_target} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"${CMAKE_CURRENT_BINARY_DIR}/obspython.py"
"${OBS_OUTPUT_DIR}/$<CONFIGURATION>/data/obs-scripting/${_bit_suffix}/obspython.py"
VERBATIM)
add_custom_command(TARGET ${additional_target} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:${additional_target}>"
"${OBS_OUTPUT_DIR}/$<CONFIGURATION>/data/obs-scripting/${_bit_suffix}$<TARGET_FILE_NAME:${additional_target}>"
VERBATIM)
endfunction()
install_plugin_bin_swig(obs-scripting _obspython)
setup_script_plugin_target(obspython)

View File

@ -26,7 +26,7 @@
#include "obs-scripting-config.h"
#include <util/platform.h>
#if UI_ENABLED
#if defined(ENABLE_UI)
#include "obs-frontend-api.h"
#endif
@ -102,7 +102,7 @@ static inline void wrap_blog(int log_level, const char *message)
%include "util/base.h"
%include "util/platform.h"
#if UI_ENABLED
#if defined(ENABLE_UI)
%include "obs-frontend-api.h"
#endif