CMakeBuildTest.cmake.in 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # create the binary directory
  2. make_directory("@CMAKE_BUILD_TEST_BINARY_DIR@")
  3. # remove the CMakeCache.txt file from the source dir
  4. # if there is one, so that in-source cmake tests
  5. # still pass
  6. message("Remove: @CMAKE_BUILD_TEST_SOURCE_DIR@/CMakeCache.txt")
  7. file(REMOVE "@CMAKE_BUILD_TEST_SOURCE_DIR@/CMakeCache.txt")
  8. # run cmake in the binary directory
  9. message("running: ${CMAKE_COMMAND}")
  10. execute_process(COMMAND "${CMAKE_COMMAND}"
  11. "@CMAKE_BUILD_TEST_SOURCE_DIR@"
  12. "-G@CMAKE_TEST_GENERATOR@"
  13. WORKING_DIRECTORY "@CMAKE_BUILD_TEST_BINARY_DIR@"
  14. RESULT_VARIABLE RESULT)
  15. if(RESULT)
  16. message(FATAL_ERROR "Error running cmake command")
  17. endif(RESULT)
  18. # Now use the --build option to build the project
  19. message("running: ${CMAKE_COMMAND} --build")
  20. execute_process(COMMAND "${CMAKE_COMMAND}"
  21. --build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug
  22. RESULT_VARIABLE RESULT)
  23. if(RESULT)
  24. message(FATAL_ERROR "Error running cmake --build")
  25. endif(RESULT)
  26. # check for configuration types
  27. set(CMAKE_CONFIGURATION_TYPES @CMAKE_CONFIGURATION_TYPES@)
  28. # run the executable out of the Debug directory if there
  29. # are configuration types
  30. if(CMAKE_CONFIGURATION_TYPES)
  31. set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/Debug/COnly")
  32. else(CMAKE_CONFIGURATION_TYPES)
  33. set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/COnly")
  34. endif(CMAKE_CONFIGURATION_TYPES)
  35. # run the test results
  36. message("running [${RUN_TEST}]")
  37. execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
  38. if(RESULT)
  39. message(FATAL_ERROR "Error running test COnly")
  40. endif(RESULT)
  41. # build it again with clean and only COnly target
  42. execute_process(COMMAND "${CMAKE_COMMAND}"
  43. --build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug
  44. --clean-first --target COnly
  45. RESULT_VARIABLE RESULT)
  46. if(RESULT)
  47. message(FATAL_ERROR "Error running cmake --build")
  48. endif(RESULT)
  49. # run it again after clean
  50. execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
  51. if(RESULT)
  52. message(FATAL_ERROR "Error running test COnly after clean ")
  53. endif(RESULT)