# Inconsistent behaviour of \<PROJECT-NAME\>\_\* Variables defined on PROJECT Command

**URL:** <https://discourse.cmake.org/t/inconsistent-behaviour-of-project-name-variables-defined-on-project-command/1288>\
**Category:** Code\
**Created:** [May 28, 2020, 6:13pm UTC](https://discourse.cmake.org/t/inconsistent-behaviour-of-project-name-variables-defined-on-project-command/1288 "2020-05-28T18:13:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![infohoschie](https://discourse.cmake.org/user_avatar/discourse.cmake.org/infohoschie/32/3611_2.png) [@infohoschie](https://discourse.cmake.org/u/infohoschie)\
**Post date:** [May 28, 2020, 6:13pm UTC](https://discourse.cmake.org/t/inconsistent-behaviour-of-project-name-variables-defined-on-project-command/1288/1 "2020-05-28T18:13:37Z")

</div>

When a Project is defined some project specific variables are set:

- \<PROJECT-NAME\>\_SOURCE\_DIR
- \<PROJECT-NAME\>\_BINARY\_DIR
- \<PROJECT-NAME\>\_VERSION
- \<PROJECT-NAME\>\_DESCRIPTION

The scope of this variables seems to be inconsistent.  
\<PROJECT-NAME\>\_SOURCE\_DIR and \<PROJECT-NAME\>\_BINARY\_DIR have global scope where the other variables only are defined within the current directory and its sub-directories.

Does someone know, if this is the intended behavior?  
I want to use \<PROJECT-NAME\>\_DESCRIPTION and others in another top-level CMake-Directory, where it isn’t available anymore.

In contrast the CMAKE\_PROJECT\_DESCRIPTION (which is linked to the very first project-call) is available globally.

Regards Thomas

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [November 9, 2020, 9:42pm UTC](https://discourse.cmake.org/t/inconsistent-behaviour-of-project-name-variables-defined-on-project-command/1288/2 "2020-11-09T21:42:23Z")

</div>

> [@infohoschie](#):
>
> CMAKE\_PROJECT\_DESCRIPTION

These variables are set by the first `project()` call. Since this is usually at the top-level, they just end up being global.

As for the others, it’s likely that there wasn’t thought behind it. I’m not sure which is preferred for the other metadata.

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [November 9, 2020, 9:54pm UTC](https://discourse.cmake.org/t/inconsistent-behaviour-of-project-name-variables-defined-on-project-command/1288/3 "2020-11-09T21:54:23Z")

</div>

It is very important that the `PROJECT_...` variables are limited to the scope they currently have. It ensures you can use them and have confidence that you are referring to the most recent `project()` call in the current directory stack. There are techniques that rely on this.

If you need the top level details, that’s what the `CMAKE_PROJECT_...` variables are for. I think only a couple of those are defined though, not the full set equivalents of `PROJECT_...` variables.

FYI you can retrieve the value of a variable from a different directory scope as follows:

```cmake
get_directory_property(<result-var> DIRECTORY <dir> DEFINITION <var-name>)

```
