Adding dependency to generated files to a single source file?

Hi:
In my use case, I have commands at configure time that generates .cpp.inc files from input files, something like :

configure_file(
        "${CMAKE_CURRENT_LIST_DIR}/Input.cpp.in"
        "${CMAKE_CURRENT_BINARY_DIR}/Input.cpp.inc")
# Copy to where Input.cpp lives
file(COPY ....)

And then in my Input.cpp file, I #include "Input.cpp.inc"

This raises a few questions:

  • Input.cpp.inc is not automatically regenerated when Input.cpp.in changes
  • Input.cpp is not recompiled when Input.cpp.in changes

P.S.:

  • libInput which contains Input.cpp might not be created yet when this CMakeLists is being run. (Uncontrollable by me)
  • libInput is not created in the same level as current CMakeLists.txt

Why not just configure directly into wherever file(COPY) puts the file? That might solve the issue.

This looks like that this will change the source directory. You should generally try to avoid that. Maybe adapt the include path instead…