Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project version CMake CLI variable #22

Merged
merged 2 commits into from
Oct 6, 2023

Conversation

filip-szweda
Copy link
Member

@filip-szweda filip-szweda commented Oct 6, 2023

Problem

Currently, the project version is retrieved from git tags.
This can cause two issues:

  • if the user clones a shallow copy of the repository or downloads the source code from GitHub releases, they won't have access to git tags
  • if the user clones a deep copy of the repository, but no tag has been created, CMake configuration and artifact publishing will fail

Solution

This change adds a project version CMake CLI variable with following syntax -DPROJECT_VERSION=<project version>.
The user needs to provide project version during configuration stage e.g. cmake --preset conan-release -DBUILD_TESTS=OFF -DPROJECT_VERSION=1.0.0.
In GitHub actions project version is retrieved from git tags and if no tags are available, commit hash is used.

Proof

With printf("%s\n", PROJECT_VERSION); added to main.cpp:
proof #1
No PROJECT_VERSION variable in the CLI:
proof #2
No PROJECT_VERSION value:
proof #3
Wrong version format:
proof #4

CMakeLists.txt Outdated Show resolved Hide resolved
@filip-szweda filip-szweda merged commit 0dc255b into main Oct 6, 2023
2 checks passed
@filip-szweda filip-szweda deleted the change-version-retrieving branch October 6, 2023 11:43
hparzych pushed a commit that referenced this pull request Apr 29, 2024
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.

2 participants