CMakeBuildTest.cmake.in 1.97 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
  "-G@CMAKE_GENERATOR@"
15
  -A "@CMAKE_GENERATOR_PLATFORM@"
16
  -T "@CMAKE_GENERATOR_TOOLSET@"
17 18 19 20
  WORKING_DIRECTORY "@CMAKE_BUILD_TEST_BINARY_DIR@"
  RESULT_VARIABLE RESULT)
if(RESULT)
  message(FATAL_ERROR "Error running cmake command")
21
endif()
22 23

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

32 33 34 35
# run the executable out of the Debug directory if using a
# multi-config generator
set(_isMultiConfig @_isMultiConfig@)
if(_isMultiConfig)
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()