Skip to content

Conversation

@benedekkupper
Copy link

I use FetchContent_Declare() and FetchContent_MakeAvailable() to pull in the cib dependency to an ESP-IDF project (among others). Strangely, at least with cmake version 3.28.3, PROJECT_IS_TOP_LEVEL evaluates to true in such scenarios. The outcome of the mixup is a completely broken build. Using ${PROJECT_NAME}_IS_TOP_LEVEL solves the problem, as it produces the expected behavior.

I use FetchContent_Declare() and FetchContent_MakeAvailable()
to pull in the cib dependency to an ESP-IDF project (among others).
Strangely, at least with cmake version 3.28.3, PROJECT_IS_TOP_LEVEL
evaluates to true in such scenarios. The outcome of the mixup is a
completely broken build. Using ${PROJECT_NAME}_IS_TOP_LEVEL solves the
problem, as it produces the expected behavior.
benedekkupper added a commit to benedekkupper/cpp-std-extensions that referenced this pull request Nov 4, 2025
@bdeane-intel
Copy link
Contributor

bdeane-intel commented Nov 4, 2025

Can you explain why this change fixes your problem?

The documentation for both is fairly identical:
https://cmake.org/cmake/help/latest/variable/PROJECT-NAME_IS_TOP_LEVEL.html
https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html

And specifically says:
The variable value will be false in a directory added by FetchContent_MakeAvailable() if the fetched content contains a project() call.
...which is your case? So I do not understand the difference here.

Is it possibly caused by a problem somewhere else in the cmake you're running?
With the cache variables?
Is it a problem others will run into?
Is it changed by a policy? (e.g. https://cmake.org/cmake/help/latest/policy/CMP0180.html#policy:CMP0180)
Would it be better to fix the ${PROJECT_NAME} to cib here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants