Check the [backend intergration](https://nim-lang.org/docs/backends.html) page 
in the manual. It's much easier doing the opposite IMO (Nim calling C/C++) and 
you generally do not need CMake for this as you can tell Nim where to link and 
what headers to use in your Nim code. Depends on what you're wrapping.

I'd do something like this if using cmake:
    
    
    add_custom_command(
        OUTPUT "${NIM_EXE_PATH}"
        COMMAND "${NIMBLE}" c --out:"${NIM_EXE_PATH}" "${NIM_PROJECT}"
        DEPENDS "${NIM_PROJECT}"
        WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
    )
    add_custom_target(
        nimbuild
        DEPENDS "${NIM_EXE_PATH}"
        COMMENT "Building Nim project"
    )
    
    add_executable(project IMPORTED GLOBAL)
    set_target_properties(project PROPERTIES IMPORTED_LOCATION 
"${NIM_EXE_PATH}")
    add_dependencies(project nimbuild)
    
    
    Run

A lot was omitted for this example but you would also pass your C/C++ target's 
headers, libs, defines to the nim compiler, which you can do via cmake 
generator expressions.

Reply via email to