cmake_minimum_required(VERSION 3.14) project(my_timer_cpp_bindings CXX C) # The generated bindings target C++20: designated initializers and other # C++20 constructs are used throughout the emitted code. set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # MSVC defaults __cplusplus to 199711L regardless of the active /std:c++XX # level — the generated header's C++20 guard would then misfire. /Zc:__cplusplus # makes MSVC report the actual standard. Harmless on every other compiler. if(MSVC) add_compile_options(/Zc:__cplusplus) endif() # ── Locate the repository root (contains ffi.nimble) ───────────────────────── set(_search_dir "${CMAKE_CURRENT_SOURCE_DIR}") set(REPO_ROOT "") foreach(_i RANGE 10) if(EXISTS "${_search_dir}/ffi.nimble") set(REPO_ROOT "${_search_dir}") break() endif() get_filename_component(_search_dir "${_search_dir}" DIRECTORY) endforeach() if("${REPO_ROOT}" STREQUAL "") message(FATAL_ERROR "Cannot find repo root (no ffi.nimble in any ancestor)") endif() # Build the Nim dylib + vendored TinyCBOR (shared with the C backend). set(NIM_FFI_LIB my_timer) set(NIM_FFI_SRC ../timer.nim) include("${REPO_ROOT}/ffi/codegen/templates/nim_ffi_lib.cmake") add_library(my_timer_headers INTERFACE) target_include_directories(my_timer_headers INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(my_timer_headers INTERFACE my_timer tinycbor) if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp") add_executable(my_timer_example main.cpp) target_link_libraries(my_timer_example PRIVATE my_timer_headers) add_dependencies(my_timer_example my_timer_nim_lib) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") add_custom_command(TARGET my_timer_example POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${my_timer_RUNTIME_LIB}" "$" COMMENT "Staging my_timer.dll next to my_timer_example.exe") endif() endif()