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