# Cmake-gui not detecting top-level project?

**URL:** https://discourse.cmake.org/t/cmake-gui-not-detecting-top-level-project/2142
**Category:** Usage
**Tags:** os:windows
**Created:** [November 9, 2020, 11:50am UTC](https://discourse.cmake.org/t/cmake-gui-not-detecting-top-level-project/2142 "2020-11-09T11:50:42Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [November 9, 2020, 11:50am UTC](https://discourse.cmake.org/t/cmake-gui-not-detecting-top-level-project/2142/1 "2020-11-09T11:50:42Z")

</div>

I’m using cmake 3.19.0-rc1 and I’m currently getting strange behavior from cmake-gui.

Here is the code causing the problem:

```auto
cmake_minimum_required(VERSION 3.18)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(Pito)

if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
    set(PITO_IS_TOP_LEVEL ON)
endif()

message(STATUS "PITO_IS_TOP_LEVEL = ${PITO_IS_TOP_LEVEL}")

if (PITO_IS_TOP_LEVEL)
    pito_pre_project_wide_setup()
endif()

```

Basically if I am the top level project I set the system version, and other things. However, my logic to detect if I am the top level project seems to act differently when I am using cmake-gui.

![image](https://discourse.cmake.org/uploads/default/original/1X/6539f82085a72cbfe11d4f4de3f6ee5498fb4ed1.png)

PITO\_IS\_TOP\_LEVEL is undefined for some reason! Despite the fact that I’m the top level project. Am I doing something wrong or is there a bug?

---

<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:38pm UTC](https://discourse.cmake.org/t/cmake-gui-not-detecting-top-level-project/2142/2 "2020-11-09T21:38:53Z")

</div>

A couple of thoughts come to mind. If you print out the value of `CMAKE_SOURCE_DIR` and `CMAKE_CURRENT_SOURCE_DIR`, you should see the actual differences. I am wondering about whether:

- There are differences with forward/back slashes
- Whether the trailing slash seen in the screenshot is preserved

Printing both values should reveal the reason for the difference.

FWIW, there is work being done on a new `cmake_path()` command which has a `COMPARE` sub-command for comparing paths more robustly. That won’t help you now, but it would potentially be a more robust way forward in the future.

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [November 10, 2020, 12:03pm UTC](https://discourse.cmake.org/t/cmake-gui-not-detecting-top-level-project/2142/3 "2020-11-10T12:03:12Z")

</div>

Yep the trailing slash causes the problem as you said. Removing it fixes everything.

```auto
cmake_minimum_required(VERSION 3.18)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(Pito)

if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
    set(PITO_IS_TOP_LEVEL ON)
endif()

message(STATUS "PITO_IS_TOP_LEVEL = ${PITO_IS_TOP_LEVEL}")
message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "${CMAKE_SOURCE_DIR}")

message(FATAL_ERROR "END")

```

Output from cmake-gui

```auto
PITO_IS_TOP_LEVEL = 
D:/Git/PitoEngine
D:/Git/PitoEngine/
CMake Error at CMakeLists.txt:14 (message):
  END

```

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [November 10, 2020, 12:48pm UTC](https://discourse.cmake.org/t/cmake-gui-not-detecting-top-level-project/2142/4 "2020-11-10T12:48:19Z")

</div>

Would you like me to open up on issue on gitlab or would you prefer to?

---

<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 10, 2020, 9:18pm UTC](https://discourse.cmake.org/t/cmake-gui-not-detecting-top-level-project/2142/5 "2020-11-10T21:18:03Z")

</div>

Please go ahead and open an issue. Reference this forum discussion in the description.

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [November 11, 2020, 11:33am UTC](https://discourse.cmake.org/t/cmake-gui-not-detecting-top-level-project/2142/6 "2020-11-11T11:33:15Z")

</div>

I created the issue on gitlab:  
[https://gitlab.kitware.com/cmake/cmake/-/issues/21421](https://gitlab.kitware.com/cmake/cmake/-/issues/21421)
