cmake_minimum_required(VERSION 3.22...3.25) legacy_check() if(POLICY CMP0078) cmake_policy(SET CMP0078 NEW) endif() if(POLICY CMP0086) cmake_policy(SET CMP0086 NEW) endif() if(POLICY CMP0094) cmake_policy(SET CMP0094 NEW) endif() find_package(Python 3.8...<3.12 REQUIRED Interpreter Development) find_package(SWIG 4 REQUIRED) include(UseSWIG) set_source_files_properties(obspython.i PROPERTIES USE_TARGET_INCLUDE_DIRECTORIES TRUE SWIG_FLAGS $<$:-py3-stable-abi>) swig_add_library( obspython LANGUAGE python TYPE MODULE SOURCES obspython.i) add_library(OBS::python ALIAS obspython) file( GENERATE OUTPUT $<$:$/>obspython.h CONTENT "#pragma once\n\n#define PYTHON_LIB \"$\"\n") target_include_directories( obspython PRIVATE "$<$:${CMAKE_CURRENT_BINARY_DIR}/$>" "$<$:$>") target_compile_options( obspython PRIVATE $<$:/wd4100> $<$:/wd4197> $<$:-Wno-unused-parameter> $<$:-Wno-macro-redefined> $<$:-Wno-unreachable-code>) target_compile_definitions(obspython PRIVATE SWIG_TYPE_TABLE=obspython Py_ENABLE_SHARED=1 SWIG_PYTHON_INTERPRETER_NO_DEBUG $<$:ENABLE_UI>) target_link_libraries( obspython PRIVATE OBS::cstrcache OBS::libobs OBS::scripting $<$:OBS::frontend-api> $<$>:Python::Python>) target_link_options(obspython PRIVATE $<$:LINKER:-undefined,dynamic_lookup>) if(MSVC OR XCODE) add_custom_command( TARGET obspython POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_BINARY_DIR}/obspython.py" "${CMAKE_CURRENT_BINARY_DIR}/$/obspython.py" VERBATIM) endif() set_property( TARGET obspython APPEND PROPERTY SWIG_COMPILE_DEFINITIONS "SWIG_TYPE_TABLE=obspython" "Py_ENABLE_SHARED=1" "SWIG_PYTHON_INTERPRETER_NO_DEBUG" "$<$:ENABLE_UI>" "$<$:MS_NO_COREDLL>") # cmake-format: off set_target_properties_obs(obspython PROPERTIES FOLDER scripting PREFIX "_" XCODE_ATTRIBUTE_STRIP_STYLE non-global) # cmake-format: on