Skip to content

Commit

Permalink
cmake: Update cross-platform build project management for Windows
Browse files Browse the repository at this point in the history
Enables creation of x64 and x86 child projects when building on ARM64
and decouples functionality from legacy_check function
  • Loading branch information
PatTheMav authored and RytoEX committed Aug 20, 2024
1 parent 5bbb5e0 commit d81fcd7
Show file tree
Hide file tree
Showing 33 changed files with 602 additions and 457 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[submodule "plugins/win-dshow/libdshowcapture"]
path = plugins/win-dshow/libdshowcapture
path = deps/libdshowcapture/src
url = https://github.com/obsproject/libdshowcapture.git
[submodule "plugins/obs-browser"]
path = plugins/obs-browser
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ if(CMAKE_HOST_SYSTEM_NAME MATCHES "(Darwin)" OR OBS_CMAKE_VERSION VERSION_GREATE

project(obs-studio VERSION ${OBS_VERSION_CANONICAL})

if(CMAKE_HOST_SYSTEM_NAME MATCHES "(Windows)" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/32bit/projects.cmake")
return()
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows/architecture.cmake")
if(NOT OBS_PARENT_ARCHITECTURE STREQUAL CMAKE_GENERATOR_PLATFORM)
return()
endif()
endif()

include(compilerconfig)
Expand Down
4 changes: 2 additions & 2 deletions build-aux/.run-format.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ invoke_formatter() {

if (( ! #source_files )) source_files=((libobs|libobs-*|UI|plugins|deps|shared)/**/*.(c|cpp|h|hpp|m|mm)(.N))

source_files=(${source_files:#*/(obs-websocket/deps|decklink/*/decklink-sdk|mac-syphon/syphon-framework|win-dshow/libdshowcapture)/*})
source_files=(${source_files:#*/(obs-websocket/deps|decklink/*/decklink-sdk|mac-syphon/syphon-framework|libdshowcapture)/*})

local -a format_args=(-style=file -fallback-style=none)
if (( _loglevel > 2 )) format_args+=(--verbose)
Expand Down Expand Up @@ -104,7 +104,7 @@ invoke_formatter() {

if (( ! #source_files )) source_files=(CMakeLists.txt (libobs|libobs-*|UI|plugins|deps|shared|cmake|test)/**/(CMakeLists.txt|*.cmake)(.N))

source_files=(${source_files:#*/(jansson|decklink/*/decklink-sdk|obs-websocket|obs-browser|win-dshow/libdshowcapture)/*})
source_files=(${source_files:#*/(jansson|decklink/*/decklink-sdk|obs-websocket|obs-browser|libdshowcapture)/*})
source_files=(${source_files:#(cmake/Modules/*|*/legacy.cmake)})

check_files() {
Expand Down
63 changes: 0 additions & 63 deletions cmake/32bit/projects.cmake

This file was deleted.

3 changes: 3 additions & 0 deletions cmake/common/buildspec_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ function(_check_dependencies)
string(JSON dependency_data GET ${buildspec} dependencies)

foreach(dependency IN LISTS dependencies_list)
if(dependency STREQUAL cef AND NOT ENABLE_BROWSER)
continue()
endif()
if(dependency STREQUAL cef AND arch STREQUAL universal)
if(CMAKE_OSX_ARCHITECTURES MATCHES ".+;.+")
continue()
Expand Down
2 changes: 1 addition & 1 deletion cmake/common/helpers_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function(_handle_generator_expression_dependency library)
if(TARGET ${gen_target})
set(${var_FOUND_VAR} "${gen_target}")
endif()
elseif(library MATCHES "\\$<.*Qt6::EntryPointPrivate>" OR library MATCHES "\\$<.*Qt6::QDarwin.+PermissionPlugin>")
elseif(library MATCHES "\\$<.*Qt6::(EntryPointPrivate|QDarwin.*PermissionPlugin)>")
set(${var_FOUND_VAR} "${var_FOUND_VAR}-SKIP")
else()
# Unknown or unimplemented generator expression found. Abort script run to either add to ignore list or implement
Expand Down
97 changes: 97 additions & 0 deletions cmake/windows/architecture.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# OBS CMake Windows Architecture Helper

include_guard(GLOBAL)

include(compilerconfig)

if(NOT DEFINED OBS_PARENT_ARCHITECTURE)
if(CMAKE_GENERATOR_PLATFORM MATCHES "(Win32|x64)")
set(OBS_PARENT_ARCHITECTURE ${CMAKE_GENERATOR_PLATFORM})
else()
message(FATAL_ERROR "Unsupported generator platform for Windows builds: ${CMAKE_GENERATOR_PLATFORM}!")
endif()
endif()

if(OBS_PARENT_ARCHITECTURE STREQUAL CMAKE_GENERATOR_PLATFORM)
if(OBS_PARENT_ARCHITECTURE STREQUAL x64)
execute_process(
COMMAND
"${CMAKE_COMMAND}" -S ${CMAKE_CURRENT_SOURCE_DIR} -B ${CMAKE_SOURCE_DIR}/build_x86 -A Win32 -G
"${CMAKE_GENERATOR}" -DCMAKE_SYSTEM_VERSION:STRING='${CMAKE_SYSTEM_VERSION}' -DOBS_CMAKE_VERSION:STRING=3.0.0
-DVIRTUALCAM_GUID:STRING=${VIRTUALCAM_GUID} -DCMAKE_MESSAGE_LOG_LEVEL:STRING=${CMAKE_MESSAGE_LOG_LEVEL}
-DENABLE_CCACHE:BOOL=${ENABLE_CCACHE} -DOBS_PARENT_ARCHITECTURE:STRING=x64
RESULT_VARIABLE _process_result
COMMAND_ERROR_IS_FATAL ANY
)
endif()
else()
# legacy_check: Stub macro for child architecture builds
macro(legacy_check)
endmacro()

# target_disable_feature: Stub macro for child architecture builds
macro(target_disable_feature)
endmacro()

# target_disable: Stub macro for child architecture builds
macro(target_disable)
endmacro()

# target_add_resource: Stub macro for child architecture builds
macro(target_add_resource)
endmacro()

# target_export: Stub macro for child architecture builds
macro(target_export)
endmacro()

# set_target_properties_obs: Stub macro for child architecture builds
macro(set_target_properties_obs)
set_target_properties(${ARGV})
endmacro()

# check_uuid: Helper function to check for valid UUID
function(check_uuid uuid_string return_value)
set(valid_uuid TRUE)
# gersemi: off
set(uuid_token_lengths 8 4 4 4 12)
# gersemi: on
set(token_num 0)

string(REPLACE "-" ";" uuid_tokens ${uuid_string})
list(LENGTH uuid_tokens uuid_num_tokens)

if(uuid_num_tokens EQUAL 5)
message(DEBUG "UUID ${uuid_string} is valid with 5 tokens.")
foreach(uuid_token IN LISTS uuid_tokens)
list(GET uuid_token_lengths ${token_num} uuid_target_length)
string(LENGTH "${uuid_token}" uuid_actual_length)
if(uuid_actual_length EQUAL uuid_target_length)
string(REGEX MATCH "[0-9a-fA-F]+" uuid_hex_match ${uuid_token})
if(NOT uuid_hex_match STREQUAL uuid_token)
set(valid_uuid FALSE)
break()
endif()
else()
set(valid_uuid FALSE)
break()
endif()
math(EXPR token_num "${token_num}+1")
endforeach()
else()
set(valid_uuid FALSE)
endif()
message(DEBUG "UUID ${uuid_string} valid: ${valid_uuid}")
set(${return_value} ${valid_uuid} PARENT_SCOPE)
endfunction()

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows/buildspec.cmake")

add_subdirectory(libobs)
add_subdirectory(plugins/win-capture/get-graphics-offsets)
add_subdirectory(plugins/win-capture/graphics-hook)
add_subdirectory(plugins/win-capture/inject-helper)
add_subdirectory(plugins/win-dshow/virtualcam-module)

return()
endif()
2 changes: 1 addition & 1 deletion cmake/windows/buildspec.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function(_check_dependencies_windows)
set(arch x86)
set(dependencies_list prebuilt)
else()
set(arch ${CMAKE_GENERATOR_PLATFORM})
string(TOLOWER "${CMAKE_GENERATOR_PLATFORM}" arch)
set(dependencies_list prebuilt qt6 cef)
endif()
set(platform windows-${arch})
Expand Down
2 changes: 1 addition & 1 deletion cmake/windows/defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL TRUE)
include(buildspec)
include(cpackconfig)

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
if(CMAKE_GENERATOR_PLATFORM STREQUAL x64)
execute_process(
COMMAND
"${CMAKE_COMMAND}" -S ${CMAKE_CURRENT_SOURCE_DIR} -B ${CMAKE_SOURCE_DIR}/build_x86 -A Win32 -G
Expand Down
33 changes: 27 additions & 6 deletions cmake/windows/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function(set_target_properties_obs target)
elseif(target STREQUAL inject-helper OR target STREQUAL get-graphics-offsets)
set(OBS_EXECUTABLE_DESTINATION "${OBS_DATA_DESTINATION}/obs-plugins/win-capture")

_target_install_obs(${target} DESTINATION ${OBS_EXECUTABLE_DESTINATION} 32BIT)
_target_install_obs(${target} DESTINATION ${OBS_EXECUTABLE_DESTINATION} x86)
endif()

_target_install_obs(${target} DESTINATION ${OBS_EXECUTABLE_DESTINATION})
Expand Down Expand Up @@ -66,11 +66,11 @@ function(set_target_properties_obs target)
target_add_resource(graphics-hook "${CMAKE_CURRENT_SOURCE_DIR}/obs-vulkan64.json" "${target_destination}")
target_add_resource(graphics-hook "${CMAKE_CURRENT_SOURCE_DIR}/obs-vulkan32.json" "${target_destination}")

_target_install_obs(${target} DESTINATION ${target_destination} 32BIT)
_target_install_obs(${target} DESTINATION ${target_destination} x86)
elseif(target STREQUAL obs-virtualcam-module)
set(target_destination "${OBS_DATA_DESTINATION}/obs-plugins/win-dshow")

_target_install_obs(${target} DESTINATION ${target_destination} 32BIT)
_target_install_obs(${target} DESTINATION ${target_destination} x86)
else()
set(target_destination "${OBS_PLUGIN_DESTINATION}")
endif()
Expand Down Expand Up @@ -171,12 +171,12 @@ endfunction()

# _target_install_obs: Helper function to install build artifacts to rundir and install location
function(_target_install_obs target)
set(options "32BIT")
set(options "x86" "x64")
set(oneValueArgs "DESTINATION" "LIBRARY_DESTINATION" "HEADER_DESTINATION")
set(multiValueArgs "")
cmake_parse_arguments(PARSE_ARGV 0 _TIO "${options}" "${oneValueArgs}" "${multiValueArgs}")

if(_TIO_32BIT)
if(_TIO_x86)
get_target_property(target_type ${target} TYPE)
if(target_type STREQUAL EXECUTABLE)
set(suffix exe)
Expand All @@ -189,14 +189,35 @@ function(_target_install_obs target)
set(32bit_project_path "${OBS_SOURCE_DIR}/build_x86/${project_path}")
set(target_file "${32bit_project_path}/$<CONFIG>/${target}32.${suffix}")
set(target_pdb_file "${32bit_project_path}/$<CONFIG>/${target}32.pdb")
set(comment "Copy ${target} (32-bit) to destination")
set(comment "Copy ${target} (x86) to destination")

install(
FILES "${32bit_project_path}/$<CONFIG>/${target}32.${suffix}"
DESTINATION "${_TIO_DESTINATION}"
COMPONENT Runtime
OPTIONAL
)
elseif(_TIO_x64)
get_target_property(target_type ${target} TYPE)
if(target_type STREQUAL EXECUTABLE)
set(suffix exe)
else()
set(suffix dll)
endif()

cmake_path(RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR BASE_DIRECTORY "${OBS_SOURCE_DIR}" OUTPUT_VARIABLE project_path)

set(32bit_project_path "${OBS_SOURCE_DIR}/build_x64/${project_path}")
set(target_file "${32bit_project_path}/$<CONFIG>/${target}64.${suffix}")
set(target_pdb_file "${32bit_project_path}/$<CONFIG>/${target}64.pdb")
set(comment "Copy ${target} (x64) to destination")

install(
FILES "${32bit_project_path}/$<CONFIG>/${target}64.${suffix}"
DESTINATION "${_TIO_DESTINATION}"
COMPONENT Runtime
OPTIONAL
)
else()
set(target_file "$<TARGET_FILE:${target}>")
set(target_pdb_file "$<TARGET_PDB_FILE:${target}>")
Expand Down
43 changes: 43 additions & 0 deletions deps/libdshowcapture/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
add_library(libdshowcapture INTERFACE)
add_library(OBS::libdshowcapture ALIAS libdshowcapture)

target_sources(
libdshowcapture
INTERFACE src/dshowcapture.hpp
src/source/capture-filter.cpp
src/source/capture-filter.hpp
src/source/device-vendor.cpp
src/source/device.cpp
src/source/device.hpp
src/source/dshow-base.cpp
src/source/dshow-base.hpp
src/source/dshow-demux.cpp
src/source/dshow-demux.hpp
src/source/dshow-device-defs.hpp
src/source/dshow-encoded-device.cpp
src/source/dshow-enum.cpp
src/source/dshow-enum.hpp
src/source/dshow-formats.cpp
src/source/dshow-formats.hpp
src/source/dshow-media-type.cpp
src/source/dshow-media-type.hpp
src/source/dshowcapture.cpp
src/source/dshowencode.cpp
src/source/encoder.cpp
src/source/encoder.hpp
src/source/external/IVideoCaptureFilter.h
src/source/log.cpp
src/source/log.hpp
src/source/output-filter.cpp
src/source/output-filter.hpp
src/external/capture-device-support/Library/EGAVResult.cpp
src/external/capture-device-support/Library/ElgatoUVCDevice.cpp
src/external/capture-device-support/Library/win/EGAVHIDImplementation.cpp
src/external/capture-device-support/SampleCode/DriverInterface.cpp)

target_include_directories(
libdshowcapture INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src"
"${CMAKE_CURRENT_SOURCE_DIR}/src/external/capture-device-support/Library")

target_compile_definitions(libdshowcapture INTERFACE _UP_WINDOWS=1)
target_compile_options(libdshowcapture INTERFACE /wd4018)
16 changes: 0 additions & 16 deletions libobs/cmake/32bit-build.cmake

This file was deleted.

Loading

0 comments on commit d81fcd7

Please sign in to comment.