cmake/Tests/CMakeBuildTest.cmake.in

62 lines
2.0 KiB
CMake
Raw Normal View History

2009-10-04 10:30:41 +03:00
# create the binary directory
make_directory("@CMAKE_BUILD_TEST_BINARY_DIR@")
# 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")
2013-03-16 19:13:01 +02:00
# run cmake in the binary directory
2009-10-04 10:30:41 +03:00
message("running: ${CMAKE_COMMAND}")
execute_process(COMMAND "${CMAKE_COMMAND}"
2013-03-16 19:13:01 +02:00
"@CMAKE_BUILD_TEST_SOURCE_DIR@"
2015-04-27 22:25:09 +02:00
"-G@CMAKE_GENERATOR@"
-A "@CMAKE_GENERATOR_PLATFORM@"
-T "@CMAKE_GENERATOR_TOOLSET@"
2009-10-04 10:30:41 +03:00
WORKING_DIRECTORY "@CMAKE_BUILD_TEST_BINARY_DIR@"
RESULT_VARIABLE RESULT)
if(RESULT)
message(FATAL_ERROR "Error running cmake command")
2013-03-16 19:13:01 +02:00
endif()
2009-10-04 10:30:41 +03:00
# Now use the --build option to build the project
message("running: ${CMAKE_COMMAND} --build")
2013-03-16 19:13:01 +02:00
execute_process(COMMAND "${CMAKE_COMMAND}"
2009-10-04 10:30:41 +03:00
--build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug
RESULT_VARIABLE RESULT)
if(RESULT)
message(FATAL_ERROR "Error running cmake --build")
2013-03-16 19:13:01 +02:00
endif()
2009-10-04 10:30:41 +03:00
# check for configuration types
set(CMAKE_CONFIGURATION_TYPES @CMAKE_CONFIGURATION_TYPES@)
2013-03-16 19:13:01 +02:00
# run the executable out of the Debug directory if there
2009-10-04 10:30:41 +03:00
# are configuration types
if(CMAKE_CONFIGURATION_TYPES)
2012-02-18 12:40:36 +02:00
set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/Debug/@CMAKE_BUILD_TEST_EXE@")
2013-03-16 19:13:01 +02:00
else()
2012-02-18 12:40:36 +02:00
set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/@CMAKE_BUILD_TEST_EXE@")
2013-03-16 19:13:01 +02:00
endif()
2009-10-04 10:30:41 +03:00
# run the test results
message("running [${RUN_TEST}]")
execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
if(RESULT)
2012-02-18 12:40:36 +02:00
message(FATAL_ERROR "Error running test @CMAKE_BUILD_TEST_EXE@")
2013-03-16 19:13:01 +02:00
endif()
2009-10-04 10:30:41 +03:00
2012-02-18 12:40:36 +02:00
# build it again with clean and only @CMAKE_BUILD_TEST_EXE@ target
2013-03-16 19:13:01 +02:00
execute_process(COMMAND "${CMAKE_COMMAND}"
--build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug
2012-02-18 12:40:36 +02:00
--clean-first --target @CMAKE_BUILD_TEST_EXE@
2009-10-04 10:30:41 +03:00
RESULT_VARIABLE RESULT)
if(RESULT)
message(FATAL_ERROR "Error running cmake --build")
2013-03-16 19:13:01 +02:00
endif()
2009-10-04 10:30:41 +03:00
2013-03-16 19:13:01 +02:00
# run it again after clean
2009-10-04 10:30:41 +03:00
execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
if(RESULT)
2012-02-18 12:40:36 +02:00
message(FATAL_ERROR "Error running test @CMAKE_BUILD_TEST_EXE@ after clean ")
2013-03-16 19:13:01 +02:00
endif()