# Usage of "CMAKE\_MSVC\_RUNTIME\_LIBRARY" prior to project() or not?

**URL:** https://discourse.cmake.org/t/usage-of-cmake-msvc-runtime-library-prior-to-project-or-not/13810
**Category:** Usage
**Created:** [March 25, 2025, 9:12am UTC](https://discourse.cmake.org/t/usage-of-cmake-msvc-runtime-library-prior-to-project-or-not/13810 "2025-03-25T09:12:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Taw\_Moto](https://discourse.cmake.org/user_avatar/discourse.cmake.org/taw_moto/32/5445_2.png) [@Taw\_Moto](https://discourse.cmake.org/u/Taw_Moto)
#### Post date: [March 25, 2025, 9:12am UTC](https://discourse.cmake.org/t/usage-of-cmake-msvc-runtime-library-prior-to-project-or-not/13810/1 "2025-03-25T09:12:42Z")

</div>

Hi,

In CMake, some options (like CMAKE\_OSX\_ARCHITECTURES), should be set before the first “project()” command, which is pretty clear.

But, I need a somehow similar option, CMAKE\_MSVC\_RUNTIME\_LIBRARY, and I want to be 100% sure that I understand the documentation correctly.

The documentation states that:  
_This variable has effect only when policy CMP0091 is set to NEW prior to the first project() or enable\_language() command that enables a language using a compiler targeting the MSVC ABI._

And then about the policy:  
_This policy was introduced in CMake version 3.15. It may be set by cmake\_policy() or cmake\_minimum\_required(). If it is not set, CMake does not warn, and uses OLD behavior._

So my question is: is the following code correct, or should I do something else before using “project()” command?

> cmake\_minimum\_required(VERSION 3.15)  
> project(test C CXX)  
> set(CMAKE\_MSVC\_RUNTIME\_LIBRARY “MultiThreaded$\<$CONFIG:Debug:Debug\>”)

Thank you

---

<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: [March 25, 2025, 2:07pm UTC](https://discourse.cmake.org/t/usage-of-cmake-msvc-runtime-library-prior-to-project-or-not/13810/2 "2025-03-25T14:07:31Z")

</div>

I think only the _policy_ needs to be set before compiler detection (so that the configuration-based flags can avoid mentioning any of the runtime selection flags). The variable/property can be set at any point after that.

---

<div class="post-metadata">

### Author: ![Taw\_Moto](https://discourse.cmake.org/user_avatar/discourse.cmake.org/taw_moto/32/5445_2.png) [@Taw\_Moto](https://discourse.cmake.org/u/Taw_Moto)
#### Post date: [March 25, 2025, 3:16pm UTC](https://discourse.cmake.org/t/usage-of-cmake-msvc-runtime-library-prior-to-project-or-not/13810/3 "2025-03-25T15:16:43Z")

</div>

Thank you for your answer, I understood this way, also.

But after this, seems that if set “cmake\_minimum\_required”, the policy is not needed anymore, and I am not sure about this. Also in “Professional CMake” it states something similar.

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

---

<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: [March 25, 2025, 4:43pm UTC](https://discourse.cmake.org/t/usage-of-cmake-msvc-runtime-library-prior-to-project-or-not/13810/4 "2025-03-25T16:43:39Z")

</div>

Yes, saying that your minimum version is 3.X opts into the `NEW` behavior of all policies introduced as of 3.X.
