[CMake] Technique for generating projects that depend on generated sources

Eric Noulard eric.noulard at gmail.com
Sun Mar 1 16:15:57 EST 2009


2009/3/1 Alexander Neundorf <a.neundorf-work at gmx.net>:
> On Friday 27 February 2009, Steve Huston wrote:
>> Thanks for the advice, Bill.
>>
>> My situation is somewhat different, though. The output source files
>> are not known ahead of time. Thus, the general scheme is:
>>
>> - build runs the source generator; one of the outputs is a file
>> containing the names of the generated sources.
>> - rerun cmake to regenerate the build now that the complete list of
>> sources is known.
>> - rerun the build with the complete set of sources
>
> Oh, this is ugly.

I don't think that's much of ugly.
It's a classical "generated source" problem with the may be
not so common "I don't know the generated source file names".

I did use (in my pre-CMake era) re-entrant makefiles precisely for this
kind of issue.

> The purpose of cmake is to generate project files which contain information
> about which files need to be compiled and how. This happens at cmake time.
> Then these project files are read at build time and the files are built.
> Now if the names of the files which should be built are not known at cmake
> time, cmake can't generate rules for them in the project files.
>
> Can you run the source generator at cmake time ?

Yes you are right and I miss that,
if the generator is launched at CMake time it may help a lot.
Moreover I would say that the "source file list" generated by the generator
may be some kind of CMake file, let's say

generated_source.cmake

then one may

INCLUDE(generated_source.cmake OPTIONAL) in the CMakeLists.txt

then I CMake is clever enough:

0) during the first CMake run the optionnally included file is created
1) when launching the build after that the
    cmake_check_build_system  rule will notice that
    "generated_source.cmake" appeared and will automatically
    relaunch CMake and then
    the build.

Thus you would have the usual CMake + build step with an extra
CMake run triggered by the build step itself.

I've not tried so I may be wrong concerning the cleverness of a
INCLUDE(generated_source.cmake OPTIONAL)
statement.

> This would help against the problem. You can guard the generation e.g. with
> if(file1 NEWER_THAN file2)

I don't understand that point?

-- 
Erk


More information about the CMake mailing list