From 0e08c8388a56192a686cbc157457891d8fc6c6e8 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Mon, 3 Oct 2022 15:43:17 +0300 Subject: [PATCH] Add an ability to replace some source files before building. --- CMakeLists.txt | 7 ++++++- cmake/PatchSources.cmake | 10 ++++++++++ patches/.gitkeep | 0 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 cmake/PatchSources.cmake create mode 100644 patches/.gitkeep diff --git a/CMakeLists.txt b/CMakeLists.txt index fe49a25..88fa704 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.20) set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING INTERNAL FORCE) @@ -35,6 +35,11 @@ if (MSVC) patch_file(${WEBRTC_SOURCE_DIR}/build/config/win/BUILD.gn ":static_crt" ":dynamic_crt") endif () +# Copy all files from 'patches' directory to 'webrtc/src' +# For example, 'patches/api/foo.h' will be copied to 'webrtc/src/api/foo.h' +include(PatchSources) +patch_sources("${CMAKE_CURRENT_SOURCE_DIR}/patches" "${CMAKE_CURRENT_SOURCE_DIR}/webrtc/src") + include(AddWebRTCTarget) add_webrtc_target(${WEBRTC_SOURCE_DIR} ${WEBRTC_BUILD_DIR}) diff --git a/cmake/PatchSources.cmake b/cmake/PatchSources.cmake new file mode 100644 index 0000000..c735f71 --- /dev/null +++ b/cmake/PatchSources.cmake @@ -0,0 +1,10 @@ +function(patch_sources PATCH_DIR SOURCE_DIR) + file(GLOB_RECURSE PATCHED_SOURCES RELATIVE ${PATCH_DIR} ${PATCH_DIR}/*) + list(REMOVE_ITEM PATCHED_SOURCES ".gitkeep") + foreach (file ${PATCHED_SOURCES}) + message(STATUS "Patching ${file}...") + set(destination "${SOURCE_DIR}/${file}") + cmake_path(GET destination PARENT_PATH dest_dir) + file(COPY ${PATCH_DIR}/${file} DESTINATION ${dest_dir}) + endforeach () +endfunction() diff --git a/patches/.gitkeep b/patches/.gitkeep new file mode 100644 index 0000000..e69de29