AeroSun
AeroSun

Reputation: 2571

How to add dependency one executable from other executable?

The dependency between libraries and libraries+executable could be managed via target_link_libraries. So if some library fails build - all dependent targets will not build.

I have another task: there are exist the library target, the executable test target (that provide test for library) and the main executable target with main logic.

I need that main executable target should be build only if build of the executable test target is not fails.

In other word I need set up dependency between two executables.

How I could achieve it? Could somebody provide an example?

Upvotes: 1

Views: 1694

Answers (1)

Timothy Brackett
Timothy Brackett

Reputation: 181

Testing is a different stage in the CMake/Ctest/CPack suite, so you’re unlikely to find a way to conditionally compile/link an executable based on test results.

You can use add_dependencies to ensure that the test executable builds first, but that’s not the same as only producing a build product of the test runs successfully.

I recommend running your build followed by the test. Based on the return code of the test, you can choose whether or not to package the final product.

Upvotes: 3

Related Questions