CMakeDetermineCSharpCompiler.cmake 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 ([^9]|[9][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)
  18. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
  19. CMAKE_DETERMINE_COMPILER_ID(CSharp CSFLAGS CMakeCSharpCompilerId.cs)
  20. execute_process(COMMAND "${CMAKE_CSharp_COMPILER}" "/help /preferreduilang:en-US" OUTPUT_VARIABLE output)
  21. string(REPLACE "\n" ";" output "${output}")
  22. foreach(line ${output})
  23. string(TOUPPER ${line} line)
  24. string(REGEX REPLACE "^.*COMPILER.*VERSION[^\\.0-9]*([\\.0-9]+).*$" "\\1" version "${line}")
  25. if(version AND NOT "x${line}" STREQUAL "x${version}")
  26. set(CMAKE_CSharp_COMPILER_VERSION ${version})
  27. break()
  28. endif()
  29. endforeach()
  30. message(STATUS "The CSharp compiler version is ${CMAKE_CSharp_COMPILER_VERSION}")
  31. endif()
  32. # configure variables set in this file for fast reload later on
  33. configure_file(${CMAKE_ROOT}/Modules/CMakeCSharpCompiler.cmake.in
  34. ${CMAKE_PLATFORM_INFO_DIR}/CMakeCSharpCompiler.cmake
  35. @ONLY
  36. )