1 cmake_minimum_required(VERSION 3.14)
2 project(onde_inference_plugin VERSION 0.1.0 LANGUAGES CXX)
3
4 # ── Flutter plugin boilerplate ────────────────────────────────────────────────
5 set(PLUGIN_NAME "onde_inference_plugin")
6
7 # ── Rust source directory ─────────────────────────────────────────────────────
8 # CMakeLists.txt lives in windows/, so ../rust resolves to the sibling rust/ dir.
9 set(RUST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../rust")
10
11 # ── Determine build profile ───────────────────────────────────────────────────
12 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
13 set(CARGO_PROFILE "debug")
14 set(CARGO_PROFILE_FLAG "")
15 else()
16 set(CARGO_PROFILE "release")
17 set(CARGO_PROFILE_FLAG "--release")
18 endif()
19
20 # ── Output paths for the compiled Rust DLL ───────────────────────────────────
21 # On Windows, cargo cdylib outputs are named without a "lib" prefix:
22 # onde_inference_dart.dll (not libonde_inference_dart.dll)
23 set(RUST_DLL
24 "${RUST_DIR}/target/${CARGO_PROFILE}/onde_inference_dart.dll"
25 )
26 set(RUST_IMPLIB
27 "${RUST_DIR}/target/${CARGO_PROFILE}/onde_inference_dart.dll.lib"
28 )
29
30 # ── Custom build step: invoke cargo ──────────────────────────────────────────
31 # Requires Rust + the current host toolchain (msvc or gnu) to be on PATH.
32 # For CUDA builds, append --features cuda to CARGO_PROFILE_FLAG.
33 add_custom_command(
34 OUTPUT "${RUST_DLL}" "${RUST_IMPLIB}"
35 COMMAND cargo build
36 ${CARGO_PROFILE_FLAG}
37 --manifest-path "${RUST_DIR}/Cargo.toml"
38 WORKING_DIRECTORY "${RUST_DIR}"
39 COMMENT "Building onde_inference_dart Rust bridge (${CARGO_PROFILE})…"
40 VERBATIM
41 )
42
43 add_custom_target(onde_inference_dart_cargo_build ALL
44 DEPENDS "${RUST_DLL}"
45 )
46
47 # ── Import the Rust DLL as a pre-built shared library ───────────────────────
48 add_library(onde_inference_dart SHARED IMPORTED GLOBAL)
49 set_target_properties(onde_inference_dart PROPERTIES
50 IMPORTED_LOCATION "${RUST_DLL}"
51 IMPORTED_IMPLIB "${RUST_IMPLIB}"
52 )
53 add_dependencies(onde_inference_dart onde_inference_dart_cargo_build)
54
55 # ── Flutter plugin shared library ────────────────────────────────────────────
56 add_library(${PLUGIN_NAME} SHARED
57 "onde_inference_plugin.cpp"
58 )
59
60 apply_standard_settings(${PLUGIN_NAME})
61
62 target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
63
64 target_include_directories(${PLUGIN_NAME} INTERFACE
65 "${CMAKE_CURRENT_SOURCE_DIR}/include"
66 )
67
68 target_link_libraries(${PLUGIN_NAME} PRIVATE
69 flutter
70 flutter_wrapper_plugin
71 onde_inference_dart
72 )
73
74 add_dependencies(${PLUGIN_NAME} onde_inference_dart_cargo_build)
75
76 # ── Copy the Rust DLL next to the Flutter runner executable ──────────────────
77 # Flutter's build system picks up files installed to the install prefix, so
78 # we install the DLL there so it is packaged with the final app bundle.
79 install(FILES "${RUST_DLL}"
80 DESTINATION "${CMAKE_INSTALL_PREFIX}"
81 )
82
83 # ── Bundled libraries declaration ─────────────────────────────────────────────
84 # Tells the Flutter tooling to bundle these DLLs with the distributed app.
85 set(onde_inference_plugin_bundled_libraries
86 "${RUST_DLL}"
87 PARENT_SCOPE
88 )