2

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.

tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
  • 1
    Check out [tinyalsa](https://github.com/tinyalsa/tinyalsa/blob/515be35688a76edee90b892150ea22fa9516638c/CMakeLists.txt#L7) for some inspiration. The version number is retrieved from a script before calling `project`. – tay10r Apr 24 '21 at 03:43
  • Epicccc I will totally check that out. Thank you! – tjwrona1992 Apr 24 '21 at 03:46
  • I don't have any experience with juce, but a short google search comes up with this page https://github.com/juce-framework/JUCE/blob/master/docs/CMake%20API.md ; If i read this correctly you should be able to do `juce_add_plugin(my_project VERSION 1.2.3)` which btw seems to be hinted at in the quoted text in your question. – fabian Apr 24 '21 at 09:53

0 Answers0