RunCMakeTest.cmake 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. include(RunCMake)
  2. unset(RunCMake_TEST_NO_CLEAN)
  3. function(run_cmake_with_cmp0168 name)
  4. run_cmake_with_options("${name}" -D CMP0168=OLD ${ARGN})
  5. set(RunCMake_TEST_VARIANT_DESCRIPTION "-direct")
  6. run_cmake_with_options("${name}" -D CMP0168=NEW ${ARGN})
  7. endfunction()
  8. # Won't get to the part where CMP0168 matters
  9. run_cmake_with_options(MissingDetails -D CMP0168=NEW)
  10. # These are testing specific aspects of the sub-build
  11. run_cmake_with_options(SameGenerator -D CMP0168=OLD)
  12. run_cmake_with_options(VarPassthroughs -D CMP0168=OLD)
  13. run_cmake_with_cmp0168(DirectIgnoresDetails)
  14. run_cmake_with_cmp0168(FirstDetailsWin)
  15. block(SCOPE_FOR VARIABLES)
  16. # Reuse this test to also verify that "cmake --fresh" re-executes the steps
  17. # when using the direct mode
  18. set(RunCMake_TEST_NO_CLEAN 1)
  19. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/FirstDetailsWin-direct-build)
  20. set(RunCMake_TEST_VARIANT_DESCRIPTION "-direct-fresh")
  21. run_cmake_with_options(FirstDetailsWin -D CMP0168=NEW --fresh)
  22. endblock()
  23. run_cmake_with_cmp0168(DownloadTwice)
  24. run_cmake_with_cmp0168(DownloadFile)
  25. run_cmake_with_cmp0168(IgnoreToolchainFile)
  26. run_cmake_with_cmp0168(System)
  27. run_cmake_with_cmp0168(VarDefinitions)
  28. run_cmake_with_cmp0168(GetProperties)
  29. run_cmake_with_cmp0168(UsesTerminalOverride)
  30. run_cmake_with_cmp0168(MakeAvailable)
  31. run_cmake_with_cmp0168(MakeAvailableTwice)
  32. run_cmake_with_cmp0168(MakeAvailableUndeclared)
  33. run_cmake_with_cmp0168(VerifyHeaderSet)
  34. run_cmake_with_cmp0168(FindDependencyExport
  35. -D "CMAKE_PROJECT_TOP_LEVEL_INCLUDES=${CMAKE_CURRENT_LIST_DIR}/FindDependencyExportDP.cmake"
  36. )
  37. run_cmake_with_cmp0168(ManualSourceDirectory
  38. -D "FETCHCONTENT_SOURCE_DIR_WITHPROJECT=${CMAKE_CURRENT_LIST_DIR}/WithProject"
  39. )
  40. run_cmake_with_cmp0168(ManualSourceDirectoryMissing
  41. -D "FETCHCONTENT_SOURCE_DIR_WITHPROJECT=${CMAKE_CURRENT_LIST_DIR}/ADirThatDoesNotExist"
  42. )
  43. # Need to use :STRING to prevent CMake from automatically converting it to an
  44. # absolute path
  45. run_cmake_with_cmp0168(ManualSourceDirectoryRelative
  46. -D "FETCHCONTENT_SOURCE_DIR_WITHPROJECT:STRING=WithProject"
  47. )
  48. function(run_FetchContent_DirOverrides cmp0168)
  49. if(cmp0168 STREQUAL "NEW")
  50. set(RunCMake_TEST_VARIANT_DESCRIPTION "-direct")
  51. endif()
  52. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/DirOverrides${RunCMake_TEST_VARIANT_DESCRIPTION}-build)
  53. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  54. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  55. run_cmake_with_options(DirOverrides -D CMP0168=${cmp0168})
  56. set(RunCMake_TEST_NO_CLEAN 1)
  57. run_cmake_with_options(DirOverridesDisconnected
  58. -D CMP0168=${cmp0168}
  59. -D FETCHCONTENT_FULLY_DISCONNECTED=YES
  60. )
  61. endfunction()
  62. run_FetchContent_DirOverrides(OLD)
  63. run_FetchContent_DirOverrides(NEW)
  64. set(RunCMake_TEST_OUTPUT_MERGE 1)
  65. run_cmake_with_cmp0168(PreserveEmptyArgs)
  66. set(RunCMake_TEST_OUTPUT_MERGE 0)
  67. function(run_FetchContent_ExcludeFromAll)
  68. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExcludeFromAll-build)
  69. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  70. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  71. # We're testing FetchContent_MakeAvailable()'s add_subdirectory() behavior,
  72. # so it doesn't matter if we use OLD or NEW for CMP0168, but NEW is faster.
  73. run_cmake(ExcludeFromAll -D CMP0168=NEW)
  74. set(RunCMake_TEST_NO_CLEAN 1)
  75. run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build .)
  76. endfunction()
  77. run_FetchContent_ExcludeFromAll()
  78. # Script mode testing requires more care for CMP0168 set to OLD.
  79. # We need to pass through CMAKE_GENERATOR and CMAKE_MAKE_PROGRAM
  80. # to ensure the test can run on machines where the build tool
  81. # isn't on the PATH. Some build machines explicitly test with such
  82. # an arrangement (e.g. to test with spaces in the path). We also
  83. # pass through the platform and toolset for completeness, even
  84. # though we don't build anything, just in case this somehow affects
  85. # the way the build tool is invoked.
  86. run_cmake_command(ScriptMode
  87. ${CMAKE_COMMAND}
  88. -DCMP0168=OLD
  89. -DCMAKE_GENERATOR=${RunCMake_GENERATOR}
  90. -DCMAKE_GENERATOR_PLATFORM=${RunCMake_GENERATOR_PLATFORM}
  91. -DCMAKE_GENERATOR_TOOLSET=${RunCMake_GENERATOR_TOOLSET}
  92. -DCMAKE_MAKE_PROGRAM=${RunCMake_MAKE_PROGRAM}
  93. -P ${CMAKE_CURRENT_LIST_DIR}/ScriptMode.cmake
  94. )
  95. # CMP0168 NEW doesn't need a build tool or generator, so don't set them.
  96. run_cmake_command(ScriptMode-direct
  97. ${CMAKE_COMMAND}
  98. -DCMP0168=NEW
  99. -P ${CMAKE_CURRENT_LIST_DIR}/ScriptMode.cmake
  100. )
  101. run_cmake(DisableSourceChanges)