RunCMake.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. # If we'll be testing any of the MinGW Makefiles generators, adjust the
  56. # ENV{PATH} to make sure libgmp-10.dll can be loaded as needed. But only if
  57. # the testing machine has a default MinGW install... (If you have a
  58. # non-default install, append to the PATH before running the test...)
  59. #
  60. if(generators MATCHES "MinGW Makefiles")
  61. if(EXISTS "C:/MinGW/bin/libgmp-10.dll")
  62. string(TOLOWER "$ENV{PATH}" path)
  63. if(NOT path MATCHES "/mingw/bin")
  64. if(UNIX)
  65. set(sep ":")
  66. set(mingw_bin "/mingw/bin")
  67. else()
  68. set(sep ";")
  69. set(mingw_bin "C:/MinGW/bin")
  70. endif()
  71. set(ENV{PATH} "$ENV{PATH}${sep}${mingw_bin}")
  72. message(STATUS "info: appending '${sep}${mingw_bin}' to the PATH")
  73. endif()
  74. endif()
  75. endif()
  76. # First setup a source tree to run CMake on.
  77. #
  78. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
  79. ${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast
  80. ${dir}/Source
  81. )
  82. foreach(g ${generators})
  83. message(STATUS "cmake -G \"${g}\" ..")
  84. # Create a binary directory for each generator:
  85. #
  86. execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
  87. ${dir}/Source/${g}
  88. )
  89. # Run cmake:
  90. #
  91. execute_process(COMMAND ${CMAKE_COMMAND} -G ${g} ..
  92. RESULT_VARIABLE result
  93. OUTPUT_VARIABLE stdout
  94. ERROR_VARIABLE stderr
  95. WORKING_DIRECTORY ${dir}/Source/${g}
  96. )
  97. message(STATUS "result='${result}'")
  98. message(STATUS "stdout='${stdout}'")
  99. message(STATUS "stderr='${stderr}'")
  100. message(STATUS "")
  101. endforeach()
  102. message(STATUS "CMake generators='${generators}'")
  103. message(STATUS "CMAKE_COMMAND='${CMAKE_COMMAND}'")