Is add_custom_command with APPEND supposed to work across different directories? I first suspected it was an issue because I had the main custom command in a sibling directory, but even when defining the main custom command in a root of the APPEND one, it still produces the following error. Moving the APPEND command to the main CMakeLists.txt works correctly.
CMake Error at subdir/CMakeLists.txt:2 (add_custom_command):
Attempt to APPEND to custom command with output
E:/src/tmp/cm_append/build/h.h
which is not already a custom command output.
Setup:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.30)
PROJECT(cm_app)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/h.h
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/h.h.txt ${CMAKE_CURRENT_BINARY_DIR}/h.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/h.h.txt
)
add_custom_target(hh DEPENDS h.h)
add_subdirectory(subdir)
ADD_EXECUTABLE(cm_app main.cpp h.h)
target_include_directories(cm_app PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
subdir/CMakeLists.txt
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/h.h
COMMAND echo "second command"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/b.h.txt
APPEND
)