From 9d10824f3f4b41dafdfdf8eb80f0a4ccd0d8f40a Mon Sep 17 00:00:00 2001 From: Dmitry Pinaev Date: Sun, 29 Nov 2026 16:47:34 +0100 Subject: [PATCH] Make the project version one source of truth Also update the copyright years to 2026. --- AGENTS.md | 12 +++++ CITATION.cff | 19 ++++++++ CMakeLists.txt | 22 +++++++++- LICENSE.rst | 2 +- README.rst | 35 ++++++++++++--- cmake/CheckVersion.cmake | 28 ++++++++++++ cmake/Tag.cmake | 63 +++++++++++++++++++++++++++ cmake/Version.hpp.in | 13 ++++++ docs/Doxyfile.in | 2 +- docs/conf.py | 10 +++-- docs/getting-started/installation.rst | 21 +++++++++ include/QtNodes/Version | 1 + test/CMakeLists.txt | 6 +++ test/src/TestVersion.cpp | 22 ++++++++++ 14 files changed, 244 insertions(+), 12 deletions(-) create mode 100644 CITATION.cff create mode 100644 cmake/CheckVersion.cmake create mode 100644 cmake/Tag.cmake create mode 100644 cmake/Version.hpp.in create mode 100644 include/QtNodes/Version create mode 100644 test/src/TestVersion.cpp diff --git a/AGENTS.md b/AGENTS.md index 87d467a0d..918391aef 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -96,3 +96,15 @@ that include QtNodes choose their own standard. - Versions follow semver. A tag on a later commit must have a higher version than the tags before it. Never move or delete a published tag. - Branches: `master` (latest dev state) and `v3`. Older versions are tags (`1.0`, `2.*`). + +### Version + +- The only source of the version is `project(QtNodesLibrary VERSION x.y.z)` in `CMakeLists.txt`. + The version header, the package version file, the library version and the docs read it from + there. Do not write the version by hand anywhere else. +- `CITATION.cff` (`version` and `date-released`) and the git tag are copies that cannot be + generated. `cmake/CheckVersion.cmake` compares `CITATION.cff` with `project()`, and CTest runs + it. Add any new copy to that script. +- Change the version only to prepare a release, in any commit. Then run + `cmake -P cmake/Tag.cmake`. It creates the annotated tag from `project()` and refuses a version + that is not higher than every local and remote tag. Tag and push only when asked. diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 000000000..fe00394d6 --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,19 @@ +cff-version: 1.2.0 +message: "If you use QtNodes, please cite it with the version you used." +type: software +title: "QtNodes. Node Editor" +abstract: "A Qt-based C++ library for building node graph editors and data-flow editors." +authors: + - family-names: "Pinaev" + given-names: "Dmitry" + - name: "QtNodes contributors" +repository-code: "https://github.com/paceholder/nodeeditor" +url: "https://github.com/paceholder/nodeeditor" +license: BSD-3-Clause +version: 3.2.1 +date-released: 2026-11-23 +keywords: + - Qt + - C++ + - node editor + - data flow diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fc44cef3..f7a1c5fce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_policy(SET CMP0072 NEW) # new in 3.11. The NEW behavior for this policy is cmake_policy(SET CMP0068 NEW) # new in 3.9. The NEW behavior of this policy is to ignore the RPATH settings for install_name on macOS. -project(QtNodesLibrary CXX) +project(QtNodesLibrary VERSION 3.2.1 LANGUAGES CXX) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) @@ -93,6 +93,13 @@ set(CPP_SOURCE_FILES resources/resources.qrc ) +set(QT_NODES_GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) + +configure_file(cmake/Version.hpp.in + ${QT_NODES_GENERATED_INCLUDE_DIR}/QtNodes/internal/Version.hpp + @ONLY +) + set(HPP_HEADER_FILES include/QtNodes/internal/AbstractConnectionPainter.hpp include/QtNodes/internal/AbstractGraphModel.hpp @@ -148,6 +155,7 @@ target_include_directories(QtNodes PUBLIC $ $ + $ PRIVATE $ $ @@ -199,6 +207,8 @@ set_target_properties(QtNodes ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} ) ########### @@ -242,6 +252,9 @@ install(TARGETS QtNodes install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(FILES ${QT_NODES_GENERATED_INCLUDE_DIR}/QtNodes/internal/Version.hpp + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/QtNodes/internal) + install(EXPORT QtNodesTargets FILE QtNodesTargets.cmake NAMESPACE QtNodes:: @@ -255,7 +268,14 @@ configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/QtNodesConfig.cmak INSTALL_DESTINATION ${INSTALL_CONFIGDIR} ) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/QtNodesConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/QtNodesConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/QtNodesConfigVersion.cmake DESTINATION ${INSTALL_CONFIGDIR} ) diff --git a/LICENSE.rst b/LICENSE.rst index c485d7f92..acb5a9a1e 100644 --- a/LICENSE.rst +++ b/LICENSE.rst @@ -1,7 +1,7 @@ BSD-3-Clause license ==================== -Copyright (c) 2022, Dmitry Pinaev +Copyright (c) 2013-2026, Dmitry Pinaev All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/README.rst b/README.rst index de7d01815..d61649479 100644 --- a/README.rst +++ b/README.rst @@ -231,6 +231,9 @@ Contribution #. Describe your issue in details #. Provide some use cases. +#. Do not change the version number in a pull request. The maintainer sets it at release, + see `Releasing`_. + #. I maintain this project in my free time, when I am not busy with my work or my family. **If I do not react or do not answer for too long, please ping me**. @@ -239,22 +242,44 @@ Contribution Citing ====== +Use the ``Cite this repository`` button on the GitHub page. It reads ``CITATION.cff``. +Please cite the version you used. + :: - Dmitry Pinaev et al, Qt Nodes, (2013-2025), GitHub repository, https://github.com/paceholder/nodeeditor + Dmitry Pinaev et al, Qt Nodes, (2013-2026), GitHub repository, https://github.com/paceholder/nodeeditor BibTeX:: - @misc{Pinaev2025, + @misc{Pinaev2026, author = {Dmitry Pinaev et al}, title = {QtNodes. Node Editor}, - year = {2025}, + year = {2026}, publisher = {GitHub}, journal = {GitHub repository}, - howpublished = {\url{https://github.com/paceholder/nodeeditor}}, - commit = {877ddb8c447a7a061a5022e9956a3194132e3dd9} + howpublished = {\url{https://github.com/paceholder/nodeeditor}} } +Releasing +========= + +The version is written once, in ``project(QtNodesLibrary VERSION x.y.z)`` in +``CMakeLists.txt``. The version header, the CMake package version, the library version and +the docs read it from there. ``CITATION.cff`` and the git tag hold copies. To release: + +#. Set the new version in ``project()`` and in ``CITATION.cff`` (``version`` and + ``date-released``), in any commit. +#. Run ``cmake -P cmake/Tag.cmake`` on that commit. It creates the annotated tag from the + version in ``project()``. It stops if the version is not higher than every tag, local and + on the remote, or if ``CITATION.cff`` differs. Use ``-DREMOTE=`` if your remote is + not ``origin``. +#. Push the commit and the tag:: + + git push origin master x.y.z + +``cmake -P cmake/CheckVersion.cmake`` checks that ``CITATION.cff`` and ``project()`` agree. The +tests run it. + Support ======= diff --git a/cmake/CheckVersion.cmake b/cmake/CheckVersion.cmake new file mode 100644 index 000000000..4b38c08c9 --- /dev/null +++ b/cmake/CheckVersion.cmake @@ -0,0 +1,28 @@ +# Checks that the release version is the same in every place that names it. +# +# cmake -P cmake/CheckVersion.cmake +# +# The version in project() of CMakeLists.txt is the source of truth. + +get_filename_component(root "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) +set(version_regex "[0-9]+\\.[0-9]+\\.[0-9]+") + +# Sets _version to the first group of the pattern in the file. +function(read_version name file pattern) + file(READ "${root}/${file}" text) + if(NOT text MATCHES "${pattern}") + message(FATAL_ERROR "No version found in ${file}") + endif() + set(${name}_version "${CMAKE_MATCH_1}" PARENT_SCOPE) +endfunction() + +read_version(project CMakeLists.txt + "project\\(QtNodesLibrary[ \t\r\n]+VERSION[ \t\r\n]+(${version_regex})") +read_version(citation CITATION.cff "\nversion: (${version_regex})") + +if(NOT citation_version STREQUAL project_version) + message(FATAL_ERROR + "CITATION.cff has version ${citation_version}, project() has ${project_version}") +endif() + +message(STATUS "Version ${project_version} is the same everywhere") diff --git a/cmake/Tag.cmake b/cmake/Tag.cmake new file mode 100644 index 000000000..4915bd6a6 --- /dev/null +++ b/cmake/Tag.cmake @@ -0,0 +1,63 @@ +# Creates the annotated git tag for the version in project() of CMakeLists.txt. +# It tags the current commit. It does not push. +# +# cmake -P cmake/Tag.cmake +# cmake -DREMOTE=github -P cmake/Tag.cmake # remote to compare with, default: origin +# +# It stops if CITATION.cff differs from project(), if tracked files have changes, or if the +# version is not higher than every version tag, local and on the remote. + +include("${CMAKE_CURRENT_LIST_DIR}/CheckVersion.cmake") + +if(NOT DEFINED REMOTE) + set(REMOTE origin) +endif() + +function(run_git) + execute_process(COMMAND git ${ARGN} + WORKING_DIRECTORY "${root}" + RESULT_VARIABLE result + OUTPUT_VARIABLE output + ERROR_VARIABLE error + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT result EQUAL 0) + string(REPLACE ";" " " command "${ARGN}") + message(FATAL_ERROR "git ${command} failed: ${error}") + endif() + set(git_output "${output}" PARENT_SCOPE) +endfunction() + +run_git(status --porcelain --untracked-files=no) +if(NOT git_output STREQUAL "") + message(FATAL_ERROR "Tracked files have uncommitted changes. Commit them first.") +endif() + +run_git(tag --list) +set(tags "${git_output}") +run_git(ls-remote --tags --refs "${REMOTE}") +string(REGEX MATCHALL "refs/tags/[^\n]+" remote_refs "${git_output}") +foreach(ref IN LISTS remote_refs) + string(REPLACE "refs/tags/" "" ref "${ref}") + list(APPEND tags "${ref}") +endforeach() +string(REPLACE "\n" ";" tags "${tags}") + +set(latest "") +foreach(tag IN LISTS tags) + if(NOT tag MATCHES "^${version_regex}$") + continue() + endif() + if(tag STREQUAL project_version) + message(FATAL_ERROR "The tag ${project_version} already exists, locally or on '${REMOTE}'.") + endif() + if(latest STREQUAL "" OR tag VERSION_GREATER latest) + set(latest "${tag}") + endif() +endforeach() + +if(NOT latest STREQUAL "" AND NOT project_version VERSION_GREATER latest) + message(FATAL_ERROR "The version ${project_version} is not higher than the tag ${latest}.") +endif() + +run_git(tag -a "${project_version}" -m "QtNodes ${project_version}") +message(STATUS "Created the tag ${project_version}. Push it with: git push ${REMOTE} ${project_version}") diff --git a/cmake/Version.hpp.in b/cmake/Version.hpp.in new file mode 100644 index 000000000..a209f5f81 --- /dev/null +++ b/cmake/Version.hpp.in @@ -0,0 +1,13 @@ +#pragma once + +// Generated by CMake from the version in project(). Do not edit. + +#define QTNODES_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define QTNODES_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define QTNODES_VERSION_PATCH @PROJECT_VERSION_PATCH@ +#define QTNODES_VERSION_STR "@PROJECT_VERSION@" + +#define QTNODES_VERSION_CHECK(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch)) + +#define QTNODES_VERSION \ + QTNODES_VERSION_CHECK(QTNODES_VERSION_MAJOR, QTNODES_VERSION_MINOR, QTNODES_VERSION_PATCH) diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index d58dcbf5d..76b06a7d7 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -38,7 +38,7 @@ PROJECT_NAME = "QtNodes" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1 +PROJECT_NUMBER = @PROJECT_VERSION@ # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/docs/conf.py b/docs/conf.py index ff97b881a..3116bcbf8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,4 @@ -import subprocess, os +import subprocess, os, re def configureDoxyfile(input_dir, output_dir): with open('Doxyfile.in', 'r') as file : @@ -31,11 +31,13 @@ def configureDoxyfile(input_dir, output_dir): # -- Project information ----------------------------------------------------- project = 'QtNodes' -copyright = '2022, Dmitry Pinaev' +copyright = '2026, Dmitry Pinaev' author = 'Dmitry Pinaev' -# The full version, including alpha/beta/rc tags -release = '3.0' +# The version is declared once, in project() of the top CMakeLists.txt. +with open(os.path.join(os.path.dirname(__file__), '..', 'CMakeLists.txt')) as f: + release = re.search(r'project\(\s*QtNodesLibrary\s+VERSION\s+([\d.]+)', f.read()).group(1) +version = '.'.join(release.split('.')[:2]) # -- General configuration --------------------------------------------------- diff --git a/docs/getting-started/installation.rst b/docs/getting-started/installation.rst index af83c6bf6..5a6a0f992 100644 --- a/docs/getting-started/installation.rst +++ b/docs/getting-started/installation.rst @@ -139,6 +139,27 @@ After running ``cmake --install .``: If you installed to a custom prefix, pass it with ``-DCMAKE_PREFIX_PATH=``. +Checking the Version +-------------------- + +``find_package`` takes a minimum version. ``3.2`` accepts any ``3.x`` from ``3.2`` on and +rejects ``4.0``: + +.. code-block:: cmake + + find_package(QtNodes 3.2 REQUIRED) + +In C++, ``QtNodes/Version`` defines ``QTNODES_VERSION_MAJOR``, ``QTNODES_VERSION_MINOR``, +``QTNODES_VERSION_PATCH``, the string ``QTNODES_VERSION_STR`` and ``QTNODES_VERSION_CHECK``: + +.. code-block:: cpp + + #include + + #if QTNODES_VERSION >= QTNODES_VERSION_CHECK(3, 2, 0) + // ... + #endif + Verifying Installation ---------------------- diff --git a/include/QtNodes/Version b/include/QtNodes/Version new file mode 100644 index 000000000..d9f8d831e --- /dev/null +++ b/include/QtNodes/Version @@ -0,0 +1 @@ +#include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 53ba18ead..82dc60b58 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,6 +27,7 @@ add_executable(test_nodes src/TestNodeStyleRole.cpp src/TestCopyPaste.cpp src/TestSerializedItemCommands.cpp + src/TestVersion.cpp src/TestZoomFeatures.cpp src/TestLoopDetection.cpp include/ApplicationSetup.hpp @@ -55,3 +56,8 @@ add_test( $ $<$:--use-colour=yes> ) + +add_test( + NAME version_is_the_same_everywhere + COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/CheckVersion.cmake +) diff --git a/test/src/TestVersion.cpp b/test/src/TestVersion.cpp new file mode 100644 index 000000000..bf42342be --- /dev/null +++ b/test/src/TestVersion.cpp @@ -0,0 +1,22 @@ +#include + +#include + +#include + +TEST_CASE("The version string is built from the version numbers", "[core][version]") +{ + std::string const expected = std::to_string(QTNODES_VERSION_MAJOR) + "." + + std::to_string(QTNODES_VERSION_MINOR) + "." + + std::to_string(QTNODES_VERSION_PATCH); + + CHECK(std::string(QTNODES_VERSION_STR) == expected); +} + +TEST_CASE("Newer versions compare greater with QTNODES_VERSION_CHECK", "[core][version]") +{ + CHECK(QTNODES_VERSION_CHECK(3, 2, 1) < QTNODES_VERSION_CHECK(3, 2, 2)); + CHECK(QTNODES_VERSION_CHECK(3, 2, 9) < QTNODES_VERSION_CHECK(3, 3, 0)); + CHECK(QTNODES_VERSION_CHECK(3, 9, 9) < QTNODES_VERSION_CHECK(4, 0, 0)); + CHECK(QTNODES_VERSION >= QTNODES_VERSION_CHECK(QTNODES_VERSION_MAJOR, 0, 0)); +}