[CMake] How to deal with generated source files (w/ dependency tracking) for globs

Eric Wing ewmailing at gmail.com
Mon Apr 4 19:36:10 EDT 2016


Hi, this is kind of a side problem that was asked of me. I'm not sure
how many hoops I actually want to jump through to solve this. But,
here's the situation.

I have a really nice, traditional C based project in CMake. All my
dependency tracking works really well for cross-platform and IDE
integration and even have resources/bundling/codesigning working
nicely in the single build step.

Now somebody throws me a curve ball and wants to use the Nim language.
The specifics of the Nim language itself is not that important to this
topic, but the key piece of information is that the Nim compiler can
generate C files as output.

So the question is, how can I invoke Nim to compile a list of
pre-known Nim source files, and then slurp in the generated output C
files and build them as part of my normal CMake build process.

The curve ball is this: I don't know all the names or how many files
the Nim compiler generates. If I know all the names beforehand, I
think I know how to deal with this situation. But instead, I get a
directory of C files. The names seem to be dependent on which library
features were used and also what the user's source files were named. I
suspect the standard library could theoretically change too so future
versions of Nim may have different files.

I know file globs with CMake don't auto-track changes and I think the
problem gets more trickier because of the indirection to invoke Nim.
(i.e. When I first glob the files, the directory is empty, then the
Nim compiler is invoked later and the files appear, but it is too late
for CMake to see without a regeneration).

Anyway, I was wondering what the best approach is.

Thanks,
Eric


More information about the CMake mailing list