# CMake 3.29 - 4.2.3 CMAKE\_PROJECT\_\_INCLUDE\_BEFORE cannot set variables for project(…)

**URL:** https://discourse.cmake.org/t/cmake-3-29-4-2-3-cmake-project-include-before-cannot-set-variables-for-project/15505
**Category:** Code
**Created:** [February 10, 2026, 3:39pm UTC](https://discourse.cmake.org/t/cmake-3-29-4-2-3-cmake-project-include-before-cannot-set-variables-for-project/15505 "2026-02-10T15:39:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![e\_gleba](https://discourse.cmake.org/user_avatar/discourse.cmake.org/e_gleba/32/5833_2.png) [@e\_gleba](https://discourse.cmake.org/u/e_gleba)
#### Post date: [February 10, 2026, 3:39pm UTC](https://discourse.cmake.org/t/cmake-3-29-4-2-3-cmake-project-include-before-cannot-set-variables-for-project/15505/1 "2026-02-10T15:39:35Z")

</div>

# CMAKE\_PROJECT\_\_INCLUDE\_BEFORE cannot set variables for project(…)

## Summary

`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE` fails to provide variables for the parameter of `project()` (e.g. `VERSION` or `DESCRIPTION`). Variables set in the include\_before script are undefined when `project()` parses its `VERSION` argument, despite documentation suggesting the include happens before `project()`.

Here is the minimal example:

```cmake
# CMakeLists.txt
cmake_minimum_required(VERSION 4.1)

include(CMakePrintHelpers)

variable_watch(TB_VERSION)
variable_watch(PROJECT_VERSION)

list(APPEND CMAKE_PROJECT_test_INCLUDE_BEFORE
     "${CMAKE_CURRENT_SOURCE_DIR}/set_version.cmake")

project(test VERSION ${TB_VERSION})

cmake_print_variables(TB_VERSION PROJECT_VERSION CMAKE_PROJECT_VERSION)

```

```cmake
# set_version.cmake
message(STATUS "include_before running...")

set(TB_VERSION "1.2.3")

cmake_print_variables(TB_VERSION)

```

Log:

```sh
❯ cmake .
CMake Debug Log at CMakeLists.txt:11 (project):
  Variable "TB_VERSION" was accessed using UNKNOWN_READ_ACCESS with value "".

-- include_before running...
CMake Debug Log at set_version.cmake:3 (set):
  Variable "TB_VERSION" was accessed using MODIFIED_ACCESS with value
  "1.2.3".
Call Stack (most recent call first):
  CMakeLists.txt:11 (project)

CMake Debug Log at C:/Users/e_gleba/scoop/apps/cmake/current/share/cmake-4.2/Modules/CMakePrintHelpers.cmake:94 (string):    
  Variable "TB_VERSION" was accessed using READ_ACCESS with value "1.2.3".
Call Stack (most recent call first):
  set_version.cmake:5 (cmake_print_variables)
  CMakeLists.txt:11 (project)

-- TB_VERSION="1.2.3"
CMake Warning at CMakeLists.txt:11 (project):
  VERSION keyword not followed by a value or was followed by a value that
  expanded to nothing.

CMake Debug Log at CMakeLists.txt:11 (project):
  Variable "PROJECT_VERSION" was accessed using MODIFIED_ACCESS with value
  "".

CMake Debug Log at C:/Users/e_gleba/scoop/apps/cmake/current/share/cmake-4.2/Modules/CMakePrintHelpers.cmake:94 (string):
  Variable "TB_VERSION" was accessed using READ_ACCESS with value "1.2.3".
Call Stack (most recent call first):
  CMakeLists.txt:13 (cmake_print_variables)

CMake Debug Log at C:/Users/e_gleba/scoop/apps/cmake/current/share/cmake-4.2/Modules/CMakePrintHelpers.cmake:94 (string):    
  Variable "PROJECT_VERSION" was accessed using READ_ACCESS with value "".
Call Stack (most recent call first):
  CMakeLists.txt:13 (cmake_print_variables)

-- TB_VERSION="1.2.3" ; PROJECT_VERSION="" ; CMAKE_PROJECT_VERSION=""
-- Configuring done (0.0s)
-- Generating done (0.1s)
-- Build files have been written to: C:/Users/e_gleba/testbed

```

This contradicts the documented behavior from “Professional CMake” 22nd edition, which states the code is equivalent to:

```cmake
# CMake 3.15 or later only
if(DEFINED CMAKE_PROJECT_INCLUDE_BEFORE)
    include(${CMAKE_PROJECT_INCLUDE_BEFORE})
endif()

# CMake 3.17 or later only
if(DEFINED CMAKE_PROJECT_SomeProj_INCLUDE_BEFORE)
    include(${CMAKE_PROJECT_SomeProj_INCLUDE_BEFORE})
endif()

project(SomeProj)

```

However, manually placing `include()` before `project()` **does work correctly**

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [February 10, 2026, 4:09pm UTC](https://discourse.cmake.org/t/cmake-3-29-4-2-3-cmake-project-include-before-cannot-set-variables-for-project/15505/2 "2026-02-10T16:09:23Z")

</div>

This was also raised as [CMake Issue 27588](https://gitlab.kitware.com/cmake/cmake/-/issues/27588). As I’ve just answered there, the observed behavior is that described by our official documentation.

> [@e\_gleba](#):
>
> This contradicts the documented behavior from “Professional CMake” 22nd edition

@craig.scott please look at the wording in the book.

---

<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: [February 14, 2026, 5:34am UTC](https://discourse.cmake.org/t/cmake-3-29-4-2-3-cmake-project-include-before-cannot-set-variables-for-project/15505/3 "2026-02-14T05:34:08Z")

</div>

The wording in the official docs for the `project()` commands are the most precise and correct (I also wrote the last main update to those). The wording in the _Professional CMake_ book is preceded by the sentence “The effective behavior of these variables is loosely equivalent to the following…”. Note the “loosely” there. The book’s example wasn’t intended to cover all cases, only to give an approximate high-level understanding of the steps. Your example is relying on a more intricate detail about what variables are defined in what order within the `project()` command’s implementation. I can look at the wording used by the book, but its example isn’t meant to go into the level of detail you’re talking about here.
