CMakeDetermineCSharpCompiler.cmake 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio ([^89]|[89][0-9])")
  4. message(FATAL_ERROR
  5. "C# is currently only supported for Microsoft Visual Studio 2010 and later.")
  6. endif()
  7. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
  8. #include(Platform/${CMAKE_SYSTEM_NAME}-Determine-CSharp OPTIONAL)
  9. #include(Platform/${CMAKE_SYSTEM_NAME}-CSharp OPTIONAL)
  10. if(NOT CMAKE_CSharp_COMPILER_NAMES)
  11. set(CMAKE_CSharp_COMPILER_NAMES csc)
  12. endif()
  13. # Build a small source file to identify the compiler.
  14. if(NOT CMAKE_CSharp_COMPILER_ID_RUN)
  15. set(CMAKE_CSharp_COMPILER_ID_RUN 1)
  16. # Try to identify the compiler.
  17. set(CMAKE_CSharp_COMPILER_ID_STRINGS_PARAMETERS ENCODING UTF-16LE)
  18. set(CMAKE_CSharp_COMPILER_ID)
  19. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
  20. CMAKE_DETERMINE_COMPILER_ID(CSharp CSFLAGS CMakeCSharpCompilerId.cs)
  21. execute_process(COMMAND "${CMAKE_CSharp_COMPILER}" "/help /preferreduilang:en-US" OUTPUT_VARIABLE output)
  22. string(REPLACE "\n" ";" output "${output}")
  23. foreach(line ${output})
  24. string(TOUPPER ${line} line)
  25. string(REGEX REPLACE "^.*COMPILER.*VERSION[^\\.0-9]*([\\.0-9]+).*$" "\\1" version "${line}")
  26. if(version AND NOT "x${line}" STREQUAL "x${version}")
  27. set(CMAKE_CSharp_COMPILER_VERSION ${version})
  28. break()
  29. endif()
  30. endforeach()
  31. message(STATUS "The CSharp compiler version is ${CMAKE_CSharp_COMPILER_VERSION}")
  32. endif()
  33. # configure variables set in this file for fast reload later on
  34. configure_file(${CMAKE_ROOT}/Modules/CMakeCSharpCompiler.cmake.in
  35. ${CMAKE_PLATFORM_INFO_DIR}/CMakeCSharpCompiler.cmake
  36. @ONLY
  37. )