RunCMake.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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} --help
  11. RESULT_VARIABLE result
  12. OUTPUT_VARIABLE stdout
  13. ERROR_VARIABLE stderr
  14. WORKING_DIRECTORY ${dir})
  15. string(REPLACE ";" "\\;" stdout "${stdout}")
  16. string(REPLACE "\n" "E;" stdout "${stdout}")
  17. set(collecting 0)
  18. set(generators)
  19. foreach(eline ${stdout})
  20. string(REGEX REPLACE "^(.*)E$" "\\1" line "${eline}")
  21. if(collecting AND NOT line STREQUAL "")
  22. if(line MATCHES "=")
  23. string(REGEX REPLACE "^ (.+)= (.*)$" "\\1" gen "${line}")
  24. if(gen MATCHES "[A-Za-z]")
  25. string(REGEX REPLACE "^(.*[^ ]) +$" "\\1" gen "${gen}")
  26. if(gen)
  27. set(generators ${generators} ${gen})
  28. endif()
  29. endif()
  30. else()
  31. if(line MATCHES "^ [A-Za-z0-9]")
  32. string(REGEX REPLACE "^ (.+)$" "\\1" gen "${line}")
  33. string(REGEX REPLACE "^(.*[^ ]) +$" "\\1" gen "${gen}")
  34. if(gen)
  35. set(generators ${generators} ${gen})
  36. endif()
  37. endif()
  38. endif()
  39. endif()
  40. if(line STREQUAL "The following generators are available on this platform:")
  41. set(collecting 1)
  42. endif()
  43. endforeach()
  44. # Also call with one non-existent generator:
  45. #
  46. set(generators ${generators} "BOGUS_CMAKE_GENERATOR")
  47. # Call cmake with -G on each available generator. We do not care if this
  48. # succeeds or not. We expect it *not* to succeed if the underlying packaging
  49. # tools are not installed on the system... This test is here simply to add
  50. # coverage for the various cmake generators, even/especially to test ones
  51. # where the tools are not installed.
  52. #
  53. message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
  54. message(STATUS "CMake generators='${generators}'")
  55. # First setup a source tree to run CMake on.
  56. #
  57. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
  58. ${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast
  59. ${dir}/Source
  60. )
  61. foreach(g ${generators})
  62. message(STATUS "cmake -G \"${g}\" ..")
  63. # Create a binary directory for each generator:
  64. #
  65. execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
  66. ${dir}/Source/${g}
  67. )
  68. # Run cmake:
  69. #
  70. execute_process(COMMAND ${CMAKE_COMMAND} -G ${g} ..
  71. RESULT_VARIABLE result
  72. OUTPUT_VARIABLE stdout
  73. ERROR_VARIABLE stderr
  74. WORKING_DIRECTORY ${dir}/Source/${g}
  75. )
  76. message(STATUS "result='${result}'")
  77. message(STATUS "stdout='${stdout}'")
  78. message(STATUS "stderr='${stderr}'")
  79. message(STATUS "")
  80. endforeach()
  81. message(STATUS "CMake generators='${generators}'")
  82. message(STATUS "CMAKE_COMMAND='${CMAKE_COMMAND}'")