GENERATED flag not propagated properly for INTERFACE files
Hi,
I have attached an example where CMake (version 3.13) raises an error that a file is not found which will be generated by an add_custom_command
.
The issue seems to be related to the hierarchical structure of the project.
For the example I have created an INTERFACE
lib that contains a header file that will be automatically generated. This INTERFACE
lib will be linked to a library that is defined in a child CMakeLists.txt
.
When I move the content of the child CMakeLists.txt
to the parent file then everything is working fine.
Root CMakeLists.txt:
project(example LANGUAGES C CXX)
add_executable(example source/main.cpp)
add_subdirectory(source) # include the child CMakeLists.txt here
add_library(test INTERFACE)
target_sources(test INTERFACE
"${CMAKE_CURRENT_BINARY_DIR}/gen/output.h"
)
target_link_libraries(dummy PRIVATE test)
target_link_libraries(example PRIVATE dummy)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen/output.h"
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/gen
COMMAND ${CMAKE_COMMAND} -E echo "int Get_Output(void) { return 5; }" > ${CMAKE_CURRENT_BINARY_DIR}/gen/output.h
)
Child CMakeLists.txt
add_library(dummy)
target_sources(dummy PRIVATE "dummy.cpp")