I have a cmake c++ project and a python script that generates part of c++ code (a new one every time). How can I add a build step in Visual Studio Code that will run my script before building the project?
Asked
Active
Viewed 532 times
0
-
I think that you need to add a command yourself on prebuild phase. – Anis Belaid Nov 01 '21 at 08:03
-
https://stackoverflow.com/questions/15972898/cmake-how-to-run-a-add-custom-command-before-everything-else – Anis Belaid Nov 01 '21 at 08:06
-
1https://discourse.cmake.org/t/define-a-pre-build-command-without-creating-a-new-target/1623 – Anis Belaid Nov 01 '21 at 08:08
1 Answers
1
I would check this command
add_custom_command(TARGET targetName buildStage COMMAND command1 [args1...]
[COMMAND command2 [args2...]] [WORKING_DIRECTORY dir]
[BYPRODUCTS files...]
[COMMENT comment]
[VERBATIM]
[USES_TERMINAL] # Requires CMake 3.2 or later [JOB_POOL poolName] # Requires CMake 3.15 or later
)
adding a PRE_BUILD stage

fabiop
- 179
- 10
-
It doesn't work for me. Other people have also encountered [this problem]( https://stackoverflow.com/questions/26216570/cmake-add-custom-command-with-pre-build-does-not-work), the cmake documentation says that the PRE_BUILD parameter only works with Visual Studio generators. I have GCC and the make generator. – Rivand Nov 01 '21 at 09:01
-
You can add a custom target with add_custom_target() command, and then add a dependency on it from your target – fabiop Nov 01 '21 at 09:12
-
I don't quite understand. I already have the target that I build, why would I add another one? – Rivand Nov 01 '21 at 09:48
-
In order to execute some actions before building your target. Defining a custom target and adding a dependency on it will ensure every time you build your target, the commands contained in the custom target will be executed – fabiop Nov 01 '21 at 15:26