Setting the CMake project version AFTER the call to "project"

Viewed 1213

I am trying to make a Juce plugin using CMake and the Juce CMake functions require that the current project has a version defined for it. The issue is, I don't want to hardcode the version number in CMakeLists.txt. I want to get the version from whatever the current version tag is on the git repository for the project.

I have a CMake project that I define a project without a version like so:

project(my_project LANGUAGES CXX)

And then later I get the version of the project from a Git tag using a custom function

# Sets the GIT_VERSION variable to the value that should be the project version
get_version_from_git()

I tried setting the project version after getting it from git like this:

set(my_project_VERSION ${GIT_VERSION})

except even after I do that, Juce doesn't seem to recognize that the project version has been set and throws an error when I call juce_add_plugin(${PROJECT_NAME} ...):

Target my_project must have its VERSION argument set, or must be part of a project with a PROJECT_VERSION

How can I get Juce to recognize a version that I set after calling the project command? I really want to avoid hardcoding the version number because I want it to always be automatically in sync with the current version tag in the git repository for the project.

0 Answers
Related