sony / flutter-elinux

Flutter tools for embedded Linux (eLinux)
BSD 3-Clause "New" or "Revised" License
429 stars 43 forks source link

Passing the FLUTTER_TARGET_PLATFORM flag to cmake #149

Closed cloudwebrtc closed 1 year ago

cloudwebrtc commented 1 year ago

Passing the FLUTTER_TARGET_PLATFORM flag to cmake to link the correct binary library when compiling.

flutter-elinux will have CMAKE_BUILD_TYPE and FLUTTER_TARGET_BACKEND_TYPE by default, but there is no way to know the architecture of the target app.

$ flutter-elinux run -d elinux-x11 -v --release
...
[   +2 ms] executing: [/home/parallels/flutter-webrtc/example/build/elinux/arm64/release/] 
cmake -DCMAKE_BUILD_TYPE=Release -DFLUTTER_TARGET_BACKEND_TYPE=x11 ...

flutter can get target architecture information through FLUTTER_TARGET_PLATFORM.

$ flutter run -d linux -v --release
...
[   +4 ms] executing: [build/linux/arm64/release/] 
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DFLUTTER_TARGET_PLATFORM=linux-arm64  ...
[  +24 ms] -- Architecture: aarch64, FLUTTER_TARGET_PLATFORM: linux-arm64

Use the FLUTTER_TARGET_PLATFORM flag to select the corresponding binary library. https://github.com/flutter-webrtc/flutter-webrtc/blob/main/linux/CMakeLists.txt#L45-L52