# 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:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![linuxaged](https://discourse.cmake.org/user_avatar/discourse.cmake.org/linuxaged/32/3252_2.png) [@linuxaged](https://discourse.cmake.org/u/linuxaged)
#### Post date: [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/1 "2023-03-13T01:31:37Z")

</div>

```auto
{
    "name": "windows-msvc",
    "hidden": true,
    "generator": "Ninja",
    "binaryDir": "${sourceDir}/out/build/${presetName}",
    "installDir": "${sourceDir}/out/install/${presetName}",
    "cacheVariables": {
        "CMAKE_C_COMPILER": "cl",
        "CMAKE_CXX_COMPILER": "cl",
        "CMAKE_TOOLCHAIN_FILE": {
            "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
            "type": "FILEPATH"
        },
        "CMAKE_C_FLAGS_INIT": "/arch:AVX2 /openmp:experimental /Ob3",
        "CMAKE_CXX_FLAGS_INIT": "/arch:AVX2 /openmp:experimental /Ob3"
    },
    "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
    }
}

```

Command line warning D9025: overriding ‘/Ob3’ with ‘/Ob0’

compile command

```auto
{
  "directory": "C:/workspace/Design/out/build/msvc-Debug",
  "command": "C:\\PROGRA~1\\MICROS~1\\2022\\COMMUN~1\\VC\\Tools\\MSVC\\1434~1.319\\bin\\Hostx64\\x64\\cl.exe /nologo /TP -IC:\\workspace\\Design\\fmt\\include /Ob3 /DWIN32 /D_WINDOWS /W3 /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -std:c++20 /Fofmt\\CMakeFiles\\fmt.dir\\src\\format.cc.obj /FdTARGET_COMPILE_PDB /FS -c C:\\workspace\\Design\\fmt\\src\\format.cc",
  "file": "C:\\workspace\\Design\\fmt\\src\\format.cc"
}

```

---

<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.
