[cmake-developers] Safe source list GLOBs

Matthew Woehlke matthew.woehlke at kitware.com
Wed May 29 16:59:22 EDT 2013


On 2013-05-28 21:23, Wojciech Knapik wrote:
> On Fri, May 24, 2013 at 11:21:57AM -0400, Matthew Woehlke wrote:
>> GLOB is just one of many things that will surprise you when working with
>> CMake if you don't understand the difference between the configure and
>> build passes.
>
> I've written quite a bit of CMake code in the past 6 months and so far
> that's the only thing that really surprised me.

execute_process? That's at least the main other one I always have to be 
careful about.

> I do understand the distinction between calling cmake and make and I
> understood from the start when variables are evaluated and such, but I
> just assumed that globs are propagated to the generated build system,
> because a) why not ? b) what's the point of globs if they aren't ?
>
> Imagine my surprise...

Actually, I find your surprise very surprising. You say you understand 
that setting and using variables happens at configure time. Well, 
file(GLOB) populates a variable... so why would you expect those 
variables to be somehow magically special?

> I don't think we need to be concerned about adding a few miliseconds to
> a no-op build, even if that constitutes a major percentage increase.

If that was true (and *especially* if the relative cost was 
non-trivial), ninja probably would not exist. These things add up... a 
few ms here, a few ms there, and suddenly it takes many seconds to build 
even a moderately large project set, that could otherwise be built in 
barely a second (if that). For that matter, even if it made a difference 
of 'only' 100 ms (say, in something the size of VTK), I would consider 
that a lot.

> * A feature enabling glob re-expansion on each call to the build tool
> could be switched off by default

As previously stated, there are really only two ways to do this 
correctly. One is to just always re-run CMake, which is unacceptable for 
any project of more than trivial size. The other is to teach CMake to 
reevaluate its globs and reevaluate if it needs to reconfigure. If this 
is even *possible* across build managers, it is probably not easy, but 
if you want to write a patch for that, I feel confident it will be 
considered.

-- 
Matthew




More information about the cmake-developers mailing list