Browse Source

cmake: Add architecture support to add_obs_plugin

Also add formatting support to the function
tytan652 1 year ago
parent
commit
8480660bf8
3 changed files with 44 additions and 6 deletions
  1. 8 0
      .cmake-format.json
  2. 24 3
      cmake/common/helpers_common.cmake
  3. 12 3
      plugins/CMakeLists.txt

+ 8 - 0
.cmake-format.json

@@ -41,6 +41,14 @@
           }
           }
         }
         }
       }
       }
+    },
+    "add_obs_plugin": {
+      "pargs": 1,
+      "flags": ["WITH_MESSAGE"],
+      "kwargs": {
+        "PLATFORMS": "+",
+        "ARCHITECTURES": "+"
+      }
     }
     }
   }
   }
 }
 }

+ 24 - 3
cmake/common/helpers_common.cmake

@@ -470,16 +470,19 @@ macro(legacy_check)
   endif()
   endif()
 endmacro()
 endmacro()
 
 
-# add_obs_plugin: Add plugin subdirectory if host platform is in specified list of supported platforms
+# add_obs_plugin: Add plugin subdirectory if host platform is in specified list of supported platforms and architectures
 function(add_obs_plugin target)
 function(add_obs_plugin target)
   set(options WITH_MESSAGE)
   set(options WITH_MESSAGE)
   set(oneValueArgs "")
   set(oneValueArgs "")
-  set(multiValueArgs PLATFORMS)
+  set(multiValueArgs PLATFORMS ARCHITECTURES)
   cmake_parse_arguments(PARSE_ARGV 0 _AOP "${options}" "${oneValueArgs}" "${multiValueArgs}")
   cmake_parse_arguments(PARSE_ARGV 0 _AOP "${options}" "${oneValueArgs}" "${multiValueArgs}")
 
 
   set(found_platform FALSE)
   set(found_platform FALSE)
   list(LENGTH _AOP_PLATFORMS _AOP_NUM_PLATFORMS)
   list(LENGTH _AOP_PLATFORMS _AOP_NUM_PLATFORMS)
 
 
+  set(found_architecture FALSE)
+  list(LENGTH _AOP_ARCHITECTURES _AOP_NUM_ARCHITECTURES)
+
   if(_AOP_NUM_PLATFORMS EQUAL 0)
   if(_AOP_NUM_PLATFORMS EQUAL 0)
     set(found_platform TRUE)
     set(found_platform TRUE)
   else()
   else()
@@ -492,7 +495,25 @@ function(add_obs_plugin target)
     endforeach()
     endforeach()
   endif()
   endif()
 
 
-  if(found_platform)
+  if(_AOP_NUM_ARCHITECTURES EQUAL 0)
+    set(found_architecture TRUE)
+  else()
+    foreach(architecture IN LISTS _AOP_ARCHITECTURES)
+      if(OS_WINDOWS)
+        if("${architecture}" STREQUAL CMAKE_GENERATOR_PLATFORM)
+          set(found_architecture TRUE)
+        endif()
+      elseif(OS_MACOS)
+        if("${architecture}" IN_LIST CMAKE_OSX_ARCHITECTURES)
+          set(found_architecture TRUE)
+        endif()
+      elseif("${architecture}" STREQUAL CMAKE_SYSTEM_PROCESSOR)
+        set(found_architecture TRUE)
+      endif()
+    endforeach()
+  endif()
+
+  if(found_platform AND found_architecture)
     add_subdirectory(${target})
     add_subdirectory(${target})
   elseif(_AOP_WITH_MESSAGE)
   elseif(_AOP_WITH_MESSAGE)
     add_custom_target(${target} COMMENT "Dummy target for unavailable module ${target}")
     add_custom_target(${target} COMMENT "Dummy target for unavailable module ${target}")

+ 12 - 3
plugins/CMakeLists.txt

@@ -34,9 +34,15 @@ if(OBS_CMAKE_VERSION VERSION_GREATER_EQUAL 3.0.0)
   endmacro()
   endmacro()
 
 
   # Add plugins in alphabetical order to retain order in IDE projects
   # Add plugins in alphabetical order to retain order in IDE projects
-  add_obs_plugin(aja PLATFORMS WINDOWS MACOS LINUX WITH_MESSAGE)
+  add_obs_plugin(
+    aja
+    PLATFORMS WINDOWS MACOS LINUX
+    WITH_MESSAGE)
   add_obs_plugin(coreaudio-encoder PLATFORMS WINDOWS MACOS)
   add_obs_plugin(coreaudio-encoder PLATFORMS WINDOWS MACOS)
-  add_obs_plugin(decklink PLATFORMS WINDOWS MACOS LINUX WITH_MESSAGE)
+  add_obs_plugin(
+    decklink
+    PLATFORMS WINDOWS MACOS LINUX
+    WITH_MESSAGE)
   add_obs_plugin(image-source)
   add_obs_plugin(image-source)
   add_obs_plugin(linux-alsa PLATFORMS LINUX FREEBSD OPENBSD)
   add_obs_plugin(linux-alsa PLATFORMS LINUX FREEBSD OPENBSD)
   add_obs_plugin(linux-capture PLATFORMS LINUX FREEBSD OPENBSD)
   add_obs_plugin(linux-capture PLATFORMS LINUX FREEBSD OPENBSD)
@@ -59,7 +65,10 @@ if(OBS_CMAKE_VERSION VERSION_GREATER_EQUAL 3.0.0)
   add_obs_plugin(obs-qsv11 PLATFORMS WINDOWS LINUX)
   add_obs_plugin(obs-qsv11 PLATFORMS WINDOWS LINUX)
   add_obs_plugin(obs-text PLATFORMS WINDOWS)
   add_obs_plugin(obs-text PLATFORMS WINDOWS)
   add_obs_plugin(obs-transitions)
   add_obs_plugin(obs-transitions)
-  add_obs_plugin(obs-vst PLATFORMS WINDOWS MACOS LINUX WITH_MESSAGE)
+  add_obs_plugin(
+    obs-vst
+    PLATFORMS WINDOWS MACOS LINUX
+    WITH_MESSAGE)
   add_obs_plugin(obs-webrtc)
   add_obs_plugin(obs-webrtc)
 
 
   check_obs_websocket()
   check_obs_websocket()