[CMake] Technique for generating projects that depend ongenerated sources
Steve Huston
shuston at riverace.com
Tue Mar 3 11:21:10 EST 2009
Thanks very much for all the hints - I appreciate it.
> -----Original Message-----
> From: cmake-bounces at cmake.org
> [mailto:cmake-bounces at cmake.org] On Behalf Of Eric Noulard
>
> 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".
Exactly.
> I did use (in my pre-CMake era) re-entrant makefiles
> precisely for this kind of issue.
Right - that's what I'm converting from.
> > 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.
Yes, I've put in code to try that and it works well.
> 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
Right - I'm doing this now.
> 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 hope this works... I'm sure it will when using make; when I tried
something like this with Microsoft Visual Studio, cmake choked because
it couldn't update macros or something like that.
> > 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?
It prevents regenerating the generated sources unless the spec(s)
change. I've also added checks if the generator itself changes as
well.
I think this is well in hand, at least for now.
Thanks!
-Steve
--
Steve Huston, Riverace Corporation
Check out my networked programming blog at
http://stevehuston.wordpress.com/
More information about the CMake
mailing list