From db8d9071b26c03f7b4c291375bfc4bdf8c1f09d8 Mon Sep 17 00:00:00 2001 From: FiniteSingularity Date: Wed, 17 Jun 2026 14:05:22 -0500 Subject: [PATCH] cmake: Add explicit target_enable function This provides the counterpart to the existing "target_disable" function, which also allows the functionality to be factored out of existing helper code that might run this implicitly. Co-authored-by: PatTheMav --- cmake/common/helpers_common.cmake | 15 +++++++++++++-- cmake/linux/helpers.cmake | 10 ++++------ cmake/macos/helpers.cmake | 1 - cmake/windows/helpers.cmake | 10 ++++------ plugins/aja-output-ui/CMakeLists.txt | 1 - plugins/aja/CMakeLists.txt | 1 - plugins/coreaudio-encoder/CMakeLists.txt | 1 - plugins/decklink-captions/CMakeLists.txt | 1 - plugins/decklink-output-ui/CMakeLists.txt | 1 - plugins/decklink/CMakeLists.txt | 1 - plugins/linux-alsa/CMakeLists.txt | 1 - plugins/linux-jack/CMakeLists.txt | 1 - plugins/linux-pipewire/CMakeLists.txt | 1 - plugins/linux-pulseaudio/CMakeLists.txt | 1 - plugins/linux-v4l2/CMakeLists.txt | 1 - plugins/mac-avcapture/CMakeLists.txt | 1 + plugins/mac-syphon/CMakeLists.txt | 1 - plugins/obs-libfdk/CMakeLists.txt | 1 - plugins/obs-nvenc/CMakeLists.txt | 1 - plugins/obs-qsv11/CMakeLists.txt | 1 - plugins/obs-vst/CMakeLists.txt | 1 - plugins/obs-webrtc/CMakeLists.txt | 1 - plugins/oss-audio/CMakeLists.txt | 1 - plugins/sndio/CMakeLists.txt | 1 - plugins/text-freetype2/CMakeLists.txt | 1 - plugins/vlc-video/CMakeLists.txt | 1 - 26 files changed, 22 insertions(+), 36 deletions(-) diff --git a/cmake/common/helpers_common.cmake b/cmake/common/helpers_common.cmake index 4ce77230a..67e7226f3 100644 --- a/cmake/common/helpers_common.cmake +++ b/cmake/common/helpers_common.cmake @@ -82,6 +82,11 @@ function(target_disable_feature target feature_description) endif() endfunction() +# target_enable: Adds target to list of enabled modules +function(target_enable target) + set_property(GLOBAL APPEND PROPERTY OBS_MODULES_ENABLED ${target}) +endfunction() + # target_disable: Adds target to list of disabled modules function(target_disable target) set_property(GLOBAL APPEND PROPERTY OBS_MODULES_DISABLED ${target}) @@ -499,8 +504,14 @@ function(add_obs_plugin target) if(found_platform AND found_architecture) add_subdirectory(${target}) - elseif(_AOP_WITH_MESSAGE) - add_custom_target(${target} COMMENT "Dummy target for unavailable module ${target}") + endif() + + if(TARGET ${target}) + target_enable(${target}) + else() + if(_AOP_WITH_MESSAGE) + add_custom_target(${target} COMMENT "Dummy target for unavailable module ${target}") + endif() target_disable(${target}) endif() endfunction() diff --git a/cmake/linux/helpers.cmake b/cmake/linux/helpers.cmake index 494586de9..a13c1a68f 100644 --- a/cmake/linux/helpers.cmake +++ b/cmake/linux/helpers.cmake @@ -213,8 +213,6 @@ function(set_target_properties_obs target) endif() endif() endif() - - set_property(GLOBAL APPEND PROPERTY OBS_MODULES_ENABLED ${target}) endif() target_install_resources(${target}) @@ -236,8 +234,8 @@ function(target_install_resources target) source_group("Resources/${relative_path}" FILES "${data_file}") endforeach() - get_property(obs_module_list GLOBAL PROPERTY OBS_MODULES_ENABLED) - if(target IN_LIST obs_module_list) + get_target_property(target_type ${target} TYPE) + if(target_type STREQUAL MODULE_LIBRARY) set(target_destination "${OBS_DATA_DESTINATION}/obs-plugins/${target}") elseif(target STREQUAL obs) set(target_destination "${OBS_DATA_DESTINATION}/obs-studio") @@ -267,10 +265,10 @@ endfunction() # Helper function to add a specific resource to a bundle function(target_add_resource target resource) - get_property(obs_module_list GLOBAL PROPERTY OBS_MODULES_ENABLED) + get_target_property(target_type ${target} TYPE) if(ARGN) set(target_destination "${ARGN}") - elseif(${target} IN_LIST obs_module_list) + elseif(target_type STREQUAL MODULE_LIBRARY) set(target_destination "${OBS_DATA_DESTINATION}/obs-plugins/${target}") elseif(target STREQUAL obs) set(target_destination "${OBS_DATA_DESTINATION}/obs-studio") diff --git a/cmake/macos/helpers.cmake b/cmake/macos/helpers.cmake index 8913b2b24..ec4c90170 100644 --- a/cmake/macos/helpers.cmake +++ b/cmake/macos/helpers.cmake @@ -303,7 +303,6 @@ function(set_target_properties_obs target) endif() endif() - set_property(GLOBAL APPEND PROPERTY OBS_MODULES_ENABLED ${target}) set_property(GLOBAL APPEND PROPERTY _OBS_DEPENDENCIES ${target}) endif() diff --git a/cmake/windows/helpers.cmake b/cmake/windows/helpers.cmake index 9a443f1cf..806023ab5 100644 --- a/cmake/windows/helpers.cmake +++ b/cmake/windows/helpers.cmake @@ -157,8 +157,6 @@ function(set_target_properties_obs target) endif() endif() endif() - - set_property(GLOBAL APPEND PROPERTY OBS_MODULES_ENABLED ${target}) endif() target_link_options(${target} PRIVATE "/PDBALTPATH:$") @@ -314,8 +312,8 @@ function(target_install_resources target) source_group("Resources/${relative_path}" FILES "${data_file}") endforeach() - get_property(obs_module_list GLOBAL PROPERTY OBS_MODULES_ENABLED) - if(target IN_LIST obs_module_list) + get_target_property(target_type ${target} TYPE) + if(target_type STREQUAL MODULE_LIBRARY) set(target_destination "${OBS_DATA_DESTINATION}/obs-plugins/${target}") elseif(target STREQUAL obs-studio) set(target_destination "${OBS_DATA_DESTINATION}/obs-studio") @@ -346,10 +344,10 @@ endfunction() # Helper function to add a specific resource to a bundle function(target_add_resource target resource) - get_property(obs_module_list GLOBAL PROPERTY OBS_MODULES_ENABLED) + get_target_property(target_type ${target} TYPE) if(ARGN) set(target_destination "${ARGN}") - elseif(${target} IN_LIST obs_module_list) + elseif(target_type STREQUAL MODULE_LIBRARY) set(target_destination "${OBS_DATA_DESTINATION}/obs-plugins/${target}") elseif(target STREQUAL obs-studio) set(target_destination "${OBS_DATA_DESTINATION}/obs-studio") diff --git a/plugins/aja-output-ui/CMakeLists.txt b/plugins/aja-output-ui/CMakeLists.txt index 003490d01..56dedbd11 100644 --- a/plugins/aja-output-ui/CMakeLists.txt +++ b/plugins/aja-output-ui/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.28...3.30) if(NOT ENABLE_AJA) - target_disable(aja-output-ui) return() endif() diff --git a/plugins/aja/CMakeLists.txt b/plugins/aja/CMakeLists.txt index 88ef18cad..6b04c1a0b 100644 --- a/plugins/aja/CMakeLists.txt +++ b/plugins/aja/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_AJA "Build OBS with aja support" ON) if(NOT ENABLE_AJA) - set_property(GLOBAL APPEND PROPERTY OBS_MODULES_DISABLED aja) return() endif() diff --git a/plugins/coreaudio-encoder/CMakeLists.txt b/plugins/coreaudio-encoder/CMakeLists.txt index 099995d89..907c55348 100644 --- a/plugins/coreaudio-encoder/CMakeLists.txt +++ b/plugins/coreaudio-encoder/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.28...3.30) if(OS_WINDOWS) option(ENABLE_COREAUDIO_ENCODER "Enable building with CoreAudio encoder (Windows)" ON) if(NOT ENABLE_COREAUDIO_ENCODER) - target_disable(coreaudio-encoder) return() endif() endif() diff --git a/plugins/decklink-captions/CMakeLists.txt b/plugins/decklink-captions/CMakeLists.txt index 53dab0da1..13ab83b73 100644 --- a/plugins/decklink-captions/CMakeLists.txt +++ b/plugins/decklink-captions/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.28...3.30) if(NOT ENABLE_DECKLINK) - target_disable(decklink-captions) return() endif() diff --git a/plugins/decklink-output-ui/CMakeLists.txt b/plugins/decklink-output-ui/CMakeLists.txt index b0cca166c..4695c8951 100644 --- a/plugins/decklink-output-ui/CMakeLists.txt +++ b/plugins/decklink-output-ui/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.28...3.30) if(NOT ENABLE_DECKLINK) - target_disable(decklink-output-ui) return() endif() diff --git a/plugins/decklink/CMakeLists.txt b/plugins/decklink/CMakeLists.txt index 18b9b6bc5..bd0840656 100644 --- a/plugins/decklink/CMakeLists.txt +++ b/plugins/decklink/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_DECKLINK "Build OBS with Decklink support" ON) if(NOT ENABLE_DECKLINK) - target_disable(decklink) return() endif() diff --git a/plugins/linux-alsa/CMakeLists.txt b/plugins/linux-alsa/CMakeLists.txt index 7e7b2f524..c8d516213 100644 --- a/plugins/linux-alsa/CMakeLists.txt +++ b/plugins/linux-alsa/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_ALSA "Build OBS with ALSA support" ON) if(NOT ENABLE_ALSA) - target_disable(linux-alsa) return() endif() diff --git a/plugins/linux-jack/CMakeLists.txt b/plugins/linux-jack/CMakeLists.txt index 4e58530a7..1a3e61f61 100644 --- a/plugins/linux-jack/CMakeLists.txt +++ b/plugins/linux-jack/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_JACK "Build OBS with JACK support" OFF) if(NOT ENABLE_JACK) - target_disable(linux-jack) return() endif() diff --git a/plugins/linux-pipewire/CMakeLists.txt b/plugins/linux-pipewire/CMakeLists.txt index e81bdfe2f..baf367df2 100644 --- a/plugins/linux-pipewire/CMakeLists.txt +++ b/plugins/linux-pipewire/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_PIPEWIRE "Enable PipeWire support" ON) if(NOT ENABLE_PIPEWIRE) - target_disable(linux-pipewire) return() endif() diff --git a/plugins/linux-pulseaudio/CMakeLists.txt b/plugins/linux-pulseaudio/CMakeLists.txt index 5ab582c16..d45cc5a07 100644 --- a/plugins/linux-pulseaudio/CMakeLists.txt +++ b/plugins/linux-pulseaudio/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.28...3.30) if(NOT ENABLE_PULSEAUDIO) - target_disable(linux-pulseaudio) return() endif() diff --git a/plugins/linux-v4l2/CMakeLists.txt b/plugins/linux-v4l2/CMakeLists.txt index aafbc0d28..43dbd2eb2 100644 --- a/plugins/linux-v4l2/CMakeLists.txt +++ b/plugins/linux-v4l2/CMakeLists.txt @@ -4,7 +4,6 @@ option(ENABLE_V4L2 "Build OBS with v4l2 support" ON) option(ENABLE_UDEV "Build linux-v4l2 with UDEV support" ON) if(NOT ENABLE_V4L2) - target_disable(linux-v4l2) return() endif() diff --git a/plugins/mac-avcapture/CMakeLists.txt b/plugins/mac-avcapture/CMakeLists.txt index 2c6fa10cb..73d7c0226 100644 --- a/plugins/mac-avcapture/CMakeLists.txt +++ b/plugins/mac-avcapture/CMakeLists.txt @@ -26,6 +26,7 @@ set_target_properties_obs( XCODE_ATTRIBUTE_CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION YES XCODE_ATTRIBUTE_GCC_WARN_SHADOW YES ) +target_enable(mac-avcapture-legacy) add_library(mac-avcapture MODULE) add_library(OBS::avcapture ALIAS mac-avcapture) diff --git a/plugins/mac-syphon/CMakeLists.txt b/plugins/mac-syphon/CMakeLists.txt index a0d486042..8d411c87b 100644 --- a/plugins/mac-syphon/CMakeLists.txt +++ b/plugins/mac-syphon/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_SYPHON "Enable Syphon sharing support" ON) if(NOT ENABLE_SYPHON) - target_disable(mac-syphon) target_disable_feature(mac-syphon "Syphon sharing support") return() else() diff --git a/plugins/obs-libfdk/CMakeLists.txt b/plugins/obs-libfdk/CMakeLists.txt index c785a08db..c0b722aa6 100644 --- a/plugins/obs-libfdk/CMakeLists.txt +++ b/plugins/obs-libfdk/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_LIBFDK "Enable FDK AAC support" OFF) if(NOT ENABLE_LIBFDK) - target_disable(obs-libfdk) return() endif() diff --git a/plugins/obs-nvenc/CMakeLists.txt b/plugins/obs-nvenc/CMakeLists.txt index 93053c1ed..1efeca522 100644 --- a/plugins/obs-nvenc/CMakeLists.txt +++ b/plugins/obs-nvenc/CMakeLists.txt @@ -6,7 +6,6 @@ mark_as_advanced(ENABLE_NVENC_FFMPEG_IDS) if(NOT ENABLE_NVENC) target_disable_feature(obs-nvenc "NVIDIA Hardware Encoder") - target_disable(obs-nvenc) return() endif() diff --git a/plugins/obs-qsv11/CMakeLists.txt b/plugins/obs-qsv11/CMakeLists.txt index 85b150f6d..9d06d4304 100644 --- a/plugins/obs-qsv11/CMakeLists.txt +++ b/plugins/obs-qsv11/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_QSV11 "Build Intel QSV11 Hardware Encoder." TRUE) if(NOT ENABLE_QSV11) target_disable_feature(obs-qsv11 "Intel QSV11 Hardware Encoder") - target_disable(obs-qsv11) return() endif() diff --git a/plugins/obs-vst/CMakeLists.txt b/plugins/obs-vst/CMakeLists.txt index 756474e32..7fcfc799f 100644 --- a/plugins/obs-vst/CMakeLists.txt +++ b/plugins/obs-vst/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_VST "Enable building OBS with VST plugin" ON) if(NOT ENABLE_VST) - target_disable(obs-vst) return() endif() diff --git a/plugins/obs-webrtc/CMakeLists.txt b/plugins/obs-webrtc/CMakeLists.txt index 6324ae712..3c0cbf721 100644 --- a/plugins/obs-webrtc/CMakeLists.txt +++ b/plugins/obs-webrtc/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_WEBRTC "Enable WebRTC Output support" ON) if(NOT ENABLE_WEBRTC) - target_disable(obs-webrtc) return() endif() diff --git a/plugins/oss-audio/CMakeLists.txt b/plugins/oss-audio/CMakeLists.txt index 5ae20e2cc..b08a2bf51 100644 --- a/plugins/oss-audio/CMakeLists.txt +++ b/plugins/oss-audio/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_OSS "Enable building with OSS audio support" ON) if(NOT ENABLE_OSS) - target_disable(oss-audio) return() endif() diff --git a/plugins/sndio/CMakeLists.txt b/plugins/sndio/CMakeLists.txt index f76e7c07e..008e54bb2 100644 --- a/plugins/sndio/CMakeLists.txt +++ b/plugins/sndio/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_SNDIO "Build OBS with sndio support" OFF) if(NOT ENABLE_SNDIO) - target_disable(sndio) return() endif() diff --git a/plugins/text-freetype2/CMakeLists.txt b/plugins/text-freetype2/CMakeLists.txt index 8643dd0b7..955cb7357 100644 --- a/plugins/text-freetype2/CMakeLists.txt +++ b/plugins/text-freetype2/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.28...3.30) option(ENABLE_FREETYPE "Enable FreeType text plugin" ON) if(NOT ENABLE_FREETYPE) - target_disable(text-freetype2) return() endif() diff --git a/plugins/vlc-video/CMakeLists.txt b/plugins/vlc-video/CMakeLists.txt index 871036c9f..0b6ecbec1 100644 --- a/plugins/vlc-video/CMakeLists.txt +++ b/plugins/vlc-video/CMakeLists.txt @@ -23,7 +23,6 @@ endmacro() option(ENABLE_VLC "Build OBS with VLC plugin support" ON) if(NOT ENABLE_VLC) - target_disable(vlc-video) return() endif()