Skip to content

Declare the project version in CMake and generate a version header - #561

Open
paceholder wants to merge 4 commits into
masterfrom
add-project-version
Open

paceholder wants to merge 4 commits into
masterfrom
add-project-version

Conversation

@paceholder

Copy link
Copy Markdown
Owner

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation/refactoring

Description

The library had no version in its sources. The only version was the git tag, so a copy without .git (a zip download, vendored files) could not tell its version. docs/conf.py still said release = '3.0'. There was also no way to ask for a version with find_package or #if.

The version is now written once, in project() of CMakeLists.txt. Everything else comes from it.

Commits, each builds and passes on its own:

  1. Declare the project version and install a package version file. project(QtNodesLibrary VERSION 3.2.1 LANGUAGES CXX). It installs QtNodesConfigVersion.cmake with SameMajorVersion, so find_package(QtNodes 3.1) accepts 3.2.1 and find_package(QtNodes 4.0) rejects it. It also sets VERSION and SOVERSION on the target.
  2. Generate a version header from the project version. QtNodes/Version defines QTNODES_VERSION_MAJOR, _MINOR, _PATCH, QTNODES_VERSION_STR, QTNODES_VERSION_CHECK(a, b, c) and QTNODES_VERSION. The header is generated into the build directory and installed.
  3. Test the generated version macros.
  4. Take the docs version from the project version. docs/conf.py reads the version from CMakeLists.txt. Doxygen gets PROJECT_NUMBER from PROJECT_VERSION.

To release: change the number in project(), commit, and create the tag. Between releases master shows the last released version.

Shared builds now get SOVERSION equal to the major version. On Linux the library file becomes libQtNodes.so.3 with a libQtNodes.so link. Static and Windows builds are not affected.

Testing

  • Qt version tested: Qt 6.12.0, macOS arm64 (Apple Clang), offscreen platform
  • Existing tests still pass (902 assertions in 87 test cases)
  • Added tests for new functionality (commit 3)
  • Checked by hand: cmake --install, then find_package(QtNodes 3.1 REQUIRED) finds 3.2.1 and find_package(QtNodes 4.0 REQUIRED) reports an incompatible version. The installed Version.hpp is present. The regex in conf.py returns 3.2.1.
  • Not tested: Qt 5, Windows, Linux, building the Sphinx docs. CI covers the first three.

Breaking changes?

No.

Related issue

Part of the release housekeeping. Found while answering #464, where the reporter could not tell which version he had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant