The idea is to defin开发者_StackOverflow社区e a detached "examples" target in the CMakeLists.txt that would not get executed when running:
make
But that would build the examples when doing
make examples
I found a solution: set EXCLUDE_FROM_ALL on the "add_executable" command.
This is what I had to write to solve my "examples" build:
add_custom_target(examples)
add_executable(hello EXCLUDE_FROM_ALL hello.cpp)
add_dependencies(examples hello)
When running "make", the hello executable is not built.
When running "make examples", hello is built.
精彩评论