|
| 1 | +# Building QtAVCore for OHOS on Windows |
| 2 | + |
| 3 | +QtAVCore and its repository-pinned FFmpeg dependency closure can be |
| 4 | +cross-compiled for OHOS arm64/API 23 directly on 64-bit Windows. WSL is not |
| 5 | +required. The supported Windows route uses PowerShell plus the native tools |
| 6 | +bundled with the OpenHarmony SDK installed by DevEco Studio. |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | + |
| 10 | +- 64-bit Windows and 64-bit PowerShell; |
| 11 | +- DevEco Studio with an OpenHarmony SDK containing `native/`; |
| 12 | +- Git and the repository's pinned `ffmpeg/vcpkg` submodule; |
| 13 | +- Visual Studio C++ Build Tools for vcpkg host utilities; |
| 14 | +- network access for source downloads when the vcpkg download/cache is empty. |
| 15 | + |
| 16 | +The scripts look for the SDK in this order: `-SdkRoot`, `OHOS_SDK_ROOT`, |
| 17 | +`OHOS_NDK`, `DEVECO_SDK_HOME`, then the normal DevEco Studio installation |
| 18 | +under `Program Files`. The target remains arm64-v8a/API 23 even when a newer |
| 19 | +compatible SDK is installed. |
| 20 | + |
| 21 | +Initialize vcpkg once from the repository root: |
| 22 | + |
| 23 | +```powershell |
| 24 | +git submodule update --init ffmpeg/vcpkg |
| 25 | +``` |
| 26 | + |
| 27 | +## Build FFmpeg dependencies |
| 28 | + |
| 29 | +Run the Windows OHOS dependency entry point: |
| 30 | + |
| 31 | +```powershell |
| 32 | +./ffmpeg/scripts/build-ohos.ps1 |
| 33 | +``` |
| 34 | + |
| 35 | +For a non-standard SDK or output location: |
| 36 | + |
| 37 | +```powershell |
| 38 | +./ffmpeg/scripts/build-ohos.ps1 ` |
| 39 | + -SdkRoot D:/OpenHarmony/Sdk/openharmony ` |
| 40 | + -InstallRoot D:/qtav-ohos/vcpkg_installed ` |
| 41 | + -WorkRoot D:/qtav-ohos/vcpkg-work |
| 42 | +``` |
| 43 | + |
| 44 | +`WorkRoot` must not contain spaces. DevEco normally resides below |
| 45 | +`C:\Program Files`; OpenSSL and FFmpeg invoke MSYS tools which cannot reliably |
| 46 | +consume that compiler path. The script therefore creates a stable, space-free |
| 47 | +SDK junction under the work root. It does not modify the installed SDK. Choose |
| 48 | +a different work root when intentionally switching between SDK installations. |
| 49 | + |
| 50 | +The default package database and target prefix are: |
| 51 | + |
| 52 | +```text |
| 53 | +ffmpeg/build/arm64-ohos-23-static/vcpkg_installed/ |
| 54 | +├── vcpkg/ |
| 55 | +└── arm64-ohos-23-static/ |
| 56 | +``` |
| 57 | + |
| 58 | +The FFmpeg overlay requires `--enable-ohcodec` on this triplet. The final |
| 59 | +verifier uses the SDK's `llvm-nm` to require both `ff_h264_oh_decoder` and |
| 60 | +`ff_hevc_oh_decoder` in `libavcodec.a`; a configure-time fallback to an |
| 61 | +OHCodec-disabled package is therefore an error. |
| 62 | + |
| 63 | +## Build and install QtAVCore |
| 64 | + |
| 65 | +The normal command builds missing dependencies, then configures, builds, and |
| 66 | +installs a shared Release SDK: |
| 67 | + |
| 68 | +```powershell |
| 69 | +./modern/scripts/build-ohos.ps1 |
| 70 | +``` |
| 71 | + |
| 72 | +The default output is `build/modern-ohos-shared/`, with its install tree under |
| 73 | +`build/modern-ohos-shared/install/`. To reuse an already verified dependency |
| 74 | +database without invoking vcpkg again: |
| 75 | + |
| 76 | +```powershell |
| 77 | +./modern/scripts/build-ohos.ps1 -SkipDependencies |
| 78 | +``` |
| 79 | + |
| 80 | +This skips compilation, not validation: `verify-install.cmake` still rejects |
| 81 | +an older dependency package that does not contain the required OHCodec decoder |
| 82 | +symbols. |
| 83 | + |
| 84 | +Build a static SDK with: |
| 85 | + |
| 86 | +```powershell |
| 87 | +./modern/scripts/build-ohos.ps1 ` |
| 88 | + -LibraryType Static ` |
| 89 | + -BuildDirectory build/modern-ohos-static |
| 90 | +``` |
| 91 | + |
| 92 | +Useful options include `-BuildType`, `-BuildTests`, `-BuildExamples`, |
| 93 | +`-InstallPrefix`, `-NoInstall`, and `-Parallel`. Cross-compiled tests and |
| 94 | +examples can be built on Windows but cannot be executed as Windows programs; |
| 95 | +runtime tests must be packaged in an OHOS application and run on a device. |
| 96 | + |
| 97 | +For an external CMake consumer, set `QtAVCore_DIR` to the installed |
| 98 | +`lib/cmake/QtAVCore` directory. The OHOS SDK intentionally restricts package |
| 99 | +searches to its sysroot, so `CMAKE_PREFIX_PATH` alone may not discover an SDK |
| 100 | +installed elsewhere on the Windows filesystem. |
| 101 | + |
| 102 | +The script explicitly chainloads the repository OHOS toolchain through vcpkg. |
| 103 | +Shared QtAVCore libraries receive `-Wl,-Bsymbolic` from the project CMake rules |
| 104 | +so the PIC static FFmpeg closure, including its AArch64 assembly, can be linked |
| 105 | +without interposable relocation failures. FFmpeg's pkg-config metadata supplies |
| 106 | +libsmb2, OpenSSL, dav1d, and the OHCodec system libraries to the final link. |
| 107 | + |
| 108 | +## Packaging and signing |
| 109 | + |
| 110 | +These scripts produce native libraries and CMake package metadata; they do not |
| 111 | +create or sign a HAP. Add the installed libraries to the application's |
| 112 | +`libs/arm64-v8a/` directory and configure the application certificate/signing |
| 113 | +in DevEco Studio. Device installation and authorization remain application |
| 114 | +integration steps. |
| 115 | + |
| 116 | +When diagnosing a manual CMake invocation, prefer the supported script. A |
| 117 | +compiler test that links Windows system libraries means the OHOS chainload |
| 118 | +toolchain was omitted. A shared-link `R_AARCH64_ADR_PREL_PG_HI21` failure means |
| 119 | +the QtAVCore OHOS `-Bsymbolic` rule was bypassed or removed. |
0 commit comments