IMPLICIT_DEPENDS does not work for files in the build directory
Hello,
I ran into a not completely trivial issue today, and I'm not entirely sure how to deal with it.
As I explained in #16830 a while ago, in our builds we rely on a custom executable that generates source files based on some C++ headers that we provide to it. To determine when to (re-)run this custom code generator, the code depends on add_custom_command
's IMPLICIT_DEPENDS
feature. And normally this works well.
But in some cases we do something even one step more complicated. We construct some header files during the build with some custom commands (this is a long story...), and we want to run the code generator mentioned earlier on this header. One that is put into the binary directory. And it seems that IMPLICIT_DEPENDS
does not work correctly in that case. Or maybe I just missed something obvious...
Attached is a much simplified example.
It has 2 headers. One of which includes the other one. It sets up a "build" like I described. It sets up a custom command directly on ${CMAKE_SOURCE_DIR}/header1.h
as a (working) reference showing what behaviour I'd like, and it also makes a copy of that header under ${CMAKE_BINARY_DIR}/header1.h
during the build, and sets up a second custom command based on that copied header.
A clean "build" of all of this looks like:
[bash][tauriel]:build > ~/Software/CMake/3.13.0/bin/cmake ../implicitDepInBuildDir/
-- The CXX compiler identification is AppleClang 10.0.0.10001145
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/krasznaa/Development/cmake/build
[bash][tauriel]:build > make
Scanning dependencies of target IndirectTarget
[ 33%] Copying header1.h to the binary directory
[ 66%] Detected indirect header1.h change
[ 66%] Built target IndirectTarget
Scanning dependencies of target DirectTarget
[100%] Detected direct header1.h change
[100%] Built target DirectTarget
[bash][tauriel]:build >
Now, if I make some modification in header2.h
, I'd like both custom targets to re-run. But they don't.
[bash][tauriel]:build > touch ../implicitDepInBuildDir/header2.h
[bash][tauriel]:build > make
[ 66%] Built target IndirectTarget
Scanning dependencies of target DirectTarget
[100%] Detected direct header1.h change
[100%] Built target DirectTarget
[bash][tauriel]:build >
Did I find some bug, or did I just forget about something in how IMPLICIT_DEPENDS
behaves?
Cheers, Attila