# Cannot use MSVC\_IDE before first project call?

**URL:** https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734
**Category:** Usage
**Tags:** gen:vs
**Created:** [February 10, 2021, 6:48pm UTC](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734 "2021-02-10T18:48:20Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [February 10, 2021, 6:48pm UTC](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734/1 "2021-02-10T18:48:20Z")

</div>

I’m writing a toolchain file and want to use the MSVC\_IDE variable. However it doesn’t work.

This will not work.

```auto
if (MSVC_IDE)
message(FATAL_ERROR "Foo")
endif()

```

This will work

```auto
if (CMAKE_GENERATOR MATCHES "Visual Studio")
message(FATAL_ERROR "Foo")
endif()

```

Is there a reason why?

---

<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: [February 10, 2021, 7:12pm UTC](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734/2 "2021-02-10T19:12:36Z")

</div>

Hmm. That is set in `Modules/Platform/Windows-MSVC.cmake` using the same conditional as you have here. Are you, perhaps, using `clang-cl`?

Cc: @brad.king

---

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [February 10, 2021, 7:15pm UTC](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734/3 "2021-02-10T19:15:31Z")

</div>

No I’m using MSVC.

---

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [February 10, 2021, 10:17pm UTC](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734/4 "2021-02-10T22:17:00Z")

</div>

This problem isn’t exclusive to toolchains it’s any logic executed before the first project call.

---

<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: [February 10, 2021, 10:39pm UTC](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734/5 "2021-02-10T22:39:32Z")

</div>

Oh! I missed the “toolchain” part, sorry 🤦‍♂️. Yes, the file I linked to is only run at compiler detection time, so yes, it is unavailable to toolchain files. That said, I don’t know how much more work that variable is going to carry, so the `CMAKE_GENERATOR`-based detection is likely the way to go.

---

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [February 10, 2021, 10:44pm UTC](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734/6 "2021-02-10T22:44:39Z")

</div>

Hm gotcha. That’s fine for me. I’d just suggest adding some documentation to clarify this. In case someone runs into this again.

---

<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: [February 10, 2021, 11:21pm UTC](https://discourse.cmake.org/t/cannot-use-msvc-ide-before-first-project-call/2734/7 "2021-02-10T23:21:42Z")

</div>

[https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/5800](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5800)
