[CMake] Delaying building tests to "make test"

Pierre Bourdon delroth at gmail.com
Sun Mar 2 14:30:12 EST 2014


On Sun, Mar 2, 2014 at 8:26 PM, Nils Gladitz <nilsgladitz at gmail.com> wrote:
> On 02.03.2014 20:11, Pierre Bourdon wrote:
>>
>> To avoid increasing compilation time of my project I would like to
>> only build tests when they are going to be run, for example when using
>> "make test". Is there any easy way to do this with CMake?
>
>
> You can prevent your test executables from always building by using the
> EXCLUDE_FROM_ALL flag in add_executable():
>     add_executable(mytest EXCLUDE_FROM_ALL ...)
>
> Then you can create a custom target:
>     add_custom_target(build-my-tests)
>
> And add your test executable targets as dependencies:
>     add_dependencies(build-my-tests mytest)
>
> Then you can run "make" to build everything except your tests and "make
> build-my-tests" to build the tests.
>
> You could also add a command to your custom target to perform testing
> itself.

Any way to reuse the "make test" target for that? Will adding
dependencies to the "test" target work, or is "test" a special target?

-- 
Pierre "delroth" Bourdon <delroth at gmail.com>
Software Engineer @ Zürich, Switzerland
http://code.delroth.net/


More information about the CMake mailing list