[CMake] avoiding building test targets

Michael Wild themiwi at gmail.com
Thu Oct 7 05:28:55 EDT 2010


On 7. Oct, 2010, at 10:54 , edA-qa mort-ora-y wrote:

> How can I have CMake not build test targets when doing a "make install"?
> 
> I'd prefer that test targets are only ever built if "make test" is called.
> 
> -- 
> edA-qa mort-ora-y

That needs a bit of trickery:

function(add_test_executable name)
  add_executable(${name} EXCLUDE_FROM_ALL ${ARGN})
  if(NOT TARGET test-exes)
    add_custom_target(test-exes)
  endif()
  add_dependencies(test-exes ${name})
endfunction()

add_custom_target(check
  COMMAND ${CMAKE_CTEST_COMMAND}
  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  COMMENT "Running ctest")
add_dependencies(check test-exes)


This way you can run "make check" to build all the test executables and to run ctest afterwards.

HTH

Michael

--
There is always a well-known solution to every human problem -- neat, plausible, and wrong.
H. L. Mencken

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20101007/babb001f/attachment-0001.pgp>


More information about the CMake mailing list