0

I want to use add_custom_command to generate a file. I know I can use add_custom_target to set the DEPENDS to invoke the command. But this will also create a target(like in visual studio, it will create a .vcxproj). I use another add_custom_command, and then set the DEPENDS but it does not work. Why? Which level dependency can invoke it?

Are there any methods to invoke the add_custom_command like make install invokes the install command .

1 Answer 1

1

The add_custom_command() function corresponds to Makefile's rule. It list commands which are needed to produce some file. If you wish to be able to run in from make invocation, you should wrap it into `add_custom_target(tgt DEPENDS cmd), just as you said.

So, there is no way to execute custom_command's without creating custom_target's for them.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much, so add_customer_target is the only way to execute it . but you now there are some other commands that can set dependency. so why these command can't invoke it.
Because these command aren't executed themselves. If you add_custom_command(OUTPUT a) and then add_custom_command(OUTPUT b DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/a), these command wouldn't be executed during make. But when you do add_custom_target(tgt DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/b), you can now issue make tgt and this will run both commands.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.