RunCMakeTest.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. if(NOT RunCMake_TEST_BINARY_DIR)
  11. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${CASE}-build)
  12. endif()
  13. set(RunCMake_TEST_NO_CLEAN 1)
  14. if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
  15. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  16. endif()
  17. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  18. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  19. include(${RunCMake_SOURCE_DIR}/${CASE}.step1.cmake OPTIONAL)
  20. run_cmake(${CASE})
  21. set(RunCMake-check-file check.cmake)
  22. set(check_step 1)
  23. run_cmake_command(${CASE}-build1 ${CMAKE_COMMAND} --build . --config Debug)
  24. if(run_BuildDepends_skip_step_2)
  25. return()
  26. endif()
  27. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay}) # handle 1s resolution
  28. include(${RunCMake_SOURCE_DIR}/${CASE}.step2.cmake OPTIONAL)
  29. set(check_step 2)
  30. run_cmake_command(${CASE}-build2 ${CMAKE_COMMAND} --build . --config Debug)
  31. endfunction()
  32. run_BuildDepends(C-Exe)
  33. if(NOT RunCMake_GENERATOR STREQUAL "Xcode")
  34. if(RunCMake_GENERATOR MATCHES "Visual Studio 10" OR
  35. RunCMake_GENERATOR_TOOLSET MATCHES "^(v80|v90|v100)$")
  36. # VS 10 forgets to re-link when a manifest changes
  37. set(run_BuildDepends_skip_step_2 1)
  38. endif()
  39. run_BuildDepends(C-Exe-Manifest)
  40. unset(run_BuildDepends_skip_step_2)
  41. endif()
  42. run_BuildDepends(Custom-Symbolic-and-Byproduct)
  43. run_BuildDepends(Custom-Always)
  44. set(RunCMake_TEST_OUTPUT_MERGE_save "${RunCMake_TEST_OUTPUT_MERGE}")
  45. set(RunCMake_TEST_OUTPUT_MERGE 1)
  46. run_BuildDepends(ExternalProjectCacheArgs)
  47. set(RunCMake_TEST_OUTPUT_MERGE "${RunCMake_TEST_OUTPUT_MERGE_save}")
  48. # Test header dependencies with a build tree underneath a source tree.
  49. set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/BuildUnderSource")
  50. set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/BuildUnderSource/build")
  51. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}")
  52. file(MAKE_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/include")
  53. foreach(f CMakeLists.txt BuildUnderSource.cmake BuildUnderSource.c)
  54. configure_file("${RunCMake_SOURCE_DIR}/${f}" "${RunCMake_TEST_SOURCE_DIR}/${f}" COPYONLY)
  55. endforeach()
  56. run_BuildDepends(BuildUnderSource)
  57. unset(RunCMake_TEST_BINARY_DIR)
  58. unset(RunCMake_TEST_SOURCE_DIR)
  59. if(RunCMake_GENERATOR MATCHES "Make")
  60. run_BuildDepends(MakeCustomIncludes)
  61. if(NOT "${RunCMake_BINARY_DIR}" STREQUAL "${RunCMake_SOURCE_DIR}")
  62. run_BuildDepends(MakeInProjectOnly)
  63. endif()
  64. endif()
  65. function(run_RepeatCMake CASE)
  66. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${CASE}-build)
  67. if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
  68. set(RunCMake_TEST_OPTIONS -DCMAKE_CONFIGURATION_TYPES=Debug)
  69. else()
  70. set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
  71. endif()
  72. run_cmake(${CASE})
  73. set(RunCMake_TEST_NO_CLEAN 1)
  74. run_cmake_command(${CASE}-build1 ${CMAKE_COMMAND} --build . --config Debug)
  75. run_cmake_command(${CASE}-rerun1 ${CMAKE_COMMAND} .)
  76. file(WRITE ${RunCMake_TEST_BINARY_DIR}/exists-for-build2 "")
  77. run_cmake_command(${CASE}-build2 ${CMAKE_COMMAND} --build . --config Debug)
  78. endfunction()
  79. run_RepeatCMake(RepeatCMake-Custom)
  80. function(run_ReGeneration)
  81. # test re-generation of project even if CMakeLists.txt files disappeared
  82. # Use a single build tree for a few tests without cleaning.
  83. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/regenerate-project-build)
  84. set(RunCMake_TEST_SOURCE_DIR ${RunCMake_BINARY_DIR}/regenerate-project-source)
  85. set(RunCMake_TEST_NO_CLEAN 1)
  86. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  87. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}")
  88. set(ProjectHeader [=[
  89. cmake_minimum_required(VERSION 3.5)
  90. project(Regenerate-Project NONE)
  91. ]=])
  92. # create project with subdirectory
  93. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" "${ProjectHeader}"
  94. "add_subdirectory(mysubdir)")
  95. file(MAKE_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/mysubdir")
  96. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/mysubdir/CMakeLists.txt" "# empty")
  97. run_cmake(Regenerate-Project)
  98. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay})
  99. # now we delete the subdirectory and adjust the CMakeLists.txt
  100. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}/mysubdir")
  101. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" "${ProjectHeader}")
  102. run_cmake_command(Regenerate-Project-Directory-Removed
  103. ${CMAKE_COMMAND} --build "${RunCMake_TEST_BINARY_DIR}")
  104. unset(RunCMake_TEST_BINARY_DIR)
  105. unset(RunCMake_TEST_SOURCE_DIR)
  106. unset(RunCMake_TEST_NO_CLEAN)
  107. endfunction()
  108. if(RunCMake_GENERATOR STREQUAL "Xcode")
  109. run_ReGeneration(regenerate-project)
  110. endif()
  111. if(CMake_TEST_BuildDepends_GNU_AS)
  112. set(ENV{ASM} "${CMake_TEST_BuildDepends_GNU_AS}")
  113. run_BuildDepends(GNU-AS)
  114. endif()