Cannot use MSVC_IDE before first project call?

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

This will not work.

message(FATAL_ERROR "Foo")

This will work

message(FATAL_ERROR "Foo")

Is there a reason why?

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

No I’m using MSVC.

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

Oh! I missed the “toolchain” part, sorry :man_facepalming:. 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.

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

1 Like