CMakeBuildTest.cmake.in 2 KB
Newer Older
1 2 3
# create the binary directory
make_directory("@CMAKE_BUILD_TEST_BINARY_DIR@")

4 5 6 7 8 9
# remove the CMakeCache.txt file from the source dir
# if there is one, so that in-source cmake tests
# still pass
message("Remove: @CMAKE_BUILD_TEST_SOURCE_DIR@/CMakeCache.txt")
file(REMOVE "@CMAKE_BUILD_TEST_SOURCE_DIR@/CMakeCache.txt")

10
# run cmake in the binary directory
Bill Hoffman's avatar
Bill Hoffman committed
11 12
message("running: ${CMAKE_COMMAND}")
execute_process(COMMAND "${CMAKE_COMMAND}"
13
  "@CMAKE_BUILD_TEST_SOURCE_DIR@"
14 15
  "-G@CMAKE_GENERATOR@"
  -T "@CMAKE_GENERATOR_TOOLSET@"
16 17 18 19
  WORKING_DIRECTORY "@CMAKE_BUILD_TEST_BINARY_DIR@"
  RESULT_VARIABLE RESULT)
if(RESULT)
  message(FATAL_ERROR "Error running cmake command")
20
endif()
21 22

# Now use the --build option to build the project
Bill Hoffman's avatar
Bill Hoffman committed
23
message("running: ${CMAKE_COMMAND} --build")
24
execute_process(COMMAND "${CMAKE_COMMAND}"
25 26 27 28
  --build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug
  RESULT_VARIABLE RESULT)
if(RESULT)
  message(FATAL_ERROR "Error running cmake --build")
29
endif()
30 31 32

# check for configuration types
set(CMAKE_CONFIGURATION_TYPES @CMAKE_CONFIGURATION_TYPES@)
33
# run the executable out of the Debug directory if there
34 35
# are configuration types
if(CMAKE_CONFIGURATION_TYPES)
36
  set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/Debug/@CMAKE_BUILD_TEST_EXE@")
37
else()
38
  set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/@CMAKE_BUILD_TEST_EXE@")
39
endif()
40 41 42 43
# run the test results
message("running [${RUN_TEST}]")
execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
if(RESULT)
44
  message(FATAL_ERROR "Error running test @CMAKE_BUILD_TEST_EXE@")
45
endif()
46

47
# build it again with clean and only @CMAKE_BUILD_TEST_EXE@ target
48 49
execute_process(COMMAND "${CMAKE_COMMAND}"
  --build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug
50
  --clean-first --target @CMAKE_BUILD_TEST_EXE@
51 52 53
  RESULT_VARIABLE RESULT)
if(RESULT)
  message(FATAL_ERROR "Error running cmake --build")
54
endif()
55

56
# run it again after clean
57 58
execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
if(RESULT)
59
  message(FATAL_ERROR "Error running test @CMAKE_BUILD_TEST_EXE@ after clean ")
60
endif()