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