[cmake-developers] RFC: add version to project() call
Alexander Neundorf
neundorf at kde.org
Sun Jan 19 15:23:13 EST 2014
On Wednesday 15 January 2014, Matthew Woehlke wrote:
> On 2014-01-15 16:25, Alexander Neundorf wrote:
> > On Wednesday 15 January 2014, Alexander Neundorf wrote:
> >> 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.
> >
> > I could also add more logic, to try to detect if PROJECT_VERSION has been
> > set manually, e.g. project() could reset PROJECT_VERSION only if it has
> > the same value as ${${ParentProjectName}_VERSION}. Then it would only
> > break if there was a manual set(PROJECT_VERSION ...) before a project()
> > call without VERSION, and if that manually set version was the same as
> > the version in the "parent project".
>
> IMHO your last suggestion (very good idea, btw!) is more than adequate,
> especially given the original weakness of my "objection" (which was
> always more along the lines of "did you consider this case, and should
> we worry about it?").
This is now in the AddVersionToProjectCommand branch on git stage.
Please have a close look at it.
I'm not sure I like that somewhat magic behaviour how it decides whether to
unset() the variables or not.
There will be problems with this very rarely, but when the circumstances
occur, it may be quite hard to figure out.
I.e. it could happen when the version number of a sub-project changes, then
suddenly PROJECT_VERSION could be empty afterwards:
CMakeLists.txt:
project(Parent VERSION 1.0.0)
add_subdirector(sub)
sub/CMakeLists.txt:
- set(PROJECT_VERSION 0.0.1)
+ set(PROJECT_VERSION 1.0.0)
project(Foo)
message(STATUS "Version: ${PROJECT_VERSION})
Such a patch would have the effect that PROJECT_VERSION in suddenly empty in
the message() call.
I would probably prefer to not touch the PROJECT_VERSION variables at all if
VERSION is not used, then there are at least no (very rare) surprises or
sudden breakages.
Alex
More information about the cmake-developers
mailing list