RunCMakeTest.cmake 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. include(RunCMake)
  2. if(RunCMake_GENERATOR STREQUAL "Borland Makefiles" OR
  3. RunCMake_GENERATOR STREQUAL "Watcom WMake")
  4. set(fs_delay 3)
  5. else()
  6. set(fs_delay 1.125)
  7. endif()
  8. function(run_BuildDepends CASE)
  9. # Use a single build tree for a few tests without cleaning.
  10. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${CASE}-build)
  11. set(RunCMake_TEST_NO_CLEAN 1)
  12. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  13. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  14. endif()
  15. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  16. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  17. include(${RunCMake_SOURCE_DIR}/${CASE}.step1.cmake OPTIONAL)
  18. run_cmake(${CASE})
  19. set(RunCMake-check-file check.cmake)
  20. set(check_step 1)
  21. run_cmake_command(${CASE}-build1 ${CMAKE_COMMAND} --build . --config Debug)
  22. if(run_BuildDepends_skip_step_2)
  23. return()
  24. endif()
  25. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay}) # handle 1s resolution
  26. include(${RunCMake_SOURCE_DIR}/${CASE}.step2.cmake OPTIONAL)
  27. set(check_step 2)
  28. run_cmake_command(${CASE}-build2 ${CMAKE_COMMAND} --build . --config Debug)
  29. endfunction()
  30. run_BuildDepends(C-Exe)
  31. if(NOT RunCMake_GENERATOR STREQUAL "Xcode")
  32. if(RunCMake_GENERATOR MATCHES "Visual Studio 10" OR
  33. RunCMake_GENERATOR_TOOLSET MATCHES "^(v80|v90|v100)$")
  34. # VS 10 forgets to re-link when a manifest changes
  35. set(run_BuildDepends_skip_step_2 1)
  36. endif()
  37. run_BuildDepends(C-Exe-Manifest)
  38. unset(run_BuildDepends_skip_step_2)
  39. endif()
  40. run_BuildDepends(Custom-Symbolic-and-Byproduct)
  41. run_BuildDepends(Custom-Always)
  42. if(RunCMake_GENERATOR MATCHES "Make")
  43. run_BuildDepends(MakeCustomIncludes)
  44. if(NOT "${RunCMake_BINARY_DIR}" STREQUAL "${RunCMake_SOURCE_DIR}")
  45. run_BuildDepends(MakeInProjectOnly)
  46. endif()
  47. endif()
  48. function(run_ReGeneration)
  49. # test re-generation of project even if CMakeLists.txt files disappeared
  50. # Use a single build tree for a few tests without cleaning.
  51. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/regenerate-project-build)
  52. set(RunCMake_TEST_SOURCE_DIR ${RunCMake_BINARY_DIR}/regenerate-project-source)
  53. set(RunCMake_TEST_NO_CLEAN 1)
  54. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  55. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}")
  56. set(ProjectHeader [=[
  57. cmake_minimum_required(VERSION 3.5)
  58. project(Regenerate-Project NONE)
  59. ]=])
  60. # create project with subdirectory
  61. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" "${ProjectHeader}"
  62. "add_subdirectory(mysubdir)")
  63. file(MAKE_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/mysubdir")
  64. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/mysubdir/CMakeLists.txt" "# empty")
  65. run_cmake(Regenerate-Project)
  66. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay})
  67. # now we delete the subdirectory and adjust the CMakeLists.txt
  68. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}/mysubdir")
  69. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" "${ProjectHeader}")
  70. run_cmake_command(Regenerate-Project-Directory-Removed
  71. ${CMAKE_COMMAND} --build "${RunCMake_TEST_BINARY_DIR}")
  72. unset(RunCMake_TEST_BINARY_DIR)
  73. unset(RunCMake_TEST_SOURCE_DIR)
  74. unset(RunCMake_TEST_NO_CLEAN)
  75. endfunction()
  76. if(RunCMake_GENERATOR STREQUAL "Xcode")
  77. run_ReGeneration(regenerate-project)
  78. endif()