I use a python script (gen_instantiations.py) to generate a cpp file (autogen_instantiations.cpp) which is included in another cpp file (foo.cpp)
So I want CMake to regenerate this file whenever foo.hpp or gen_instantiations.py changes.
Following instructions from the CMake FAQ, here’s what I did
add_custom_command(
COMMAND "./gen_instantiations.py"
OUTPUT "autogen_instantiations.cpp"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS gen_instantiations.py foo.hpp
)
add_custom_target(instantiations ALL DEPENDS autogen_instantiations.cpp)
add_library(foo
foo.cpp
)
add_dependencies(foo instantiations)
But this runs runs the script every single time. What am I doing wrong?
the better approach is to not
#includegeneratedautogen_instantiations.cpp, but add it to thefoolibrary as one more source file, so cmake could see thatfoodepends on it and call your generator if smth has changed