RunCMakeTest.cmake 3.9 KB

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