From ccf9447a3ccd0ca28f2c3c79c8528406d8dd1754 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Sun, 22 Jun 2025 20:08:43 +0200 Subject: [PATCH 01/10] build: integrate libc++ and libc++abi for cross-platform support --- webrtc-jni/pom.xml | 3 +- webrtc-jni/src/main/cpp/CMakeLists.txt | 4 +- .../dependencies/jni-voithos/CMakeLists.txt | 2 + .../jni-voithos/src/JavaUtils.cpp | 1 + .../cpp/dependencies/webrtc/CMakeLists.txt | 82 ++++++++++++++++++- .../media/video/VideoTrackDesktopSource.h | 62 +++++++------- .../media/video/desktop/DesktopCapturer.h | 31 +++---- .../src/main/cpp/src/JNI_RefCountedObject.cpp | 2 +- .../src/main/cpp/src/JNI_ScreenCapturer.cpp | 18 +--- .../src/main/cpp/src/JNI_WindowCapturer.cpp | 18 +--- .../src/main/cpp/src/api/VideoFrame.cpp | 2 +- .../media/video/desktop/DesktopCapturer.cpp | 31 ++++--- .../cpp/toolchain/x86_64-linux-clang.cmake | 11 ++- .../cpp/toolchain/x86_64-windows-clang.cmake | 1 + 14 files changed, 164 insertions(+), 104 deletions(-) create mode 100644 webrtc-jni/src/main/cpp/toolchain/x86_64-windows-clang.cmake diff --git a/webrtc-jni/pom.xml b/webrtc-jni/pom.xml index ea99ed9e..aa4904ce 100644 --- a/webrtc-jni/pom.xml +++ b/webrtc-jni/pom.xml @@ -154,6 +154,7 @@ -T ClangCL + toolchain/x86_64-windows-clang.cmake @@ -165,7 +166,7 @@ - toolchain/x86_64-linux-gnu.cmake + toolchain/x86_64-linux-clang.cmake diff --git a/webrtc-jni/src/main/cpp/CMakeLists.txt b/webrtc-jni/src/main/cpp/CMakeLists.txt index 7b2d0a7b..1e9faaa6 100644 --- a/webrtc-jni/src/main/cpp/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/CMakeLists.txt @@ -81,9 +81,9 @@ if(APPLE) set_source_files_properties(${SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c++") target_link_libraries(${PROJECT_NAME} "-framework Foundation" "-framework AVFoundation" "-framework CoreMedia" "-framework CoreAudio" "-framework IOKit") elseif(LINUX) - target_link_libraries(${PROJECT_NAME} -static-libgcc -static-libstdc++ pulse udev) + target_link_libraries(${PROJECT_NAME} -static-libgcc -stdlib=libc++ c++ c++abi pulse udev) elseif(WIN32) - target_link_libraries(${PROJECT_NAME} dwmapi.lib mf.lib mfreadwrite.lib mfplat.lib mfuuid.lib shcore.lib) + target_link_libraries(${PROJECT_NAME} c++.lib msvcprt.lib dwmapi.lib mf.lib mfreadwrite.lib mfplat.lib mfuuid.lib shcore.lib) endif() install(TARGETS ${PROJECT_NAME} diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt index 4144b5ee..3f8fdccb 100644 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt @@ -79,3 +79,5 @@ target_include_directories(${PROJECT_NAME} include/jni include/jni/${JNI_PLATFORM} ) + +target_link_libraries(${PROJECT_NAME} PRIVATE webrtc) \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaUtils.cpp b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaUtils.cpp index 860e6f10..e3b3a940 100644 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaUtils.cpp +++ b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaUtils.cpp @@ -16,6 +16,7 @@ #include "JavaThreadEnv.h" #include "JavaWrappedException.h" +#include #include bool ExceptionCheck(JNIEnv * env) diff --git a/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt b/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt index 06d95c01..682bf44f 100644 --- a/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt @@ -138,11 +138,26 @@ message(STATUS "WebRTC install path: ${WEBRTC_INSTALL_DIR}") if(EXISTS "${WEBRTC_LIB_PATH_INSTALLED}") set(TARGET_INC_DIR ${WEBRTC_INSTALL_DIR}/include) set(TARGET_LINK_LIB ${WEBRTC_LIB_PATH_INSTALLED}) + set(TARGET_LIB_DIR ${WEBRTC_INSTALL_DIR}/lib) + set(TARGET_LIBCPP_BUILDTOOLS_INC_DIR ${TARGET_INC_DIR}/third_party/libc++/) + set(TARGET_LIBCPP_INC_DIR ${TARGET_INC_DIR}/third_party/libc++/include) + set(TARGET_LIBCPP_ABI_INC_DIR ${TARGET_INC_DIR}/third_party/libc++abi/include) else() set(TARGET_INC_DIR ${WEBRTC_SRC}) set(TARGET_LINK_LIB ${WEBRTC_LIB_PATH}) + set(TARGET_LIB_DIR ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj) + set(TARGET_LIBCPP_BUILDTOOLS_INC_DIR ${WEBRTC_SRC}/buildtools/third_party/libc++/) + set(TARGET_LIBCPP_INC_DIR ${WEBRTC_SRC}/third_party/libc++/src/include) + set(TARGET_LIBCPP_ABI_INC_DIR ${WEBRTC_SRC}/third_party/libc++abi/src/include) endif() +#if(LINUX) + target_include_directories(${PROJECT_NAME} PUBLIC ${TARGET_LIBCPP_BUILDTOOLS_INC_DIR}) + target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${TARGET_LIBCPP_INC_DIR} ${TARGET_LIBCPP_ABI_INC_DIR}) + + target_link_directories(${PROJECT_NAME} PUBLIC "${TARGET_LIB_DIR}") +#endif() + target_include_directories(${PROJECT_NAME} PUBLIC ${TARGET_INC_DIR} @@ -155,9 +170,6 @@ if(APPLE) target_compile_definitions(${PROJECT_NAME} PUBLIC WEBRTC_MAC WEBRTC_POSIX) target_link_libraries(${PROJECT_NAME} "-framework Foundation" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreAudio" "-framework CoreVideo" "-framework ScreenCaptureKit" "-framework AudioToolbox" "-framework IOSurface" "-framework ApplicationServices" "-framework AppKit") elseif(LINUX) - # Due to branch 6998 (m134) build with gcc. Linking webrtc built with clang causes errors. - set(WEBRTC_CLANG "false") - # Find DBus find_package(PkgConfig QUIET REQUIRED) # Include functions provided by PkgConfig module. pkg_check_modules(DBUS REQUIRED dbus-1) @@ -242,7 +254,7 @@ if (PATCHES) endif() message(STATUS "WebRTC: generate") -set(COMPILE_ARGS "target_cpu=\"${TARGET_CPU}\" is_clang=${WEBRTC_CLANG} is_debug=false is_component_build=false treat_warnings_as_errors=false rtc_build_tools=false rtc_use_perfetto=false rtc_use_pipewire=false rtc_enable_protobuf=false rtc_build_examples=false rtc_include_tests=false use_rtti=true rtc_use_h264=true use_custom_libcxx=false symbol_level=0") +set(COMPILE_ARGS "target_cpu=\"${TARGET_CPU}\" is_clang=${WEBRTC_CLANG} is_debug=false is_component_build=false treat_warnings_as_errors=false rtc_build_tools=false rtc_use_perfetto=false rtc_use_pipewire=false rtc_enable_protobuf=false rtc_build_examples=false rtc_include_tests=false use_rtti=true rtc_use_h264=true use_custom_libcxx=true symbol_level=0") execute_command( COMMAND gn gen ${WEBRTC_BUILD} --args=${COMPILE_ARGS} WORKING_DIRECTORY "${WEBRTC_SRC}" @@ -256,6 +268,68 @@ execute_command( if(LINUX) sysroot_link() + + # Collect lib++ objects + file(GLOB_RECURSE LibCPP_OBJS + ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/buildtools/third_party/libc++/libc++/*.o + ) + # Collect lib++abi objects + file(GLOB_RECURSE LibCPP_ABI_OBJS + ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/buildtools/third_party/libc++abi/libc++abi/*.o + ) + # Create static libraries + execute_command( + COMMAND ${CMAKE_AR} rcs ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++.a ${LibCPP_OBJS} + ) + execute_command( + COMMAND ${CMAKE_AR} rcs ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++abi.a ${LibCPP_ABI_OBJS} + ) + # Install libc++ and libc++abi headers and libraries + install( + FILES + "${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++.a" + "${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++abi.a" + DESTINATION + "${WEBRTC_INSTALL_DIR}/lib" + ) + install( + DIRECTORY "${WEBRTC_SRC}/third_party/libc++/src/include" + DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++" + ) + install( + DIRECTORY "${WEBRTC_SRC}/buildtools/third_party/libc++/" + DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++" + ) + install( + DIRECTORY "${WEBRTC_SRC}/third_party/libc++abi/src/include" + DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++abi" + ) +elseif(WIN32) + # Collect lib++ objects + file(GLOB_RECURSE LibCPP_OBJS + ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/buildtools/third_party/libc++/libc++/*.obj + ) + + # Create static libraries + execute_command( + COMMAND ${CMAKE_LINKER} /LIB /OUT:${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/c++.lib ${LibCPP_OBJS} + ) + + # Install libc++ headers and libraries + install( + FILES + "${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/c++.lib" + DESTINATION + "${WEBRTC_INSTALL_DIR}/lib" + ) + install( + DIRECTORY "${WEBRTC_SRC}/third_party/libc++/src/include" + DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++" + ) + install( + DIRECTORY "${WEBRTC_SRC}/buildtools/third_party/libc++/" + DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++" + ) endif() install(FILES "${WEBRTC_LIB_PATH}" DESTINATION "${WEBRTC_INSTALL_DIR}/lib") diff --git a/webrtc-jni/src/main/cpp/include/media/video/VideoTrackDesktopSource.h b/webrtc-jni/src/main/cpp/include/media/video/VideoTrackDesktopSource.h index 4e5189b6..84fe7950 100644 --- a/webrtc-jni/src/main/cpp/include/media/video/VideoTrackDesktopSource.h +++ b/webrtc-jni/src/main/cpp/include/media/video/VideoTrackDesktopSource.h @@ -26,49 +26,49 @@ namespace jni { class VideoTrackDesktopSource : public rtc::AdaptedVideoTrackSource, public webrtc::DesktopCapturer::Callback { - public: - VideoTrackDesktopSource(); - ~VideoTrackDesktopSource(); + public: + VideoTrackDesktopSource(); + ~VideoTrackDesktopSource(); - void setSourceId(webrtc::DesktopCapturer::SourceId source, bool isWindow); - void setFrameRate(const uint16_t frameRate); - void setMaxFrameSize(webrtc::DesktopSize size); - void setFocusSelectedSource(bool focus); + void setSourceId(webrtc::DesktopCapturer::SourceId source, bool isWindow); + void setFrameRate(const uint16_t frameRate); + void setMaxFrameSize(webrtc::DesktopSize size); + void setFocusSelectedSource(bool focus); - void start(); - void stop(); - void terminate(); + void start(); + void stop(); + void terminate(); - // AdaptedVideoTrackSource implementation. - virtual bool is_screencast() const override; - virtual std::optional needs_denoising() const override; - SourceState state() const override; - bool remote() const override; + // AdaptedVideoTrackSource implementation. + virtual bool is_screencast() const override; + virtual std::optional needs_denoising() const override; + SourceState state() const override; + bool remote() const override; - // DesktopCapturer::Callback implementation. - void OnCaptureResult(webrtc::DesktopCapturer::Result result, std::unique_ptr frame) override; + // DesktopCapturer::Callback implementation. + void OnCaptureResult(webrtc::DesktopCapturer::Result result, std::unique_ptr frame) override; - private: - void capture(); - void process(std::unique_ptr& frame); + private: + void capture(); + void process(std::unique_ptr& frame); - private: - uint16_t frameRate; - bool isCapturing; - bool focusSelectedSource; + private: + uint16_t frameRate; + bool isCapturing; + bool focusSelectedSource; - webrtc::DesktopSize maxFrameSize; + webrtc::DesktopSize maxFrameSize; - webrtc::MediaSourceInterface::SourceState sourceState; + webrtc::MediaSourceInterface::SourceState sourceState; - webrtc::DesktopCapturer::SourceId sourceId; - bool sourceIsWindow; + webrtc::DesktopCapturer::SourceId sourceId; + bool sourceIsWindow; - std::unique_ptr lastFrame; + std::unique_ptr lastFrame; - std::unique_ptr captureThread; + std::unique_ptr captureThread; - rtc::scoped_refptr buffer; + rtc::scoped_refptr buffer; }; } diff --git a/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopCapturer.h b/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopCapturer.h index 5f5dc000..927afdc8 100644 --- a/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopCapturer.h +++ b/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopCapturer.h @@ -14,41 +14,36 @@ * limitations under the License. */ -#ifndef JNI_WEBRTC_MEDIA_VIDEO_DESKTOP_CAPTURER_H_ -#define JNI_WEBRTC_MEDIA_VIDEO_DESKTOP_CAPTURER_H_ +#ifndef JNI_WEBRTC_MEDIA_DESKTOP_CAPTURER_H_ +#define JNI_WEBRTC_MEDIA_DESKTOP_CAPTURER_H_ #if defined(WEBRTC_WIN) #include "platform/windows/ComInitializer.h" #endif #include "modules/desktop_capture/desktop_capturer.h" -#include "modules/desktop_capture/desktop_and_cursor_composer.h" #include #include namespace jni { - class DesktopCapturer + class DesktopCapturer : public webrtc::DesktopCapturer { public: - DesktopCapturer(webrtc::DesktopCapturer * capturer); - ~DesktopCapturer(); - - DesktopCapturer(const DesktopCapturer &) = delete; - DesktopCapturer & operator=(const DesktopCapturer &) = delete; + explicit DesktopCapturer(bool screenCapturer); + ~DesktopCapturer() override; // webrtc::DesktopCapturer implementations. - void Start(webrtc::DesktopCapturer::Callback * callback); - void SetSharedMemoryFactory(std::unique_ptr factory); - void SetMaxFrameRate(uint32_t max_frame_rate); - void CaptureFrame(); - void SetExcludedWindow(webrtc::WindowId window); - bool GetSourceList(webrtc::DesktopCapturer::SourceList * sources); - bool SelectSource(webrtc::DesktopCapturer::SourceId id); - bool FocusOnSelectedSource(); + void Start(Callback * callback) override; + void SetSharedMemoryFactory(std::unique_ptr factory) override; + void CaptureFrame() override; + void SetExcludedWindow(webrtc::WindowId window) override; + bool GetSourceList(SourceList * sources) override; + bool SelectSource(SourceId id) override; + bool FocusOnSelectedSource() override; void setFocusSelectedSource(bool focus); - bool IsOccluded(const webrtc::DesktopVector & pos); + bool IsOccluded(const webrtc::DesktopVector & pos) override; protected: std::unique_ptr capturer; diff --git a/webrtc-jni/src/main/cpp/src/JNI_RefCountedObject.cpp b/webrtc-jni/src/main/cpp/src/JNI_RefCountedObject.cpp index 3623032c..74791248 100644 --- a/webrtc-jni/src/main/cpp/src/JNI_RefCountedObject.cpp +++ b/webrtc-jni/src/main/cpp/src/JNI_RefCountedObject.cpp @@ -34,7 +34,7 @@ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_internal_RefCountedObject_release webrtc::RefCountInterface * ref = GetHandle(env, caller); CHECK_HANDLE(ref); - const webrtc::RefCountReleaseStatus status = ref->Release(); + const auto status = ref->Release(); if (status == webrtc::RefCountReleaseStatus::kDroppedLastRef) { SetHandle(env, caller, nullptr); diff --git a/webrtc-jni/src/main/cpp/src/JNI_ScreenCapturer.cpp b/webrtc-jni/src/main/cpp/src/JNI_ScreenCapturer.cpp index 185cfc10..957292e8 100644 --- a/webrtc-jni/src/main/cpp/src/JNI_ScreenCapturer.cpp +++ b/webrtc-jni/src/main/cpp/src/JNI_ScreenCapturer.cpp @@ -18,24 +18,8 @@ #include "JavaUtils.h" #include "media/video/desktop/DesktopCapturer.h" -#include "modules/desktop_capture/desktop_capturer.h" -#include "modules/desktop_capture/desktop_capture_options.h" -#include "modules/desktop_capture/desktop_and_cursor_composer.h" - JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_desktop_ScreenCapturer_initialize (JNIEnv * env, jobject caller) { - auto options = webrtc::DesktopCaptureOptions::CreateDefault(); - // Enable desktop effects. - options.set_disable_effects(false); - -#if defined(WEBRTC_WIN) - options.set_allow_directx_capturer(true); -#endif - - auto capturer = new webrtc::DesktopAndCursorComposer( - webrtc::DesktopCapturer::CreateScreenCapturer(options), - options); - - SetHandle(env, caller, new jni::DesktopCapturer(capturer)); + SetHandle(env, caller, new jni::DesktopCapturer(true)); } \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/src/JNI_WindowCapturer.cpp b/webrtc-jni/src/main/cpp/src/JNI_WindowCapturer.cpp index b5be4004..c08107b0 100644 --- a/webrtc-jni/src/main/cpp/src/JNI_WindowCapturer.cpp +++ b/webrtc-jni/src/main/cpp/src/JNI_WindowCapturer.cpp @@ -18,24 +18,8 @@ #include "JavaUtils.h" #include "media/video/desktop/DesktopCapturer.h" -#include "modules/desktop_capture/desktop_capturer.h" -#include "modules/desktop_capture/desktop_capture_options.h" -#include "modules/desktop_capture/desktop_and_cursor_composer.h" - JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_desktop_WindowCapturer_initialize (JNIEnv * env, jobject caller) { - auto options = webrtc::DesktopCaptureOptions::CreateDefault(); - // Enable desktop effects. - options.set_disable_effects(false); - -#if defined(WEBRTC_WIN) - options.set_allow_directx_capturer(true); -#endif - - auto capturer = new webrtc::DesktopAndCursorComposer( - webrtc::DesktopCapturer::CreateWindowCapturer(options), - options); - - SetHandle(env, caller, new jni::DesktopCapturer(capturer)); + SetHandle(env, caller, new jni::DesktopCapturer(false)); } \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/src/api/VideoFrame.cpp b/webrtc-jni/src/main/cpp/src/api/VideoFrame.cpp index 457fd4a8..cd826102 100644 --- a/webrtc-jni/src/main/cpp/src/api/VideoFrame.cpp +++ b/webrtc-jni/src/main/cpp/src/api/VideoFrame.cpp @@ -27,7 +27,7 @@ namespace jni { webrtc::VideoFrame toNative(JNIEnv * env, const JavaRef & javaFrame) { - const std::shared_ptr javaClass = JavaClasses::get(env); + const auto javaClass = JavaClasses::get(env); JavaObject obj(env, javaFrame); int rotation = obj.getInt(javaClass->rotation); diff --git a/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCapturer.cpp b/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCapturer.cpp index 57158a96..7be0f110 100644 --- a/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCapturer.cpp +++ b/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCapturer.cpp @@ -22,10 +22,26 @@ namespace jni { - DesktopCapturer::DesktopCapturer(webrtc::DesktopCapturer * capturer) : + DesktopCapturer::DesktopCapturer(bool screenCapturer) : focusSelectedSource(false) { - this->capturer.reset(capturer); + auto options = webrtc::DesktopCaptureOptions::CreateDefault(); + // Enable desktop effects. + options.set_disable_effects(false); + +#if defined(WEBRTC_WIN) + options.set_allow_directx_capturer(true); +#endif + + if (screenCapturer) { + capturer.reset(new webrtc::DesktopAndCursorComposer( + webrtc::DesktopCapturer::CreateScreenCapturer(options), + options)); + } + else { + capturer = std::make_unique( + webrtc::DesktopCapturer::CreateWindowCapturer(options), options); + } } DesktopCapturer::~DesktopCapturer() @@ -33,7 +49,7 @@ namespace jni capturer.reset(); } - void DesktopCapturer::Start(webrtc::DesktopCapturer::Callback * callback) + void DesktopCapturer::Start(Callback * callback) { capturer->Start(callback); @@ -47,11 +63,6 @@ namespace jni capturer->SetSharedMemoryFactory(std::move(factory)); } - void DesktopCapturer::SetMaxFrameRate(uint32_t max_frame_rate) - { - capturer->SetMaxFrameRate(max_frame_rate); - } - void DesktopCapturer::CaptureFrame() { capturer->CaptureFrame(); @@ -62,12 +73,12 @@ namespace jni capturer->SetExcludedWindow(window); } - bool DesktopCapturer::GetSourceList(webrtc::DesktopCapturer::SourceList * sources) + bool DesktopCapturer::GetSourceList(SourceList * sources) { return capturer->GetSourceList(sources); } - bool DesktopCapturer::SelectSource(webrtc::DesktopCapturer::SourceId id) + bool DesktopCapturer::SelectSource(SourceId id) { return capturer->SelectSource(id); } diff --git a/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake b/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake index 4874614a..4a7d9647 100644 --- a/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake +++ b/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake @@ -1,6 +1,13 @@ set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR x86_64) -set(CMAKE_C_COMPILER /usr/bin/clang-21) -set(CMAKE_CXX_COMPILER /usr/bin/clang++-21) +set(CMAKE_C_COMPILER /tmp/clang/bin/clang) +set(CMAKE_CXX_COMPILER /tmp/clang/bin/clang++) +set(CMAKE_AR /tmp/clang/bin/llvm-ar) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++ -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE") + +foreach(LINKER SHARED_LINKER) + set(CMAKE_${LINKER}_FLAGS "-fuse-ld=lld -Wl,-s") +endforeach() set(TARGET_CPU "x64") diff --git a/webrtc-jni/src/main/cpp/toolchain/x86_64-windows-clang.cmake b/webrtc-jni/src/main/cpp/toolchain/x86_64-windows-clang.cmake new file mode 100644 index 00000000..785d513d --- /dev/null +++ b/webrtc-jni/src/main/cpp/toolchain/x86_64-windows-clang.cmake @@ -0,0 +1 @@ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT /EHsc -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE") From e7612966c19f03682dd918a0fd6a70a2f859bbfd Mon Sep 17 00:00:00 2001 From: Alex Andres <58339654+devopvoid@users.noreply.github.com> Date: Sun, 22 Jun 2025 23:44:26 +0000 Subject: [PATCH 02/10] fix: GitHub actions --- .github/actions/prepare-linux/action.yml | 6 ++---- .github/workflows/build.yml | 1 - .github/workflows/release.yml | 4 ---- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/actions/prepare-linux/action.yml b/.github/actions/prepare-linux/action.yml index f4faa49a..3ffb92f7 100644 --- a/.github/actions/prepare-linux/action.yml +++ b/.github/actions/prepare-linux/action.yml @@ -33,10 +33,8 @@ runs: sudo apt-get update sudo apt-get install -y pulseaudio libpulse-dev libasound2-dev libdbus-1-dev libudev-dev libv4l-dev libx11-dev libxcomposite-dev libxrandr-dev libxfixes-dev binutils cmake git locales lsb-release ninja-build pkg-config python3 python3-setuptools rsync unzip wget xz-utils - # More recent LLVM and Clang. - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh ${{ matrix.llvm }} all + # Chromium Clang to be used with the clang toolchain file + curl -s https://raw.githubusercontent.com/chromium/chromium/main/tools/clang/scripts/update.py | python3 - --output-dir=/opt/clang # Required for testing #pulseaudio --start diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c812d903..62c6a750 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,7 +55,6 @@ jobs: - name: linux_x86-64 runs-on: ubuntu-22.04 java: [17] - llvm: [21] runs-on: ${{ matrix.platform.runs-on }} steps: - name: Checkout code diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 834393f4..5d094d7e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,9 +18,6 @@ env: jobs: prepare-release: - strategy: - matrix: - llvm: [ 21 ] runs-on: ubuntu-22.04 steps: - id: prepare @@ -100,7 +97,6 @@ jobs: - name: linux_x86-64 runs-on: ubuntu-22.04 java: [17] - llvm: [21] runs-on: ${{ matrix.platform.runs-on }} steps: - name: Checkout code From 114351ff9cb8586bd628b735e25fb5d95648590c Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Mon, 23 Jun 2025 01:54:11 +0200 Subject: [PATCH 03/10] build: update clang compiler paths in x86_64-linux-clang.cmake --- webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake b/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake index 4a7d9647..c7a9e5e6 100644 --- a/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake +++ b/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake @@ -1,8 +1,8 @@ set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR x86_64) -set(CMAKE_C_COMPILER /tmp/clang/bin/clang) -set(CMAKE_CXX_COMPILER /tmp/clang/bin/clang++) -set(CMAKE_AR /tmp/clang/bin/llvm-ar) +set(CMAKE_C_COMPILER /opt/clang/bin/clang) +set(CMAKE_CXX_COMPILER /opt/clang/bin/clang++) +set(CMAKE_AR /opt/clang/bin/llvm-ar) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++ -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE") From 3d86636f66355ebe34a11c453bb6f08dab592847 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Mon, 23 Jun 2025 12:42:26 +0200 Subject: [PATCH 04/10] build: add libc++ as the standard library for linking --- webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake b/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake index c7a9e5e6..af407568 100644 --- a/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake +++ b/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake @@ -4,7 +4,8 @@ set(CMAKE_C_COMPILER /opt/clang/bin/clang) set(CMAKE_CXX_COMPILER /opt/clang/bin/clang++) set(CMAKE_AR /opt/clang/bin/llvm-ar) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++ -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++ -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") foreach(LINKER SHARED_LINKER) set(CMAKE_${LINKER}_FLAGS "-fuse-ld=lld -Wl,-s") From f0461e1c23badefe725b4d56447e2addd75de635 Mon Sep 17 00:00:00 2001 From: Alex Andres <58339654+devopvoid@users.noreply.github.com> Date: Mon, 23 Jun 2025 11:16:12 +0000 Subject: [PATCH 05/10] fix: linux build by adding libc++-dev and libc++abi-dev --- .github/actions/prepare-linux/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/prepare-linux/action.yml b/.github/actions/prepare-linux/action.yml index 3ffb92f7..c5071ffd 100644 --- a/.github/actions/prepare-linux/action.yml +++ b/.github/actions/prepare-linux/action.yml @@ -31,7 +31,7 @@ runs: - name: Install required packages run: | sudo apt-get update - sudo apt-get install -y pulseaudio libpulse-dev libasound2-dev libdbus-1-dev libudev-dev libv4l-dev libx11-dev libxcomposite-dev libxrandr-dev libxfixes-dev binutils cmake git locales lsb-release ninja-build pkg-config python3 python3-setuptools rsync unzip wget xz-utils + sudo apt-get install -y pulseaudio libpulse-dev libasound2-dev libdbus-1-dev libudev-dev libv4l-dev libx11-dev libxcomposite-dev libxrandr-dev libxfixes-dev libc++-dev libc++abi-dev binutils cmake git locales lsb-release ninja-build pkg-config python3 python3-setuptools rsync unzip wget xz-utils # Chromium Clang to be used with the clang toolchain file curl -s https://raw.githubusercontent.com/chromium/chromium/main/tools/clang/scripts/update.py | python3 - --output-dir=/opt/clang From c4e4b3a0d56f3ac226f1a1386ab121160ff43489 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Mon, 23 Jun 2025 13:24:49 +0200 Subject: [PATCH 06/10] Revert "fix: linux build by adding libc++-dev and libc++abi-dev" This reverts commit f0461e1c23badefe725b4d56447e2addd75de635. --- .github/actions/prepare-linux/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/prepare-linux/action.yml b/.github/actions/prepare-linux/action.yml index c5071ffd..3ffb92f7 100644 --- a/.github/actions/prepare-linux/action.yml +++ b/.github/actions/prepare-linux/action.yml @@ -31,7 +31,7 @@ runs: - name: Install required packages run: | sudo apt-get update - sudo apt-get install -y pulseaudio libpulse-dev libasound2-dev libdbus-1-dev libudev-dev libv4l-dev libx11-dev libxcomposite-dev libxrandr-dev libxfixes-dev libc++-dev libc++abi-dev binutils cmake git locales lsb-release ninja-build pkg-config python3 python3-setuptools rsync unzip wget xz-utils + sudo apt-get install -y pulseaudio libpulse-dev libasound2-dev libdbus-1-dev libudev-dev libv4l-dev libx11-dev libxcomposite-dev libxrandr-dev libxfixes-dev binutils cmake git locales lsb-release ninja-build pkg-config python3 python3-setuptools rsync unzip wget xz-utils # Chromium Clang to be used with the clang toolchain file curl -s https://raw.githubusercontent.com/chromium/chromium/main/tools/clang/scripts/update.py | python3 - --output-dir=/opt/clang From ccf0251f4a249c63ae1c095ca14e60473d85b8b0 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Mon, 23 Jun 2025 15:38:05 +0200 Subject: [PATCH 07/10] build: inherit libc++ include paths and set as standard library for Linux --- .../main/cpp/dependencies/jni-voithos/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt index 3f8fdccb..e6d4f669 100644 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt @@ -80,4 +80,16 @@ target_include_directories(${PROJECT_NAME} include/jni/${JNI_PLATFORM} ) +# Inherit libc++ include paths from webrtc +target_include_directories(${PROJECT_NAME} + PUBLIC + ${TARGET_LIBCPP_BUILDTOOLS_INC_DIR} + ${TARGET_LIBCPP_INC_DIR} + ${TARGET_LIBCPP_ABI_INC_DIR} +) + +if(LINUX) + target_compile_options(${PROJECT_NAME} PUBLIC -stdlib=libc++) +endif() + target_link_libraries(${PROJECT_NAME} PRIVATE webrtc) \ No newline at end of file From 0f9795da81eea54a4a7a9e01aef45e2714cc7599 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Mon, 23 Jun 2025 16:30:32 +0200 Subject: [PATCH 08/10] refactor: update DesktopCapturer to use unique_ptr and improve method signatures --- .../media/video/desktop/DesktopCapturer.h | 21 ++++++++++--------- .../media/video/desktop/DesktopCapturer.cpp | 16 ++++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopCapturer.h b/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopCapturer.h index 927afdc8..06a4c2af 100644 --- a/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopCapturer.h +++ b/webrtc-jni/src/main/cpp/include/media/video/desktop/DesktopCapturer.h @@ -28,22 +28,23 @@ namespace jni { - class DesktopCapturer : public webrtc::DesktopCapturer + class DesktopCapturer { public: explicit DesktopCapturer(bool screenCapturer); - ~DesktopCapturer() override; + ~DesktopCapturer(); // webrtc::DesktopCapturer implementations. - void Start(Callback * callback) override; - void SetSharedMemoryFactory(std::unique_ptr factory) override; - void CaptureFrame() override; - void SetExcludedWindow(webrtc::WindowId window) override; - bool GetSourceList(SourceList * sources) override; - bool SelectSource(SourceId id) override; - bool FocusOnSelectedSource() override; + void Start(webrtc::DesktopCapturer::Callback * callback); + void SetMaxFrameRate(uint32_t max_frame_rate); + void SetSharedMemoryFactory(std::unique_ptr factory); + void CaptureFrame(); + void SetExcludedWindow(webrtc::WindowId window); + bool GetSourceList(webrtc::DesktopCapturer::SourceList * sources); + bool SelectSource(webrtc::DesktopCapturer::SourceId id); + bool FocusOnSelectedSource(); void setFocusSelectedSource(bool focus); - bool IsOccluded(const webrtc::DesktopVector & pos) override; + bool IsOccluded(const webrtc::DesktopVector & pos); protected: std::unique_ptr capturer; diff --git a/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCapturer.cpp b/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCapturer.cpp index 7be0f110..68a07bea 100644 --- a/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCapturer.cpp +++ b/webrtc-jni/src/main/cpp/src/media/video/desktop/DesktopCapturer.cpp @@ -34,9 +34,8 @@ namespace jni #endif if (screenCapturer) { - capturer.reset(new webrtc::DesktopAndCursorComposer( - webrtc::DesktopCapturer::CreateScreenCapturer(options), - options)); + capturer = std::make_unique( + webrtc::DesktopCapturer::CreateScreenCapturer(options), options); } else { capturer = std::make_unique( @@ -49,7 +48,7 @@ namespace jni capturer.reset(); } - void DesktopCapturer::Start(Callback * callback) + void DesktopCapturer::Start(webrtc::DesktopCapturer::Callback * callback) { capturer->Start(callback); @@ -58,6 +57,11 @@ namespace jni } } + void DesktopCapturer::SetMaxFrameRate(uint32_t max_frame_rate) + { + capturer->SetMaxFrameRate(max_frame_rate); + } + void DesktopCapturer::SetSharedMemoryFactory(std::unique_ptr factory) { capturer->SetSharedMemoryFactory(std::move(factory)); @@ -73,12 +77,12 @@ namespace jni capturer->SetExcludedWindow(window); } - bool DesktopCapturer::GetSourceList(SourceList * sources) + bool DesktopCapturer::GetSourceList(webrtc::DesktopCapturer::SourceList * sources) { return capturer->GetSourceList(sources); } - bool DesktopCapturer::SelectSource(SourceId id) + bool DesktopCapturer::SelectSource(webrtc::DesktopCapturer::SourceId id) { return capturer->SelectSource(id); } From 623490e1830320e1a52665fc04f08d3c153e7725 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Mon, 23 Jun 2025 23:30:11 +0200 Subject: [PATCH 09/10] build: update CMakeLists.txt to inherit libc++ include paths for both Linux and Windows --- .../main/cpp/dependencies/jni-voithos/CMakeLists.txt | 12 ------------ .../src/main/cpp/dependencies/webrtc/CMakeLists.txt | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt index e6d4f669..3f8fdccb 100644 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt @@ -80,16 +80,4 @@ target_include_directories(${PROJECT_NAME} include/jni/${JNI_PLATFORM} ) -# Inherit libc++ include paths from webrtc -target_include_directories(${PROJECT_NAME} - PUBLIC - ${TARGET_LIBCPP_BUILDTOOLS_INC_DIR} - ${TARGET_LIBCPP_INC_DIR} - ${TARGET_LIBCPP_ABI_INC_DIR} -) - -if(LINUX) - target_compile_options(${PROJECT_NAME} PUBLIC -stdlib=libc++) -endif() - target_link_libraries(${PROJECT_NAME} PRIVATE webrtc) \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt b/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt index 682bf44f..ad14ff92 100644 --- a/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt @@ -151,12 +151,12 @@ else() set(TARGET_LIBCPP_ABI_INC_DIR ${WEBRTC_SRC}/third_party/libc++abi/src/include) endif() -#if(LINUX) +if(LINUX OR WIN32) target_include_directories(${PROJECT_NAME} PUBLIC ${TARGET_LIBCPP_BUILDTOOLS_INC_DIR}) target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${TARGET_LIBCPP_INC_DIR} ${TARGET_LIBCPP_ABI_INC_DIR}) target_link_directories(${PROJECT_NAME} PUBLIC "${TARGET_LIB_DIR}") -#endif() +endif() target_include_directories(${PROJECT_NAME} PUBLIC From e754b1eb1813378d65f5aae0272e38c0a250f6e1 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Tue, 1 Jul 2025 17:38:23 +0200 Subject: [PATCH 10/10] build: update CMake and action files for aarch32 and aarch64 support --- .github/actions/build/action.yml | 19 ++- .github/actions/prepare-linux/action.yml | 64 +++++++- .github/actions/prepare-macos/action.yml | 1 - .github/workflows/build.yml | 4 + README.md | 4 +- webrtc-jni/pom.xml | 4 +- webrtc-jni/src/main/cpp/CMakeLists.txt | 10 +- .../dependencies/jni-voithos/CMakeLists.txt | 4 +- .../cpp/dependencies/webrtc/CMakeLists.txt | 140 ++++++++++++------ .../cpp/toolchain/aarch32-linux-clang.cmake | 17 +++ .../cpp/toolchain/aarch64-linux-clang.cmake | 17 +++ .../cpp/toolchain/aarch64-linux-gnu.cmake | 2 +- .../cpp/toolchain/x86_64-linux-clang.cmake | 4 +- 13 files changed, 231 insertions(+), 59 deletions(-) create mode 100644 webrtc-jni/src/main/cpp/toolchain/aarch32-linux-clang.cmake create mode 100644 webrtc-jni/src/main/cpp/toolchain/aarch64-linux-clang.cmake diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 31f1decf..79572d64 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -47,10 +47,18 @@ runs: server-password: MAVEN_TOKEN - name: Build - run: mvn package -DskipTests + run: | + if [ "${{ inputs.platform-name }}" == "linux_arm" ]; then + mvn package -DskipTests -Plinux-aarch32 + elif [ "${{ inputs.platform-name }}" == "linux_arm64" ]; then + mvn package -DskipTests -Plinux-aarch64 + else + mvn package -DskipTests + fi shell: bash - name: Test + if: ${{ inputs.platform-name != 'linux_arm' && inputs.platform-name != 'linux_arm64' }} run: mvn -B jar:jar surefire:test shell: bash @@ -58,5 +66,12 @@ runs: env: MAVEN_USERNAME: ${{ inputs.maven-username }} MAVEN_TOKEN: ${{ inputs.maven-password }} - run: mvn deploy -DskipTests + run: | + if [ "${{ inputs.platform-name }}" == "linux_arm" ]; then + mvn deploy -DskipTests -Plinux-aarch32 + elif [ "${{ inputs.platform-name }}" == "linux_arm64" ]; then + mvn deploy -DskipTests -Plinux-aarch64 + else + mvn deploy -DskipTests + fi shell: bash diff --git a/.github/actions/prepare-linux/action.yml b/.github/actions/prepare-linux/action.yml index 3ffb92f7..cda0c25b 100644 --- a/.github/actions/prepare-linux/action.yml +++ b/.github/actions/prepare-linux/action.yml @@ -34,7 +34,11 @@ runs: sudo apt-get install -y pulseaudio libpulse-dev libasound2-dev libdbus-1-dev libudev-dev libv4l-dev libx11-dev libxcomposite-dev libxrandr-dev libxfixes-dev binutils cmake git locales lsb-release ninja-build pkg-config python3 python3-setuptools rsync unzip wget xz-utils # Chromium Clang to be used with the clang toolchain file - curl -s https://raw.githubusercontent.com/chromium/chromium/main/tools/clang/scripts/update.py | python3 - --output-dir=/opt/clang + #curl -s https://raw.githubusercontent.com/chromium/chromium/main/tools/clang/scripts/update.py | python3 - --output-dir=/opt/clang + # Use a more stable version of Clang + sudo mkdir -p /opt/clang + wget https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-llvmorg-20-init-9764-gb81d8e90-72.tar.xz + sudo tar -xvf clang-llvmorg-20-init-9764-gb81d8e90-72.tar.xz -C /opt/clang # Required for testing #pulseaudio --start @@ -42,3 +46,61 @@ runs: systemctl --user daemon-reload systemctl --user --now enable pipewire{,-pulse}.{socket,service} shell: bash + + - name: Install required packages for arm + if: matrix.platform.name == 'linux_arm' + run: | + sudo apt install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + + sudo dpkg --add-architecture armhf + + sudo rm /etc/apt/sources.list + + sudo tee -a /etc/apt/sources.list > /dev/null < /dev/null < Linux ✔ - - - - + ✔ armeabi-v7a + ✔ arm64-v8a macOS diff --git a/webrtc-jni/pom.xml b/webrtc-jni/pom.xml index aa4904ce..dfc5ad4f 100644 --- a/webrtc-jni/pom.xml +++ b/webrtc-jni/pom.xml @@ -178,7 +178,7 @@ - toolchain/aarch32-linux-gnu.cmake + toolchain/aarch32-linux-clang.cmake @@ -190,7 +190,7 @@ - toolchain/aarch64-linux-gnu.cmake + toolchain/aarch64-linux-clang.cmake diff --git a/webrtc-jni/src/main/cpp/CMakeLists.txt b/webrtc-jni/src/main/cpp/CMakeLists.txt index 1e9faaa6..2b2e439d 100644 --- a/webrtc-jni/src/main/cpp/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/CMakeLists.txt @@ -81,7 +81,13 @@ if(APPLE) set_source_files_properties(${SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c++") target_link_libraries(${PROJECT_NAME} "-framework Foundation" "-framework AVFoundation" "-framework CoreMedia" "-framework CoreAudio" "-framework IOKit") elseif(LINUX) - target_link_libraries(${PROJECT_NAME} -static-libgcc -stdlib=libc++ c++ c++abi pulse udev) + if(NOT TARGET_CPU MATCHES "^arm") + set(CXX_LIBS "-static-libgcc -stdlib=libc++ -lc++ -lc++abi") + else() + set(CXX_LIBS "-static-libgcc") + endif() + + target_link_libraries(${PROJECT_NAME} ${CXX_LIBS} pulse udev) elseif(WIN32) target_link_libraries(${PROJECT_NAME} c++.lib msvcprt.lib dwmapi.lib mf.lib mfreadwrite.lib mfplat.lib mfuuid.lib shcore.lib) endif() @@ -89,4 +95,4 @@ endif() install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT Runtime LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT Runtime -) \ No newline at end of file +) diff --git a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt index 3f8fdccb..19f10cc6 100644 --- a/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/dependencies/jni-voithos/CMakeLists.txt @@ -80,4 +80,6 @@ target_include_directories(${PROJECT_NAME} include/jni/${JNI_PLATFORM} ) -target_link_libraries(${PROJECT_NAME} PRIVATE webrtc) \ No newline at end of file +if(LINUX OR WIN32) + target_link_libraries(${PROJECT_NAME} PRIVATE webrtc) +endif() \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt b/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt index ad14ff92..221811e7 100644 --- a/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt +++ b/webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt @@ -13,6 +13,12 @@ FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pseudo.cxx add_library(${PROJECT_NAME} STATIC pseudo.cxx pseudo.hxx) +set(CUSTOM_LIBCXX false) + +if((LINUX AND NOT TARGET_CPU MATCHES "^arm") OR WIN32) + set(CUSTOM_LIBCXX true) +endif() + if(NOT DEFINED TARGET_CPU) if(CMAKE_SIZEOF_VOID_P EQUAL 4) set(TARGET_CPU "x86") @@ -20,7 +26,7 @@ if(NOT DEFINED TARGET_CPU) set(TARGET_CPU "x64") endif() - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64") + if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm.*$") set(TARGET_CPU "${CMAKE_SYSTEM_PROCESSOR}") endif() endif() @@ -82,15 +88,20 @@ endfunction() function(sysroot_install) message(STATUS "Installing sysroot") - set(SCRIPT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/linux/sysroot/install-sysroot.py) + if(EXISTS "${WEBRTC_INSTALL_DIR}/lib/${WEBRTC_LIB}") + set(SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/linux/sysroot") + else() + set(SCRIPT_PATH "${WEBRTC_SRC_DIR}/src/build/linux/sysroot_scripts") + endif() execute_process( - COMMAND ${Python3_EXECUTABLE} ${SCRIPT_PATH} --arch=${TARGET_CPU} - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + COMMAND ${Python3_EXECUTABLE} install-sysroot.py --arch=${TARGET_CPU} + WORKING_DIRECTORY "${SCRIPT_PATH}" OUTPUT_VARIABLE COMMAND_OUTPUT ERROR_VARIABLE COMMAND_ERROR ) + print("Sysroot script path: ${SCRIPT_PATH}") print("${COMMAND_OUTPUT}") print("${COMMAND_ERROR}") endfunction() @@ -98,10 +109,24 @@ endfunction() function(sysroot_link) message(STATUS "Retrieving libm.so from sysroot") - set(SYSROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/linux) + set(SYSROOT_ARCH "amd64") + + if(${TARGET_CPU} STREQUAL "x64") + set(SYSROOT_ARCH "amd64") + elseif(${TARGET_CPU} STREQUAL "arm") + set(SYSROOT_ARCH "armhf") + elseif(${TARGET_CPU} STREQUAL "arm64") + set(SYSROOT_ARCH "arm64") + endif() + + if(EXISTS "${WEBRTC_INSTALL_DIR}/lib/${WEBRTC_LIB}") + set(SYSROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}") + else() + set(SYSROOT_PATH "${WEBRTC_SRC_DIR}/src/build") + endif() execute_process( - COMMAND find ${SYSROOT_PATH} -iname libm-*.so + COMMAND find "${SYSROOT_PATH}/linux/debian_bullseye_${SYSROOT_ARCH}-sysroot" -iname libm-*.so WORKING_DIRECTORY "${WEBRTC_SRC_DIR}" OUTPUT_VARIABLE COMMAND_OUTPUT ERROR_VARIABLE COMMAND_ERROR @@ -122,8 +147,6 @@ set(WEBRTC_BUILD out/${TARGET_CPU}) set(WEBRTC_LIB_PATH ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/${WEBRTC_LIB}) set(WEBRTC_LIB_PATH_INSTALLED ${WEBRTC_INSTALL_DIR}/lib/${WEBRTC_LIB}) -set(WEBRTC_CLANG "true") - file(TO_CMAKE_PATH "${WEBRTC_DIR}" WEBRTC_DIR) file(TO_CMAKE_PATH "${WEBRTC_INSTALL_DIR}" WEBRTC_INSTALL_DIR) file(TO_CMAKE_PATH "${WEBRTC_LIB_PATH}" WEBRTC_LIB_PATH) @@ -133,8 +156,10 @@ message(STATUS "WebRTC checkout path: ${WEBRTC_DIR}") message(STATUS "WebRTC checkout branch: ${WEBRTC_BRANCH}") message(STATUS "WebRTC target: ${SOURCE_TARGET} ${TARGET_CPU}") message(STATUS "WebRTC build type: ${CMAKE_BUILD_TYPE}") +message(STATUS "WebRTC use custom libcxx: ${CUSTOM_LIBCXX}") message(STATUS "WebRTC install path: ${WEBRTC_INSTALL_DIR}") + if(EXISTS "${WEBRTC_LIB_PATH_INSTALLED}") set(TARGET_INC_DIR ${WEBRTC_INSTALL_DIR}/include) set(TARGET_LINK_LIB ${WEBRTC_LIB_PATH_INSTALLED}) @@ -151,7 +176,7 @@ else() set(TARGET_LIBCPP_ABI_INC_DIR ${WEBRTC_SRC}/third_party/libc++abi/src/include) endif() -if(LINUX OR WIN32) +if((LINUX AND NOT TARGET_CPU MATCHES "^arm") OR WIN32) target_include_directories(${PROJECT_NAME} PUBLIC ${TARGET_LIBCPP_BUILDTOOLS_INC_DIR}) target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${TARGET_LIBCPP_INC_DIR} ${TARGET_LIBCPP_ABI_INC_DIR}) @@ -254,7 +279,30 @@ if (PATCHES) endif() message(STATUS "WebRTC: generate") -set(COMPILE_ARGS "target_cpu=\"${TARGET_CPU}\" is_clang=${WEBRTC_CLANG} is_debug=false is_component_build=false treat_warnings_as_errors=false rtc_build_tools=false rtc_use_perfetto=false rtc_use_pipewire=false rtc_enable_protobuf=false rtc_build_examples=false rtc_include_tests=false use_rtti=true rtc_use_h264=true use_custom_libcxx=true symbol_level=0") +set(COMPILE_ARGS "target_cpu=\"${TARGET_CPU}\" \ +use_custom_libcxx=${CUSTOM_LIBCXX} \ +is_clang=true \ +is_debug=false \ +is_component_build=false \ +treat_warnings_as_errors=false \ +rtc_build_tools=false \ +rtc_use_perfetto=false \ +rtc_use_pipewire=false \ +rtc_enable_protobuf=false \ +rtc_build_examples=false \ +rtc_include_tests=false \ +use_rtti=true \ +rtc_use_h264=true \ +symbol_level=0") + +if(LINUX) + if(${TARGET_CPU} STREQUAL "arm") + set(COMPILE_ARGS "${COMPILE_ARGS} custom_toolchain=\"//build/toolchain/linux:clang_arm\"") + elseif(${TARGET_CPU} STREQUAL "arm64") + set(COMPILE_ARGS "${COMPILE_ARGS} custom_toolchain=\"//build/toolchain/linux:clang_arm64\"") + endif() +endif() + execute_command( COMMAND gn gen ${WEBRTC_BUILD} --args=${COMPILE_ARGS} WORKING_DIRECTORY "${WEBRTC_SRC}" @@ -269,41 +317,43 @@ execute_command( if(LINUX) sysroot_link() - # Collect lib++ objects - file(GLOB_RECURSE LibCPP_OBJS - ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/buildtools/third_party/libc++/libc++/*.o - ) - # Collect lib++abi objects - file(GLOB_RECURSE LibCPP_ABI_OBJS - ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/buildtools/third_party/libc++abi/libc++abi/*.o - ) - # Create static libraries - execute_command( - COMMAND ${CMAKE_AR} rcs ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++.a ${LibCPP_OBJS} - ) - execute_command( - COMMAND ${CMAKE_AR} rcs ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++abi.a ${LibCPP_ABI_OBJS} - ) - # Install libc++ and libc++abi headers and libraries - install( - FILES - "${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++.a" - "${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++abi.a" - DESTINATION - "${WEBRTC_INSTALL_DIR}/lib" - ) - install( - DIRECTORY "${WEBRTC_SRC}/third_party/libc++/src/include" - DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++" - ) - install( - DIRECTORY "${WEBRTC_SRC}/buildtools/third_party/libc++/" - DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++" - ) - install( - DIRECTORY "${WEBRTC_SRC}/third_party/libc++abi/src/include" - DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++abi" - ) + if(LINUX AND NOT TARGET_CPU MATCHES "^arm") + # Collect lib++ objects + file(GLOB_RECURSE LibCPP_OBJS + ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/buildtools/third_party/libc++/libc++/*.o + ) + # Collect lib++abi objects + file(GLOB_RECURSE LibCPP_ABI_OBJS + ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/buildtools/third_party/libc++abi/libc++abi/*.o + ) + # Create static libraries + execute_command( + COMMAND ${CMAKE_AR} rcs ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++.a ${LibCPP_OBJS} + ) + execute_command( + COMMAND ${CMAKE_AR} rcs ${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++abi.a ${LibCPP_ABI_OBJS} + ) + # Install libc++ and libc++abi headers and libraries + install( + FILES + "${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++.a" + "${WEBRTC_SRC}/${WEBRTC_BUILD}/obj/libc++abi.a" + DESTINATION + "${WEBRTC_INSTALL_DIR}/lib" + ) + install( + DIRECTORY "${WEBRTC_SRC}/third_party/libc++/src/include" + DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++" + ) + install( + DIRECTORY "${WEBRTC_SRC}/buildtools/third_party/libc++/" + DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++" + ) + install( + DIRECTORY "${WEBRTC_SRC}/third_party/libc++abi/src/include" + DESTINATION "${WEBRTC_INSTALL_DIR}/include/third_party/libc++abi" + ) + endif() elseif(WIN32) # Collect lib++ objects file(GLOB_RECURSE LibCPP_OBJS diff --git a/webrtc-jni/src/main/cpp/toolchain/aarch32-linux-clang.cmake b/webrtc-jni/src/main/cpp/toolchain/aarch32-linux-clang.cmake new file mode 100644 index 00000000..0210b7ed --- /dev/null +++ b/webrtc-jni/src/main/cpp/toolchain/aarch32-linux-clang.cmake @@ -0,0 +1,17 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_C_COMPILER /opt/clang/bin/clang) +set(CMAKE_CXX_COMPILER /opt/clang/bin/clang++) +set(CMAKE_AR /opt/clang/bin/llvm-ar) + +set(TARGET_TRIPLE arm-linux-gnueabihf) + +set(CMAKE_C_FLAGS "--target=${TARGET_TRIPLE} -march=armv7-a -mfloat-abi=hard -mfpu=neon") +set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -v -Wl,--verbose") + +foreach(LINKER SHARED_LINKER) + set(CMAKE_${LINKER}_FLAGS "-fuse-ld=lld -Wl,-s -v -Wl,--verbose") +endforeach() + +set(TARGET_CPU "arm") \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/toolchain/aarch64-linux-clang.cmake b/webrtc-jni/src/main/cpp/toolchain/aarch64-linux-clang.cmake new file mode 100644 index 00000000..beeb17f4 --- /dev/null +++ b/webrtc-jni/src/main/cpp/toolchain/aarch64-linux-clang.cmake @@ -0,0 +1,17 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) +set(CMAKE_C_COMPILER /opt/clang/bin/clang) +set(CMAKE_CXX_COMPILER /opt/clang/bin/clang++) +set(CMAKE_AR /opt/clang/bin/llvm-ar) + +set(TARGET_TRIPLE aarch64-linux-gnu) + +set(CMAKE_C_FLAGS "--target=${TARGET_TRIPLE}") +set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -v -Wl,--verbose") + +foreach(LINKER SHARED_LINKER) + set(CMAKE_${LINKER}_FLAGS "-fuse-ld=lld -Wl,-s -v -Wl,--verbose") +endforeach() + +set(TARGET_CPU "arm64") \ No newline at end of file diff --git a/webrtc-jni/src/main/cpp/toolchain/aarch64-linux-gnu.cmake b/webrtc-jni/src/main/cpp/toolchain/aarch64-linux-gnu.cmake index 031f6f8c..e6c3dc64 100644 --- a/webrtc-jni/src/main/cpp/toolchain/aarch64-linux-gnu.cmake +++ b/webrtc-jni/src/main/cpp/toolchain/aarch64-linux-gnu.cmake @@ -1,5 +1,5 @@ set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_SYSTEM_PROCESSOR aarch64) set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc) set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++) diff --git a/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake b/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake index af407568..b942380d 100644 --- a/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake +++ b/webrtc-jni/src/main/cpp/toolchain/x86_64-linux-clang.cmake @@ -5,10 +5,10 @@ set(CMAKE_CXX_COMPILER /opt/clang/bin/clang++) set(CMAKE_AR /opt/clang/bin/llvm-ar) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++ -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -v -Wl,--verbose") foreach(LINKER SHARED_LINKER) - set(CMAKE_${LINKER}_FLAGS "-fuse-ld=lld -Wl,-s") + set(CMAKE_${LINKER}_FLAGS "-fuse-ld=lld -Wl,-s -v -Wl,--verbose") endforeach() set(TARGET_CPU "x64")