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:
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.

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?
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.
Yep the trailing slash causes the problem as you said. Removing it fixes everything.
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
PITO_IS_TOP_LEVEL =
D:/Git/PitoEngine
D:/Git/PitoEngine/
CMake Error at CMakeLists.txt:14 (message):
END
Would you like me to open up on issue on gitlab or would you prefer to?
Please go ahead and open an issue. Reference this forum discussion in the description.