RunCMake.cmake 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. if(NOT DEFINED CMake_SOURCE_DIR)
  2. message(FATAL_ERROR "CMake_SOURCE_DIR not defined")
  3. endif()
  4. if(NOT DEFINED dir)
  5. message(FATAL_ERROR "dir not defined")
  6. endif()
  7. # Analyze 'cmake --help' output for list of available generators:
  8. #
  9. execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${dir})
  10. execute_process(COMMAND ${CMAKE_COMMAND} -E capabilities
  11. RESULT_VARIABLE result
  12. OUTPUT_VARIABLE stdout
  13. ERROR_VARIABLE stderr
  14. WORKING_DIRECTORY ${dir})
  15. set(generators)
  16. string(REGEX MATCHALL [["name":"[^"]+","platformSupport"]] generators_json "${stdout}")
  17. foreach(gen_json IN LISTS generators_json)
  18. if("${gen_json}" MATCHES [["name":"([^"]+)"]])
  19. set(gen "${CMAKE_MATCH_1}")
  20. if(NOT gen MATCHES " (Win64|IA64|ARM)$")
  21. list(APPEND generators "${gen}")
  22. endif()
  23. endif()
  24. endforeach()
  25. list(REMOVE_DUPLICATES generators)
  26. # Also call with one non-existent generator:
  27. #
  28. set(generators ${generators} "BOGUS_CMAKE_GENERATOR")
  29. # Call cmake with -G on each available generator. We do not care if this
  30. # succeeds or not. We expect it *not* to succeed if the underlying packaging
  31. # tools are not installed on the system... This test is here simply to add
  32. # coverage for the various cmake generators, even/especially to test ones
  33. # where the tools are not installed.
  34. #
  35. message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
  36. message(STATUS "CMake generators='${generators}'")
  37. # First setup a source tree to run CMake on.
  38. #
  39. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
  40. ${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast
  41. ${dir}/Source
  42. )
  43. foreach(g ${generators})
  44. message(STATUS "cmake -G \"${g}\" ..")
  45. # Create a binary directory for each generator:
  46. #
  47. execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
  48. ${dir}/Source/${g}
  49. )
  50. # Run cmake:
  51. #
  52. execute_process(COMMAND ${CMAKE_COMMAND} -G ${g} ..
  53. RESULT_VARIABLE result
  54. OUTPUT_VARIABLE stdout
  55. ERROR_VARIABLE stderr
  56. WORKING_DIRECTORY ${dir}/Source/${g}
  57. )
  58. message(STATUS "result='${result}'")
  59. message(STATUS "stdout='${stdout}'")
  60. message(STATUS "stderr='${stderr}'")
  61. message(STATUS "")
  62. endforeach()
  63. message(STATUS "CMake generators='${generators}'")
  64. message(STATUS "CMAKE_COMMAND='${CMAKE_COMMAND}'")