| Initial commit: V -> Flutter FFI plugin ad0ccda nandi 9h ago | 1 | # Shared CMake logic for every platform that builds the V library from source. |
| 2 | # Included by android/, linux/ and windows/. |
| 3 | cmake_minimum_required(VERSION 3.15) |
| 4 | project(vflutter LANGUAGES C) |
| 5 | |
| 6 | find_program(V_EXECUTABLE v REQUIRED |
| 7 | DOC "The V compiler. Set -DV_EXECUTABLE=/path/to/v to override.") |
| 8 | |
| 9 | set(VF_SRC "${CMAKE_CURRENT_LIST_DIR}/vflutter.v") |
| 10 | |
| 11 | # V cross-compiles by emitting C, so the reliable pattern is: |
| 12 | # V source -> C (V's job) C -> object/library (the platform's toolchain) |
| 13 | # This keeps the NDK / MSVC / clang in charge of ABI, sysroot and flags. |
| 14 | set(VF_GENERATED_C "${CMAKE_CURRENT_BINARY_DIR}/vflutter.gen.c") |
| 15 | |
| 16 | add_custom_command( |
| 17 | OUTPUT "${VF_GENERATED_C}" |
| 18 | COMMAND "${V_EXECUTABLE}" -shared -gc none -no-parallel -o "${VF_GENERATED_C}" "${VF_SRC}" |
| 19 | DEPENDS "${VF_SRC}" |
| 20 | COMMENT "v -shared -> C (${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})" |
| 21 | VERBATIM) |
| 22 | |
| 23 | add_library(vflutter SHARED "${VF_GENERATED_C}") |
| 24 | |
| 25 | target_include_directories(vflutter PUBLIC "${CMAKE_CURRENT_LIST_DIR}") |
| 26 | |
| 27 | # V's generated C is machine output: silence the noise, keep real errors. |
| Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 5h ago | 28 | # |
| 29 | # -O2 is set unconditionally, including in Debug. This library is a numeric |
| 30 | # kernel with no Dart-visible debugger story of its own, and at -O0 the |
| 31 | # Mandelbrot path runs several times slower than the equivalent Dart — which |
| 32 | # makes a debug run of the example wildly misrepresent the bridge. |
| 33 | if(MSVC) |
| 34 | target_compile_options(vflutter PRIVATE /O2) |
| 35 | else() |
| Initial commit: V -> Flutter FFI plugin ad0ccda nandi 9h ago | 36 | target_compile_options(vflutter PRIVATE |
| Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 5h ago | 37 | -O2 -w -fPIC -Wno-int-conversion -Wno-incompatible-pointer-types) |
| Initial commit: V -> Flutter FFI plugin ad0ccda nandi 9h ago | 38 | endif() |
| 39 | |
| 40 | # Boehm GC ships with V and is linked statically by the V toolchain on desktop; |
| 41 | # on Android it must come from the NDK-built copy. See tool/build_gc.sh. |
| 42 | if(ANDROID) |
| 43 | target_link_libraries(vflutter PRIVATE log) |
| 44 | endif() |
| 45 | |
| 46 | set_target_properties(vflutter PROPERTIES |
| 47 | OUTPUT_NAME "vflutter" |
| 48 | C_VISIBILITY_PRESET hidden) |