CMakeTestCSharpCompiler.cmake 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. if(CMAKE_CSharp_COMPILER_FORCED)
  4. # The compiler configuration was forced by the user.
  5. # Assume the user has configured all compiler information.
  6. set(CMAKE_CSharp_COMPILER_WORKS TRUE)
  7. return()
  8. endif()
  9. include(CMakeTestCompilerCommon)
  10. unset(CMAKE_CSharp_COMPILER_WORKS CACHE)
  11. set(test_compile_file "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCSharpCompiler.cs")
  12. # This file is used by EnableLanguage in cmGlobalGenerator to
  13. # determine that the selected C# compiler can actually compile
  14. # and link the most basic of programs. If not, a fatal error
  15. # is set and cmake stops processing commands and will not generate
  16. # any makefiles or projects.
  17. if(NOT CMAKE_CSharp_COMPILER_WORKS)
  18. PrintTestCompilerStatus("C#" "${CMAKE_CSharp_COMPILER}")
  19. file(WRITE "${test_compile_file}"
  20. "namespace Test {"
  21. " public class CSharp {"
  22. " static void Main(string[] args) {}"
  23. " }"
  24. "}"
  25. )
  26. try_compile(CMAKE_CSharp_COMPILER_WORKS ${CMAKE_BINARY_DIR} "${test_compile_file}"
  27. OUTPUT_VARIABLE __CMAKE_CSharp_COMPILER_OUTPUT
  28. )
  29. # Move result from cache to normal variable.
  30. set(CMAKE_CSharp_COMPILER_WORKS ${CMAKE_CSharp_COMPILER_WORKS})
  31. unset(CMAKE_CSharp_COMPILER_WORKS CACHE)
  32. set(CSharp_TEST_WAS_RUN 1)
  33. endif()
  34. if(NOT CMAKE_CSharp_COMPILER_WORKS)
  35. PrintTestCompilerStatus("C#" "${CMAKE_CSharp_COMPILER} -- broken")
  36. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  37. "Determining if the C# compiler works failed with "
  38. "the following output:\n${__CMAKE_CSharp_COMPILER_OUTPUT}\n\n")
  39. string(REPLACE "\n" "\n " _output "${__CMAKE_CSharp_COMPILER_OUTPUT}")
  40. message(FATAL_ERROR "The C# compiler\n \"${CMAKE_CSharp_COMPILER}\"\n"
  41. "is not able to compile a simple test program.\nIt fails "
  42. "with the following output:\n ${_output}\n\n"
  43. "CMake will not be able to correctly generate this project.")
  44. else()
  45. if(CSharp_TEST_WAS_RUN)
  46. PrintTestCompilerStatus("C#" "${CMAKE_CSharp_COMPILER} -- works")
  47. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  48. "Determining if the C# compiler works passed with "
  49. "the following output:\n${__CMAKE_CSharp_COMPILER_OUTPUT}\n\n")
  50. endif()
  51. # Re-configure to save learned information.
  52. configure_file(
  53. ${CMAKE_ROOT}/Modules/CMakeCSharpCompiler.cmake.in
  54. ${CMAKE_PLATFORM_INFO_DIR}/CMakeCSharpCompiler.cmake
  55. @ONLY
  56. )
  57. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCSharpCompiler.cmake)
  58. endif()