# how to make "/Ob3" flag set in preset not overrided by default "/Ob0" after

**URL:** https://discourse.cmake.org/t/how-to-make-ob3-flag-set-in-preset-not-overrided-by-default-ob0-after/7665
**Category:** Usage
**Created:** [March 13, 2023, 1:31am UTC](https://discourse.cmake.org/t/how-to-make-ob3-flag-set-in-preset-not-overrided-by-default-ob0-after/7665 "2023-03-13T01:31:37Z")
**Posts on this page:** 1
**Showing post:** 2

<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: [March 13, 2023, 9:24pm UTC](https://discourse.cmake.org/t/how-to-make-ob3-flag-set-in-preset-not-overrided-by-default-ob0-after/7665/2 "2023-03-13T21:24:04Z")

</div>

Very similar situation to this post:

> [@How to fix build warning D9025 (Overriding /GR with /GR-)](https://discourse.cmake.org/t/how-to-fix-build-warning-d9025-overriding-gr-with-gr/878/1):
>
> My project needs to disable RTTI however I’m getting this build warning. This is all I’m doing. target\_compile\_optons(foo\_target PRIVATE /GR-)

EDIT:

First off. I would modify your preset slightly.

```auto
"CMAKE_C_FLAGS_INIT": "/arch:AVX2 /openmp:experimental",
"CMAKE_CXX_FLAGS_INIT": "/arch:AVX2 /openmp:experimental"

```

Then in your `CMakeLists.txt` do this after the `first` project call.

```auto
project(FOOBAR)

string(REPLACE "/Ob2" "/Ob3" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "/Ob2" "/Ob3" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})

```

By default CMake has default values for inlining on the MSVC compiler:  
[https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Platform/Windows-MSVC.cmake#L468](https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Platform/Windows-MSVC.cmake#L468)

It maybe worth re-evaluating the defaults now that /Ob3 exists.

Or better yet, not specifying the default at all. Since /O2 implies /Ob2 by default with modern msvc compilers.

`/O2` is equal to `/Og /Oi /Ot /Oy /Ob2 /GF /Gy`

> **[/O1, /O2 (Minimize Size, Maximize Speed)](https://learn.microsoft.com/en-us/cpp/build/reference/o1-o2-minimize-size-maximize-speed?view=msvc-170)**
>
> The MSVC compiler options /O1 and /O2 specify all optimizations for minimum size or maximum speed.

---

_[View the full topic](https://discourse.cmake.org/t/how-to-make-ob3-flag-set-in-preset-not-overrided-by-default-ob0-after/7665)._
