> However, you can trigger on nimcache/myproject.json if Nim updates this file 
> after each build. It's a bit coarse though. I solved it by forcing the Nim 
> build each time because cmake doesn't know about if I change any library 
> files either.

Good point! I created a PR to help with this. Initially I modified the json 
build cache file logic to only write the file on changes. However, you'd still 
need to do post processing of the json file, which isn't great in CMake.

Instead I went with generating a list of newline separate C source files that 
works nicely with CMake: <https://github.com/nim-lang/Nim/pull/20950>

> I'm not an expert at cmake and perhaps what you describe is possible if you 
> dwell deep enough within the cmake world. Normally cmake want to know about 
> files when generating the makefile target. It cannot create rules for 
> filenames it doesn't know.

I got a working example with the esp-idf library and the above PR!

Here's the setup:
    
    
    set(CDEPS "${CMAKE_CURRENT_LIST_DIR}/.nimcache/main.cdeps")
    set(NIMBASE "${CMAKE_CURRENT_LIST_DIR}/.nimcache/nimbase.h")
    
    set_directory_properties(PROPERTIES CMAKE_CONFIGURE_DEPENDS ${CDEPS})
    file(STRINGS ${CDEPS} CFILES ENCODING UTF-8)
    idf_component_register(SRCS "${CFILES}"
                           INCLUDE_DIRS ""
                           REQUIRES lwip newlib nvs_flash mdns pthread 
app_update i2cdev)
    
    
    
    Run

Running it with `nim c --compileOnly ... && cd build/ && ninja` only rebuilds 
the C files which changed, and will call CMake configure stage if the input 
`.cdeps` changes.

Reply via email to