From c6aaaf066a39485bf34869ccae5b5d4fac04f0b9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 29 Jun 2021 12:53:02 -0400 Subject: DetermineCompiler: Restore identification of MSVC with no INCLUDE dirs Since commit bd844387df (ROCMClang: Add the ROCm toolkit derived clang compiler to CMake, 2020-08-28, v3.21.0-rc1~66^2~6), our generated compiler id source file contains a preprocessor condition of the form #elif ... && __has_include(...) When MSVC is invoked with no include directories in the `INCLUDE` environment variable or in `-I` flags, its implementation of `__has_include` errors out immediately. This breaks identification of the compiler. Work around the problem by adding a fallback attempt to compile the identification source using a dummy include directory. --- Modules/CMakeDetermineCCompiler.cmake | 4 ++++ Modules/CMakeDetermineCXXCompiler.cmake | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index cd07ba9..ca497f1 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -85,6 +85,10 @@ else() # ARMClang need target options "--target=arm-arm-none-eabi -mcpu=cortex-m3" + + # MSVC needs at least one include directory for __has_include to function, + # but custom toolchains may run MSVC with no INCLUDE env var and no -I flags. + "-I__does_not_exist__" ) endif() if(CMAKE_C_COMPILER_TARGET) diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index 3d1a7bb..e297f90 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -80,6 +80,10 @@ else() # ARMClang need target options "--target=arm-arm-none-eabi -mcpu=cortex-m3" + + # MSVC needs at least one include directory for __has_include to function, + # but custom toolchains may run MSVC with no INCLUDE env var and no -I flags. + "-I__does_not_exist__" ) endif() -- cgit v0.12