nandi/vflutter_ffipublic Fork 0
4506a586d7400b00d732dcb97167be75ab41cab1
Commits
Clone
git clone https://git.rickub.com/nandi/vflutter_ffi.git
git clone ssh://git@rickub.com/nandi/vflutter_ffi.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

CMakeLists.txt · 70 lines · 2.6 KBCMake Blame HistoryRaw
Replace V with Nim 472eb49 nandithebull 8h ago1# Shared CMake logic for every platform that builds the Nim library from
2# source. Included by android/, linux/ and windows/.
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago3cmake_minimum_required(VERSION 3.15)
Replace V with Nim 472eb49 nandithebull 8h ago4project(nimflutter LANGUAGES C)
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago5
Replace V with Nim 472eb49 nandithebull 8h ago6find_program(NIM_EXECUTABLE nim REQUIRED
7 DOC "The Nim compiler. Set -DNIM_EXECUTABLE=/path/to/nim to override.")
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago8
Replace V with Nim 472eb49 nandithebull 8h ago9set(NF_SRC "${CMAKE_CURRENT_LIST_DIR}/nimflutter.nim")
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago10
Replace V with Nim 472eb49 nandithebull 8h ago11# Nim cross-compiles by emitting C, so the reliable pattern is:
12# Nim source -> C (Nim's job) C -> object/library (the toolchain's)
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago13# This keeps the NDK / MSVC / clang in charge of ABI, sysroot and flags.
Replace V with Nim 472eb49 nandithebull 8h ago14#
15# Nim writes one .c per module rather than a single file, and the set is only
16# known after it runs — so it runs at CONFIGURE time and the results are
17# globbed, instead of the add_custom_command a single-file emitter allows.
18set(NF_NIMCACHE "${CMAKE_CURRENT_BINARY_DIR}/nimcache")
19
20execute_process(
21 COMMAND "${NIM_EXECUTABLE}" c --compileOnly --nimcache:${NF_NIMCACHE}
22 --mm:arc -d:danger --threads:on --noMain "${NF_SRC}"
23 RESULT_VARIABLE NF_NIM_RESULT
24 OUTPUT_VARIABLE NF_NIM_OUTPUT
25 ERROR_VARIABLE NF_NIM_OUTPUT)
26if(NOT NF_NIM_RESULT EQUAL 0)
27 message(FATAL_ERROR "nim failed to emit C:\n${NF_NIM_OUTPUT}")
28endif()
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago29
Replace V with Nim 472eb49 nandithebull 8h ago30file(GLOB NF_GENERATED_C "${NF_NIMCACHE}/*.c")
31if(NF_GENERATED_C STREQUAL "")
32 message(FATAL_ERROR "nim produced no C in ${NF_NIMCACHE}")
33endif()
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago34
Replace V with Nim 472eb49 nandithebull 8h ago35add_library(nimflutter SHARED ${NF_GENERATED_C})
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago36
Replace V with Nim 472eb49 nandithebull 8h ago37# nimbase.h lives in Nim's own lib/, alongside the compiler.
38get_filename_component(NF_NIM_BIN "${NIM_EXECUTABLE}" DIRECTORY)
39get_filename_component(NF_NIM_ROOT "${NF_NIM_BIN}" DIRECTORY)
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago40
Replace V with Nim 472eb49 nandithebull 8h ago41target_include_directories(nimflutter PUBLIC
42 "${CMAKE_CURRENT_LIST_DIR}"
43 "${NF_NIM_ROOT}/lib")
44
45# Nim'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 10h ago46#
47# -O2 is set unconditionally, including in Debug. This library is a numeric
48# kernel with no Dart-visible debugger story of its own, and at -O0 the
49# Mandelbrot path runs several times slower than the equivalent Dart — which
50# makes a debug run of the example wildly misrepresent the bridge.
51if(MSVC)
Replace V with Nim 472eb49 nandithebull 8h ago52 target_compile_options(nimflutter PRIVATE /O2)
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 10h ago53else()
Replace V with Nim 472eb49 nandithebull 8h ago54 target_compile_options(nimflutter PRIVATE
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull 10h ago55 -O2 -w -fPIC -Wno-int-conversion -Wno-incompatible-pointer-types)
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago56endif()
57
58if(ANDROID)
Replace V with Nim 472eb49 nandithebull 8h ago59 target_link_libraries(nimflutter PRIVATE log)
60endif()
61
62# Nim's threading support needs pthreads where the platform has them.
63find_package(Threads)
64if(Threads_FOUND AND NOT ANDROID AND NOT WIN32)
65 target_link_libraries(nimflutter PRIVATE Threads::Threads)
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago66endif()
67
Replace V with Nim 472eb49 nandithebull 8h ago68set_target_properties(nimflutter PROPERTIES
69 OUTPUT_NAME "nimflutter"
Initial commit: V -> Flutter FFI plugin ad0ccda nandi 14h ago70 C_VISIBILITY_PRESET hidden)