I've a target which has some headers in its SOURCES
among others; these are generated using add_custom_command
. Here's the excerpt
set(MY_SOURCES
a.txt
b.txt)
set(MY_HEADERS)
foreach (TXT ${MY_SOURCES})
add_custom_command(OUTPUT ${TXT}.h
COMMAND txt2h
-i "${CMAKE_CURRENT_SOURCE_DIR}/${TXT}"
-o "${TXT}.h"
MAIN_DEPENDENCY ${TXT}
COMMENT "Generating header from ${TXT}"
VERBATIM)
list(APPEND MY_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/${TXT}.h")
endforeach ()
add_executable(exe main.cpp ${MY_HEADERS})
target_include_directories(exe PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
This generates (cmake -B build
) and builds (cmake --build build
) fine.
When I edit a.txt
and run cmake --build build
. It regenerates a.txt.h
since I see
Generating header from a.txt
However, the exe
target isn't built. Since the generated header is listed as a source for exe
, I'm hoping it should also make exe
dirty and rebuild it. What am I missing?
I verified the timestamps on a.txt
and a.txt.h
match and are newer than the exe
's.
References
- Adding a custom command and generated file (Official CMake tutorial)
- Generated sources in CMake builds