Bug: CMAKE_PARENT_LIST_FILE changed after include
My CMake version is 3.26.4.
I have 3 files:
A.cmake
message(STATUS "${CMAKE_CURRENT_LIST_FILE} pre include B: ${CMAKE_PARENT_LIST_FILE}")
include("${CMAKE_CURRENT_LIST_DIR}/B.cmake")
message(STATUS "${CMAKE_CURRENT_LIST_FILE} post include B: ${CMAKE_PARENT_LIST_FILE}")
B.cmake
message(STATUS "${CMAKE_CURRENT_LIST_FILE} pre include C: ${CMAKE_PARENT_LIST_FILE}")
include("${CMAKE_CURRENT_LIST_DIR}/C.cmake")
message(STATUS "${CMAKE_CURRENT_LIST_FILE} post include C: ${CMAKE_PARENT_LIST_FILE}")
C.cmake
message(STATUS "${CMAKE_CURRENT_LIST_FILE}: ${CMAKE_PARENT_LIST_FILE}")
When I call:
cmake -P A.cmake
the output is
-- C:/Temp/A.cmake pre include B:
-- C:/Temp/B.cmake pre include C: C:/Temp/A.cmake
-- C:/Temp/C.cmake: C:/Temp/B.cmake
-- C:/Temp/B.cmake post include C: C:/Temp/B.cmake
-- C:/Temp/A.cmake post include B: C:/Temp/A.cmake
As you can see the value of CMAKE_PARENT_LIST_FILE
changed after include
to the value of CMAKE_CURRENT_LIST_FILE
. I find it extra iritating that the last issue is again C:/Temp/A.cmake
instead of C:/Temp/B.cmake
. There is obviously a reset after the include
, but to the wrong value.
I am pretty sure that the correct behavior should be that CMAKE_PARENT_LIST_FILE
is not changed by any include
.
Expected behavior:
-- C:/Temp/A.cmake pre include B:
-- C:/Temp/B.cmake pre include C: C:/Temp/A.cmake
-- C:/Temp/C.cmake: C:/Temp/B.cmake
-- C:/Temp/B.cmake post include C: C:/Temp/A.cmake
-- C:/Temp/A.cmake post include B:
If this is actually intended, then it should definitely be documented!
Edited by Benjamin Buch