project(mytest C) cmake_minimum_required(VERSION 2.8) enable_testing() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) file(WRITE ${CMAKE_BINARY_DIR}/test.c "int main() { return 0; }\n") add_executable(myfirsttest ${CMAKE_BINARY_DIR}/test.c) add_test(myfirsttest myfirsttest)