Using the JSON parser of CMake you can do this:
    
    
    # Read the nimcache JSON file to get the source files
    set(NimSources "")
    file(READ "${NIMCACHE_JSON_FILE}" NIMCACHE_JSON_DATA)
    string(JSON cfilelength LENGTH "${NIMCACHE_JSON_DATA}" compile)
    math(EXPR cfilelength "${cfilelength} - 1")
    foreach(IDX RANGE ${cfilelength})
        string(JSON CUR_FILE GET "${NIMCACHE_JSON_DATA}" compile ${IDX} 0)
        list(APPEND NimSources ${CUR_FILE})
    endforeach()
    
    # Suppress gcc warnings for nim-generated files
    set_source_files_properties(${NimSources} PROPERTIES COMPILE_OPTIONS "-w")
    add_executable(${OUTPUT_NAME} ${NimSources})
    
    
    Run

See this 
[CMakeLists.txt](https://github.com/daniel-j/nim-picosdk/blob/6a702c6a8874768dd197b198556e53b455404975/src/picostdlib/build_utils/template/csource/CMakeLists.txt)
 for a real-world example (Pico SDK in Nim). In my case, during the initial 
CMake configure it doesn't run because Nim code hasn't been compiled yet (see 
if(EXISTS imports.cmake), which is generated using a nimble hook)

Reply via email to