[cmake-developers] RFC: add version to project() call

Alexander Neundorf neundorf at kde.org
Wed Jan 15 12:30:58 EST 2014


On Wednesday 15 January 2014, Matthew Woehlke wrote:
> On 2014-01-14 18:00, Alexander Neundorf wrote:
> > On Tuesday 14 January 2014, Matthew Woehlke wrote:
> >> While that sounds good for 99.9% of cases, what about the case of
> >> project A that includes project B, where B is not updated, but A decides
> >> to start using project(...VERSION...). Now if B was using
> >> PROJECT_VERSION internally, it is broken. (Note that I'm implying that B
> >> is e.g. a separate repository that may not be "as easy to update/fix as
> >> A".)
> > 
> > You mean
> > CMakeLists.txt:
> > 
> > project(Foo VERSION 1.2.3)
> > 
> > ....
> > 
> > add_subdir(B)
> > 
> > B/CMakeLists.txt:
> > 
> > set(PROJECT_VERSION "4.5.6")
> > project(Bar)
> > 
> > 
> > Indeed.
> > In that case, PROJECT_VERSION will be unset afterwards.
> 
> Exactly. I wanted to point it out, but as that's probably unusual, I
> would be okay ignoring that case.
> 
> > If it would be
> > 
> > B/CMakeLists.txt:
> > 
> > 
> > project(Bar)
> > set(PROJECT_VERSION "4.5.6")
> > 
> > everything is fine.
> 
> ...until B/C/CMakeLists.txt also calls project() :-). Basically, you
> (can) get into trouble if you "update" your project to use
> project(VERSION) and also have an "external" sub-project that tries to
> use PROJECT_VERSION. However, as much as folks¹ occasionally bleat about
> this use case (having an embedded "external" project), I suspect it's
> not actually very common², and anyway there is only a problem when the
> sub-project *also* uses PROJECT_VERSION (which I suspect is also rare in
> general, and more so the intersection of the two).
> 
> Again, given the above, I've no objection to breaking that case, which
> may well only exist in the hypothetical sense with no 'in the wild'
> instances actually existing.

And, to actually produce the breakage, at some place the VERSION argument must 
have been added.
With the current state of my branch, this could be worked around by unsetting 
the guard variable:


project(Foo VERSION 1.2.3)
....

unset(CMAKE_PROJECT_VERSION_SET_BY_PROJECT_COMMAND)
add_subdir(B)

This way B would be protected from that change in behaviour.

Alex



More information about the cmake-developers mailing list