# CMake 3.21 rc-1 | HIP support breaks custom MSVC toolchain

**URL:** https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629
**Category:** Development
**Tags:** os:windows, comp:msvc
**Created:** [June 25, 2021, 9:13pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629 "2021-06-25T21:13:58Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 25, 2021, 9:13pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/1 "2021-06-25T21:13:58Z")

</div>

Since I’ve upgraded to CMake 3.21 our internal MSVC toolchains have broken.

It’s not longer able to identify the compiler. It’s no longer able to detect the CXX compiler ABI info. As a result it seems to be unable to produce a simple test program.

I’m using Ninja as the generator and I’m using MSVC version 19.28.29910.

My toolchain file for MSVC is pretty minimal. I’m setting the

- CMAKE\_SYSTEM\_PROCESSOR
- CMAKE\_CXX\_COMPILER
- CMAKE\_C\_COMPILER
- CMAKE\_RC\_COMPILER
- CMAKE\_MT

Here is the error message:

```auto
-- The CXX compiler identification is unknown
-- The C compiler identification is unknown
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: d:/dk/win/vc/14.28.29910/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: d:/dk/win/vc/14.28.29910/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/CMake/share/cmake-3.21/Modules/CMakeTestCXXCompiler.cmake:59 (message):
  The C++ compiler

    "d:/dk/win/vc/14.28.29910/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: D:/github/foobar_cmake_modules/tests/test0/build/nin/CMakeFiles/CMakeTmp
    
    Run Build Command(s):D:/dk/win/ninja/1.10.2/ninja.exe cmTC_1f78e && [1/2] Building CXX object CMakeFiles\cmTC_1f78e.dir\testCXXCompiler.cxx.obj
    Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29910 for x64
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
    testCXXCompiler.cxx
    [2/2] Linking CXX executable cmTC_1f78e.exe
    FAILED: cmTC_1f78e.exe 
    cmd.exe /C "cd . && d:\dk\win\vc\14.28.29910\bin\Hostx64\x64\cl.exe /FS /LIBPATH:d:/dk/win/vc/14.28.29910/lib/x64 /LIBPATH:d:/dk/win/vc/14.28.29910/atlmfc/lib/x64 /LIBPATH:d:/dk/win/ms_sdk/n21322/10/lib/10.0.21322.0/ucrt/x64 /LIBPATH:d:/dk/win/ms_sdk/n21322/10/lib/10.0.21322.0/um/x64 /LIBPATH:d:/dk/win/ms_wdk/n21322/lib/10.0.21322.0/km/x64 /LIBPATH:d:/dk/win/ms_wdk/n21322/lib/10.0.21322.0/um/x64 CMakeFiles\cmTC_1f78e.dir\testCXXCompiler.cxx.obj -o cmTC_1f78e.exe && cd ."
    Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29910 for x64
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
    cl : Command line warning D9002 : ignoring unknown option '/LIBPATH:d:/dk/win/vc/14.28.29910/lib/x64'
    cl : Command line warning D9002 : ignoring unknown option '/LIBPATH:d:/dk/win/vc/14.28.29910/atlmfc/lib/x64'
    cl : Command line warning D9002 : ignoring unknown option '/LIBPATH:d:/dk/win/ms_sdk/n21322/10/lib/10.0.21322.0/ucrt/x64'
    cl : Command line warning D9002 : ignoring unknown option '/LIBPATH:d:/dk/win/ms_sdk/n21322/10/lib/10.0.21322.0/um/x64'  
    cl : Command line warning D9002 : ignoring unknown option '/LIBPATH:d:/dk/win/ms_wdk/n21322/lib/10.0.21322.0/km/x64'     
    cl : Command line warning D9002 : ignoring unknown option '/LIBPATH:d:/dk/win/ms_wdk/n21322/lib/10.0.21322.0/um/x64'
    Microsoft (R) Incremental Linker Version 14.28.29910.0
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    /out:testCXXCompiler.cxx.exe 
    /out:cmTC_1f78e.exe
    CMakeFiles\cmTC_1f78e.dir\testCXXCompiler.cxx.obj
    LINK : fatal error LNK1181: cannot open input file 'CMakeFiles\cmTC_1f78e.dir\testCXXCompiler.cxx.obj'
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:22 (project)

-- Configuring incomplete, errors occurred!
See also "D:/github/foobar_cmake_modules/tests/test0/build/nin/CMakeFiles/CMakeOutput.log".
See also "D:/github/foobar_cmake_modules/tests/test0/build/nin/CMakeFiles/CMakeError.log".

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 25, 2021, 9:32pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/2 "2021-06-25T21:32:13Z")

</div>

Hmm. This is quite odd. We do have CI running with this setup, though we’ve moved onto a newer compiler (14.29.30037). Would you be willing and able to bisect the problem?

Looking at your setup, it seems you’re using a different location for the compiler than is normal. There were some changes for “relocatable VS toolchains”, but I don’t the change(s) involved that well.

Cc: @brad.king

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 25, 2021, 9:37pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/3 "2021-06-25T21:37:58Z")

</div>

> [@ben.boeckel](#):
>
> Looking at your setup, it seems you’re using a different location for the compiler than is normal. There were some changes for “relocatable VS toolchains”, but I don’t the change(s) involved that well.

That is correct.

My company basically doesn’t rely on the MSVC compilers provided by Visual Studio. So we host the binaries in a separate location.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 25, 2021, 9:41pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/4 "2021-06-25T21:41:21Z")

</div>

Hmm. I can’t find the MR(s) right now, but if you do have a chance to bisect, searching for where [CMake 3.21 rc-1 | Threads::Threads not found](https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630) got introduced would also be handy.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 25, 2021, 9:44pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/5 "2021-06-25T21:44:32Z")

</div>

> [@ben.boeckel](#):
>
> Hmm. This is quite odd. We do have CI running with this setup, though we’ve moved onto a newer compiler (14.29.30037).

Also I tried using a newer/older compiler and it doesn’t seem to matter at all. I still get the same error.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 25, 2021, 10:22pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/6 "2021-06-25T22:22:32Z")

</div>

> [@ben.boeckel](#):
>
> Would you be willing and able to bisect the problem?

EDIT:  
I think I can figure it out actually.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 28, 2021, 5:16pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/7 "2021-06-28T17:16:27Z")

</div>

I was having issues doing commit bisects but I did narrow the issue down to a change in CMakeDetermineCompilerId.cmake

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 28, 2021, 5:33pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/8 "2021-06-28T17:33:05Z")

</div>

CMakeCxxCompilerId.cmake fails to compile in 3.21 due to not being able to find hip/hip\_version.h

 ![image](https://discourse.cmake.org/uploads/default/original/2X/e/e724cde81eb3243262fae5d6c1d4352b53e6478c.png)

It seems to fail a execute\_process call due to the lack of this hip/hip\_version.h which in turn doesn’t allow the CMake logic to determine the compiler ID causing everything else to fail…

Is there a way to turn HIP off?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 28, 2021, 5:38pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/9 "2021-06-28T17:38:33Z")

</div>

Cc: @robert.maynard

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 28, 2021, 6:09pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/10 "2021-06-28T18:09:19Z")

</div>

Here is the compiler error:

```auto
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: d:/dk/win/vc/14.28.29910/bin/Hostx64/x64/cl.exe 
Build flags: /FS
Id flags: -c 

The output was:
2
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29910 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

CMakeCXXCompilerId.cpp
CMakeCXXCompilerId.cpp(304): fatal error C1034: hip/hip_version.h: no include path set

```

And here is the file:  
[CMakeCXXCompilerId.cpp](https://discourse.cmake.org/uploads/short-url/6A8iV7sXBKTOymERTasTBJ5hGSQ.cpp) (24.9 KB)

This is where it fails to compiler:

```auto
// Fails to compile on this line.... I'm not sure why though...
#elif defined( __clang__ ) && __has_include(<hip/hip_version.h>)
# define COMPILER_ID "ROCMClang"
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
# elif defined( __clang__ )
# define SIMULATE_ID "Clang"
# elif defined( __GNUC__ )
# define SIMULATE_ID "GNU"
# endif
# if defined( __clang__ ) && __has_include(<hip/hip_version.h>)
# include <hip/hip_version.h>
# define COMPILER_VERSION_MAJOR DEC(HIP_VERSION_MAJOR)
# define COMPILER_VERSION_MINOR DEC(HIP_VERSION_MINOR)
# define COMPILER_VERSION_PATCH DEC(HIP_VERSION_PATCH)
# endif

```

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [June 28, 2021, 6:11pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/11 "2021-06-28T18:11:04Z")

</div>

@zackgalbreath

Looking at the compiler detection that would only occur if `__has_include()` returns but the header doesn’t actually exist.

I also don’t think that compiler is supported on windows, so we should drop it from the detection list

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 28, 2021, 6:26pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/12 "2021-06-28T18:26:27Z")

</div>

> [@robert.maynard](#):
>
> Looking at the compiler detection that would only occur if `__has_include()` returns but the header doesn’t actually exist.

You are correct I really don’t understand why this is happening. The logic looks fine to me. Something is happening though to cause it to evaluate to true and try including the HIP header…

I’ll try and see if I can dig any further.

But since HIP currently doesn’t support Windows, I’d appreciate it if you guys dropped it from the detection list for now.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 28, 2021, 6:36pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/13 "2021-06-28T18:36:43Z")

</div>

Just for reference I tried using the compiler directly and it didn’t work either…

 ![image](https://discourse.cmake.org/uploads/default/original/2X/f/f1d4a53d96283ef7205d4e43f44cefd1f9a83c20.png)

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 28, 2021, 6:56pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/14 "2021-06-28T18:56:27Z")

</div>

I think I figured it out.

**In order for \_\_has\_include to work properly on MSVC it requires at least 1 include directory. Since I’m using a toolchain for my toolchain environment and not relying on the developer command prompts it was always failing.**

I cheated and just used the directory that CMakeCXXCompilerId.cpp resides in:

 ![image](https://discourse.cmake.org/uploads/default/original/2X/0/0f6956ecdaf5836b6d24abbd28fd5f72ee28f577.png)

EDIT:

I just confirmed my theory on MSVC \_\_has\_include. It absolutely requires at least one include directory. If I add 1 include directory to my toolchain file it works.

 ![image](https://discourse.cmake.org/uploads/default/original/2X/0/0f477dbe9ea29248fad3cc6cd791d068bfc4c405.png)

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 28, 2021, 7:10pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/15 "2021-06-28T19:10:02Z")

</div>

Basically to summarize this issue here is what happened.

1. 3.21 introduced HIP.
2. HIP’s detection relies on \_\_has\_include
3. MSVC’s \_\_has\_include relies on the user having valid include directories set. Either by the environment/command line.
4. As a result my toolchain broke despite the fact I was using [CMAKE\_LANG\_STANDARD\_INCLUDE\_DIRECTORIES](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_STANDARD_INCLUDE_DIRECTORIES.html)
5. I can fix the problem on my side by adding a include directory to the CMAKE\_LANG\_FLAGS\_INIT variable.

What this means is that CMAKE\_LANG\_STANDARD\_INCLUDE\_DIRECTORIES isn’t taken into account when compiling the CMakeCXXCompiler.\* files. Perhaps it should though?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 28, 2021, 7:28pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/16 "2021-06-28T19:28:50Z")

</div>

> [@buildSystemPerson](#):
>
> What this means is that CMAKE\_LANG\_STANDARD\_INCLUDE\_DIRECTORIES isn’t taken into account when compiling the CMakeCXXCompiler.\* files. Perhaps it should though?

How can it? `CMakeCXXCompiler.*` files are for CMake to figure out what compiler it is dealing with in the first place, so CMake would need to know how to extract standard include directories from a compiler it doesn’t know how to invoke yet (because it doesn’t know the flavor of it)?

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 28, 2021, 7:33pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/17 "2021-06-28T19:33:10Z")

</div>

> [@ben.boeckel](#):
>
> How can it? `CMakeCXXCompiler.*` files are for CMake to figure out what compiler it is dealing with in the first place, so CMake would need to know how to extract standard include directories from a compiler it doesn’t know how to invoke yet (because it doesn’t know the flavor of it)?

Well I guess in my situation I’m using a toolchain file. But obviously not everyone is using a toolchain file like I am.

Do you think adding a dummy include directory is out of the question? Because all MSVC needs is a single include directory to correctly give the expected behavior for \_\_has\_include

Would adding the directory of CMakeCXXCompilerId.cpp be out of the question? As shown above?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 28, 2021, 7:53pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/18 "2021-06-28T19:53:19Z")

</div>

I think it’s better to just guard the `__has_include` stuff for HIP against MSVC (since it’s obviously not a HIP compiler).

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 28, 2021, 7:54pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/19 "2021-06-28T19:54:42Z")

</div>

Fair enough 👍

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [June 29, 2021, 2:08pm UTC](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629/20 "2021-06-29T14:08:22Z")

</div>

> just guard the `__has_include` stuff for HIP against MSVC

That’s fine with me, but how is the `defined( __clang__ )` part of the condition passing on MSVC?

> My company basically doesn’t rely on the MSVC compilers provided by Visual Studio.

Are you using a Clang-derived alternative? What preprocessor definition should be checked to exclude the compiler?

[Next page](https://discourse.cmake.org/t/cmake-3-21-rc-1-hip-support-breaks-custom-msvc-toolchain/3629.md?page=2)
