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(CMAKE_CSharp_COMPILER_FORCED) 5 # The compiler configuration was forced by the user. 6 # Assume the user has configured all compiler information. 7 set(CMAKE_CSharp_COMPILER_WORKS TRUE) 8 return() 9endif() 10 11include(CMakeTestCompilerCommon) 12 13unset(CMAKE_CSharp_COMPILER_WORKS CACHE) 14 15set(test_compile_file "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCSharpCompiler.cs") 16 17# This file is used by EnableLanguage in cmGlobalGenerator to 18# determine that the selected C# compiler can actually compile 19# and link the most basic of programs. If not, a fatal error 20# is set and cmake stops processing commands and will not generate 21# any makefiles or projects. 22if(NOT CMAKE_CSharp_COMPILER_WORKS) 23 # Don't call PrintTestCompilerStatus() because the "C#" we want to pass 24 # as the LANG doesn't match with the variable name "CMAKE_CSharp_COMPILER" 25 message(CHECK_START "Check for working C# compiler: ${CMAKE_CSharp_COMPILER}") 26 file(WRITE "${test_compile_file}" 27 "namespace Test {" 28 " public class CSharp {" 29 " static void Main(string[] args) {}" 30 " }" 31 "}" 32 ) 33 # Clear result from normal variable. 34 unset(CMAKE_CSharp_COMPILER_WORKS) 35 # Puts test result in cache variable. 36 try_compile(CMAKE_CSharp_COMPILER_WORKS ${CMAKE_BINARY_DIR} "${test_compile_file}" 37 OUTPUT_VARIABLE __CMAKE_CSharp_COMPILER_OUTPUT 38 ) 39 # Move result from cache to normal variable. 40 set(CMAKE_CSharp_COMPILER_WORKS ${CMAKE_CSharp_COMPILER_WORKS}) 41 unset(CMAKE_CSharp_COMPILER_WORKS CACHE) 42 set(CSharp_TEST_WAS_RUN 1) 43endif() 44 45if(NOT CMAKE_CSharp_COMPILER_WORKS) 46 PrintTestCompilerResult(CHECK_FAIL "broken") 47 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 48 "Determining if the C# compiler works failed with " 49 "the following output:\n${__CMAKE_CSharp_COMPILER_OUTPUT}\n\n") 50 string(REPLACE "\n" "\n " _output "${__CMAKE_CSharp_COMPILER_OUTPUT}") 51 message(FATAL_ERROR "The C# compiler\n \"${CMAKE_CSharp_COMPILER}\"\n" 52 "is not able to compile a simple test program.\nIt fails " 53 "with the following output:\n ${_output}\n\n" 54 "CMake will not be able to correctly generate this project.") 55else() 56 if(CSharp_TEST_WAS_RUN) 57 PrintTestCompilerResult(CHECK_PASS "works") 58 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 59 "Determining if the C# compiler works passed with " 60 "the following output:\n${__CMAKE_CSharp_COMPILER_OUTPUT}\n\n") 61 endif() 62 63 # Re-configure to save learned information. 64 configure_file( 65 ${CMAKE_ROOT}/Modules/CMakeCSharpCompiler.cmake.in 66 ${CMAKE_PLATFORM_INFO_DIR}/CMakeCSharpCompiler.cmake 67 @ONLY 68 ) 69 include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCSharpCompiler.cmake) 70endif() 71