RunCMakeTest.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. if(run_BuildDepends_skip_step_3)
  32. return()
  33. endif()
  34. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay}) # handle 1s resolution
  35. include(${RunCMake_SOURCE_DIR}/${CASE}.step3.cmake OPTIONAL)
  36. set(check_step 3)
  37. run_cmake_command(${CASE}-build3 ${CMAKE_COMMAND} --build . --config Debug)
  38. endfunction()
  39. set(run_BuildDepends_skip_step_3 1)
  40. run_BuildDepends(C-Exe)
  41. if(NOT RunCMake_GENERATOR STREQUAL "Xcode")
  42. if(RunCMake_GENERATOR MATCHES "Visual Studio 10" OR
  43. RunCMake_GENERATOR_TOOLSET MATCHES "^(v80|v90|v100)$")
  44. # VS 10 forgets to re-link when a manifest changes
  45. set(run_BuildDepends_skip_step_2 1)
  46. endif()
  47. run_BuildDepends(C-Exe-Manifest)
  48. unset(run_BuildDepends_skip_step_2)
  49. endif()
  50. run_BuildDepends(Custom-Symbolic-and-Byproduct)
  51. run_BuildDepends(Custom-Always)
  52. set(RunCMake_TEST_OUTPUT_MERGE_save "${RunCMake_TEST_OUTPUT_MERGE}")
  53. set(RunCMake_TEST_OUTPUT_MERGE 1)
  54. run_BuildDepends(ExternalProjectCacheArgs)
  55. set(RunCMake_TEST_OUTPUT_MERGE "${RunCMake_TEST_OUTPUT_MERGE_save}")
  56. # Test header dependencies with a build tree underneath a source tree.
  57. set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/BuildUnderSource")
  58. set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/BuildUnderSource/build")
  59. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}")
  60. file(MAKE_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/include")
  61. foreach(f CMakeLists.txt BuildUnderSource.cmake BuildUnderSource.c)
  62. configure_file("${RunCMake_SOURCE_DIR}/${f}" "${RunCMake_TEST_SOURCE_DIR}/${f}" COPYONLY)
  63. endforeach()
  64. run_BuildDepends(BuildUnderSource)
  65. unset(RunCMake_TEST_BINARY_DIR)
  66. unset(RunCMake_TEST_SOURCE_DIR)
  67. if(RunCMake_GENERATOR MATCHES "Make")
  68. run_BuildDepends(MakeCustomIncludes)
  69. if(NOT "${RunCMake_BINARY_DIR}" STREQUAL "${RunCMake_SOURCE_DIR}")
  70. run_BuildDepends(MakeInProjectOnly)
  71. endif()
  72. endif()
  73. function(run_ReGeneration)
  74. # test re-generation of project even if CMakeLists.txt files disappeared
  75. # Use a single build tree for a few tests without cleaning.
  76. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/regenerate-project-build)
  77. set(RunCMake_TEST_SOURCE_DIR ${RunCMake_BINARY_DIR}/regenerate-project-source)
  78. set(RunCMake_TEST_NO_CLEAN 1)
  79. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  80. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}")
  81. set(ProjectHeader [=[
  82. cmake_minimum_required(VERSION 3.5)
  83. project(Regenerate-Project NONE)
  84. ]=])
  85. # create project with subdirectory
  86. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" "${ProjectHeader}"
  87. "add_subdirectory(mysubdir)")
  88. file(MAKE_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/mysubdir")
  89. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/mysubdir/CMakeLists.txt" "# empty")
  90. run_cmake(Regenerate-Project)
  91. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay})
  92. # now we delete the subdirectory and adjust the CMakeLists.txt
  93. file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}/mysubdir")
  94. file(WRITE "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" "${ProjectHeader}")
  95. run_cmake_command(Regenerate-Project-Directory-Removed
  96. ${CMAKE_COMMAND} --build "${RunCMake_TEST_BINARY_DIR}")
  97. unset(RunCMake_TEST_BINARY_DIR)
  98. unset(RunCMake_TEST_SOURCE_DIR)
  99. unset(RunCMake_TEST_NO_CLEAN)
  100. endfunction()
  101. if(RunCMake_GENERATOR STREQUAL "Xcode")
  102. run_ReGeneration(regenerate-project)
  103. endif()
  104. if(CMake_TEST_BuildDepends_GNU_AS)
  105. set(ENV{ASM} "${CMake_TEST_BuildDepends_GNU_AS}")
  106. run_BuildDepends(GNU-AS)
  107. endif()
  108. if ((RunCMake_GENERATOR STREQUAL "Unix Makefiles"
  109. AND (CMAKE_C_COMPILER_ID STREQUAL "GNU"
  110. OR CMAKE_C_COMPILER_ID STREQUAL "Clang"
  111. OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang"))
  112. OR (RunCMake_GENERATOR STREQUAL "NMake Makefiles"
  113. AND MSVC_VERSION GREATER 1300
  114. AND CMAKE_C_COMPILER_ID STREQUAL "MSVC"))
  115. run_BuildDepends(CompilerDependencies)
  116. run_BuildDepends(CustomCommandDependencies)
  117. endif()
  118. if (RunCMake_GENERATOR MATCHES "Makefiles")
  119. run_cmake(CustomCommandDependencies-BadArgs)
  120. endif()
  121. if(RunCMake_GENERATOR MATCHES "Make|Ninja")
  122. unset(run_BuildDepends_skip_step_3)
  123. run_BuildDepends(CustomCommandDepfile)
  124. set(run_BuildDepends_skip_step_3 1)
  125. endif()