4

Currently to create releases for our project, we're using Travis CI to upload binaries whenever a tag is created. We're using semantic versioning, so our tags have the form v<Major>.<Minor>.<Patch>. Our version number is set by CMake, and to avoid problems with it getting out of sync with the tag version number, we're using a simple script to extract the version number from the TRAVIS_TAG environment variable.

Our CMakeLists.txt looks something like this:

execute_process(COMMAND .travis/get_version_from_tag.sh major OUTPUT_VARIABLE MAJOR)
execute_process(COMMAND .travis/get_version_from_tag.sh minor OUTPUT_VARIABLE MINOR)
execute_process(COMMAND .travis/get_version_from_tag.sh patch OUTPUT_VARIABLE PATCH)
set(VERSION ${MAJOR}.${MINOR}.${PATCH})

# Using the version number later for packaging, etc...

set(CPACK_PACKAGE_MAJOR ${MAJOR})
set(CPACK_PACKAGE_MINOR ${MINOR})
set(CPACK_PACKAGE_PATCH ${PATCH})
INCLUDE(CPack)

I like this approach because it makes it very easy to publish releases, and there's no risk of forgetting to update the hard-coded version number in a file somewhere. On the other hand, I'm worried it might be a bit confusing since from a copy of the source code alone, it's impossible to know the version number.

Is this an overly complicated and confusing setup?

1 Answer 1

2

Not really, if the source code is obtained from the tagged branch, then its obvious which version is which!

You may have more difficulty if you're working on a branch, which is probably taken from trunk, or one taken from a tag so you won't necessarily know which version the source corresponds to. If you can find the version the source came from, then its no problem. IF you can't, then your devs just have to be a bit more careful. If your devs are sloppy then a file with the version number might help them but you probably have bigger problems in that case.

One place where you might want to include a version number in source is in a readme or changelog. Some people update this by hand (summarising changes) or generate it from your SCM, but I feel its still best to commit it to the source directory once its created as part of a build. If you do this, you will have the version number right at the top no matter which source branch you fetch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.