[CMake] Set variable value based on generated files

Michael Wild themiwi at gmail.com
Tue Jun 1 10:48:49 EDT 2010


On 1. Jun, 2010, at 16:23 , Hariharan wrote:

> First off, I apologize if this is a very newbie-level question.
> I need to set the value of a variable based on based on generated files,
> using the "file" command. Something like:
> file(GLOB varFoo "*.cpp")
> 
> Here the cpp files are generated, so the value of varFoo comes up as empty
> when the build runs the first time. Is there any way to add a dependency on
> the file generation step to the "file" command?

Such a design is very likely to never work properly. Always try very hard to avoid file(GLOB). Presumably you are using ADD_CUSTOM_COMMAND to generate the files, right? So you should be able to infer the names of the generated files. It might be a bit more work to program, but is definitely worth the effort.

The problem with file(GLOB) is that CMake is a Meta-buildsystem which generates a build-systems for various generators. This also means that CMake will not be able to tell when you add or remove files, requiring you to remember to re-run CMake by hand.

Michael



More information about the CMake mailing list