# cmake project version - last guy wins?

**URL:** <https://discourse.cmake.org/t/cmake-project-version-last-guy-wins/10446>\
**Category:** Code\
**Created:** [March 22, 2024, 9:21am UTC](https://discourse.cmake.org/t/cmake-project-version-last-guy-wins/10446 "2024-03-22T09:21:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)\
**Post date:** [March 22, 2024, 9:21am UTC](https://discourse.cmake.org/t/cmake-project-version-last-guy-wins/10446/1 "2024-03-22T09:21:25Z")

</div>

How can one scope the cmake project version? It appears the project version string is last-guy wins. Say I have top project CMakeLists.txt that sets version, then it includes some other component by via add\_subdirectory, but this component will then override my project version.

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [April 4, 2024, 8:50am UTC](https://discourse.cmake.org/t/cmake-project-version-last-guy-wins/10446/2 "2024-04-04T08:50:45Z")

</div>

There are multiple variables in CMake related to project versions:

- There’s `PROJECT_VERSION`, which refers to the version specified in the last called `project()` command. I believe that’s what you’re referring to in your question.
- There’s `{ProjectName}_VERSION`, where `{ProjectName}` is a placeholder for the name of a project. This variable refers to the version specified in the `project(ProjectName)` call.
- There’s `CMAKE_PROJECT_VERSION`, which refers to the version of the top-level (i.e. _first_) `project()` call. This may be what you’re looking for.

All of these variables also have the variants `_MAJOR`, `_MINOR`, `_PATCH`, and `_TWEAK` for the individual version components. See the [docs](https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html#variables-that-provide-information) of the individual variables for more details.
