Create Visual Studio "Custom Build Step" with CMake

I would like to run the code generator every time my project is built in Visual Studio, even if the source file in the project has not been modified. Therefore, I would like to create a custom build step, as described in Visual Studio: Run a C ++ Project Post-Build Event, even if the project is updated .

How can I create such a build step using CMake?

+4
source share
2 answers

I think the custom target is what you are looking for: add_custom_target

From the documentation:

Add a goal without output so that it is always built.

Or, if you create a code file,

http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_custom_target

You can run POST_BUILD and generate the output.

+5
source

This is not possible with CMake and therefore a missing feature .

The answer from Tarydon in the question you are referring to is setting up exactly what you want - the " Custom Build Step ". This means that you still only have your main goal (VS Project), with something that looks like a " Post-construction event ", but technically it is not, because events after assembly do not fire if the project is updated.

The answer from tpg2114 works, but has one major drawback; this is spam of your decision with fake projects. If you have one hundred projects in the solution, you need to add another hundred, as well as post-build wrappers in the first hundred, of course, it is undesirable.

Depending on your situation, it can sometimes be easier to use Post-Build Events and force a rebuild of at least one source file so that the project is actually created and therefore also runs your user command.

0
source

Source: https://habr.com/ru/post/1393899/


All Articles