In CMake I currently have a simple Python script to generate a header, but if I update the script itself CMake won’t re-run the script. Is there a way I can get CMake to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It seems you are directly invoking your code generation script when cmake is run. While it is possible solution but it is definitely not a right way to use code generators with cmake.
I recommend you to use
add_custom_commandfor your case:And next you can simple put your header to the list of source files passed to
add_library/add_executablecommands. cmake will automatically track all the dependencies and invoke your script.Term
DEPENDS generator.pyinforms cmake that it should regenerate header if script is changed.With this approach file
generated.hwill be generated only at build time (when you runmakeor execute a build command in IDE). In contrast if you are running your script at cmake time (withexecute_processcommand) then you have to rerun cmake to regenerate your file. Which is possible but you need to use some tricks to introduce a non-standard dependency.