RunCMakeTest.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. include(RunCMake)
  2. # For `if (IN_LIST)`
  3. cmake_policy(SET CMP0057 NEW)
  4. run_cmake(compiler_introspection)
  5. include("${RunCMake_BINARY_DIR}/compiler_introspection-build/info.cmake")
  6. # Test negative cases where C++20 modules do not work.
  7. run_cmake(NoCXX)
  8. if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
  9. # This test requires that the compiler be told to compile in an older-than-20
  10. # standard. If the compiler forces a standard to be used, skip it.
  11. if (NOT forced_cxx_standard)
  12. run_cmake(NoCXX20)
  13. endif ()
  14. # This test uses C++20, but another prerequisite is missing, so forced
  15. # standards don't matter.
  16. run_cmake(NoCXX20ModuleFlag)
  17. endif ()
  18. if (RunCMake_GENERATOR MATCHES "Ninja")
  19. execute_process(
  20. COMMAND "${CMAKE_MAKE_PROGRAM}" --version
  21. RESULT_VARIABLE res
  22. OUTPUT_VARIABLE ninja_version
  23. ERROR_VARIABLE err
  24. OUTPUT_STRIP_TRAILING_WHITESPACE
  25. ERROR_STRIP_TRAILING_WHITESPACE)
  26. if (res)
  27. message(WARNING
  28. "Failed to determine `ninja` version: ${err}")
  29. set(ninja_version "0")
  30. endif ()
  31. endif ()
  32. # Test behavior when the generator does not support C++20 modules.
  33. if (NOT RunCMake_GENERATOR MATCHES "Ninja" OR
  34. ninja_version VERSION_LESS "1.10" OR
  35. NOT "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
  36. if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
  37. run_cmake(NoDyndepSupport)
  38. endif ()
  39. # Bail; the remaining tests require the generator to successfully generate
  40. # with C++20 modules in the source list.
  41. return ()
  42. endif ()
  43. set(fileset_types
  44. Modules
  45. ModuleHeaderUnits)
  46. set(scopes
  47. Interface
  48. Private
  49. Public)
  50. foreach (fileset_type IN LISTS fileset_types)
  51. foreach (scope IN LISTS scopes)
  52. run_cmake("FileSet${fileset_type}${scope}")
  53. endforeach ()
  54. # Test the error message when a non-C++ source file is found in the source
  55. # list.
  56. run_cmake("NotCXXSource${fileset_type}")
  57. endforeach ()