RunCMakeTest.cmake 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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(RunCMake_GENERATOR MATCHES "Make|Ninja")
  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")
  33. # VS 10 forgets to re-link when a manifest changes
  34. set(run_BuildDepends_skip_step_2 1)
  35. endif()
  36. run_BuildDepends(C-Exe-Manifest)
  37. unset(run_BuildDepends_skip_step_2)
  38. endif()
  39. run_BuildDepends(Custom-Symbolic-and-Byproduct)
  40. run_BuildDepends(Custom-Always)
  41. if(RunCMake_GENERATOR MATCHES "Make")
  42. if(NOT "${RunCMake_BINARY_DIR}" STREQUAL "${RunCMake_SOURCE_DIR}")
  43. run_BuildDepends(MakeInProjectOnly)
  44. endif()
  45. endif()
  46. function(run_ReGeneration)
  47. # test re-generation of project even if CMakeLists.txt files disappeared
  48. # Use a single build tree for a few tests without cleaning.
  49. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/regenerate-project-build)
  50. set(RunCMake_TEST_SOURCE_DIR ${RunCMake_BINARY_DIR}/regenerate-project-source)
  51. set(RunCMake_TEST_NO_CLEAN 1)
  52. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  53. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}")
  54. set(ProjectHeader [=[
  55. cmake_minimum_required(VERSION 3.5)
  56. project(Regenerate-Project NONE)
  57. ]=])
  58. # create project with subdirectory
  59. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" "${ProjectHeader}"
  60. "add_subdirectory(mysubdir)")
  61. file(MAKE_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/mysubdir")
  62. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/mysubdir/CMakeLists.txt" "# empty")
  63. run_cmake(Regenerate-Project)
  64. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay})
  65. # now we delete the subdirectory and adjust the CMakeLists.txt
  66. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}/mysubdir")
  67. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" "${ProjectHeader}")
  68. run_cmake_command(Regenerate-Project-Directory-Removed
  69. ${CMAKE_COMMAND} --build "${RunCMake_TEST_BINARY_DIR}")
  70. unset(RunCMake_TEST_BINARY_DIR)
  71. unset(RunCMake_TEST_SOURCE_DIR)
  72. unset(RunCMake_TEST_NO_CLEAN)
  73. endfunction()
  74. if(RunCMake_GENERATOR STREQUAL "Xcode")
  75. run_ReGeneration(regenerate-project)
  76. endif()