nandi/vflutter_ffipublic Fork 0
472eb493bac94bdcb79a38829ccca0c541256fef
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 yesterday1# 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 yesterday3cmake_minimum_required(VERSION 3.15)
Replace V with Nim 472eb49 nandithebull yesterday4project(nimflutter LANGUAGES C)
Initial commit: V -> Flutter FFI plugin ad0ccda nandi yesterday5
Replace V with Nim 472eb49 nandithebull yesterday6find_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 yesterday8
Replace V with Nim 472eb49 nandithebull yesterday9set(NF_SRC "${CMAKE_CURRENT_LIST_DIR}/nimflutter.nim")
Initial commit: V -> Flutter FFI plugin ad0ccda nandi yesterday10
Replace V with Nim 472eb49 nandithebull yesterday11# 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 yesterday13# This keeps the NDK / MSVC / clang in charge of ABI, sysroot and flags.
Replace V with Nim 472eb49 nandithebull yesterday14#
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 yesterday29
Replace V with Nim 472eb49 nandithebull yesterday30file(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 yesterday34
Replace V with Nim 472eb49 nandithebull yesterday35add_library(nimflutter SHARED ${NF_GENERATED_C})
Initial commit: V -> Flutter FFI plugin ad0ccda nandi yesterday36
Replace V with Nim 472eb49 nandithebull yesterday37# 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 yesterday40
Replace V with Nim 472eb49 nandithebull yesterday41target_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 yesterday46#
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 yesterday52 target_compile_options(nimflutter PRIVATE /O2)
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull yesterday53else()
Replace V with Nim 472eb49 nandithebull yesterday54 target_compile_options(nimflutter PRIVATE
Add a Mandelbrot example app, and a V kernel worth demonstrating 81540bb nandithebull yesterday55 -O2 -w -fPIC -Wno-int-conversion -Wno-incompatible-pointer-types)
Initial commit: V -> Flutter FFI plugin ad0ccda nandi yesterday56endif()
57
58if(ANDROID)
Replace V with Nim 472eb49 nandithebull yesterday59 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 yesterday66endif()
67
Replace V with Nim 472eb49 nandithebull yesterday68set_target_properties(nimflutter PROPERTIES
69 OUTPUT_NAME "nimflutter"
Initial commit: V -> Flutter FFI plugin ad0ccda nandi yesterday70 C_VISIBILITY_PRESET hidden)