0

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?

Rivand
  • 103
  • 3

1 Answers1

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