GENERATED property returns wrong value when called from parent directory
Hi,
Based on my reading of the documentation of the GENERATED property and CMP0118, I believe the current behavior to be a bug (if it is not, I think the behavior should be called out explicitly in the documentation, because it is very surprising).
If a parent directory reads the GENERATED
property of a file in a subdirectory, the wrong result is returned.
To reproduce:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.26...3.27 FATAL_ERROR)
project(BugWithGeneratedProperty LANGUAGES CXX)
include(CMakePrintHelpers)
add_subdirectory(subdir)
# BUG: Prints GENERATED = 0
cmake_print_properties(SOURCES "${PROJECT_BINARY_DIR}/subdir/foo.cc" PROPERTIES GENERATED)
# subdir/CMakeLists.txt
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/foo.cc"
COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/foo.cc"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
VERBATIM)
# Prints GENERATED=1 as expected
include(CMakePrintHelpers)
cmake_print_properties(SOURCES "${CMAKE_CURRENT_BINARY_DIR}/foo.cc" PROPERTIES GENERATED)
$ cmake -S . -B build
-- The CXX compiler identification is GNU 11.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--
Properties for SOURCE /home/xxx/BugWithGeneratedProperty/build/subdir/foo.cc:
/home/xxx/BugWithGeneratedProperty/build/subdir/foo.cc.GENERATED = "1"
--
Properties for SOURCE /home/xxx/BugWithGeneratedProperty/build/subdir/foo.cc:
/home/xxx/BugWithGeneratedProperty/build/subdir/foo.cc.GENERATED = "0"
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/xxx/BugWithGeneratedProperty/build
As can be seen in the output, the subdirectory correctly finds foo.cc
to be GENERATED
, but in the top level directory it is not marked as GENERATED
.
The cmake version is the current release from the website
$ cmake --version
cmake version 3.27.0-rc4
CMake suite maintained and supported by Kitware (kitware.com/cmake).