0

I have C++ code that only works when inlined. But VC refuse to inline them in debug mode even when __forceinline is used. I know I can turn them into macros but that's ugly.

After some googling, I found the culprit is /ZI option. I print all the options. But cmake doesn't seem to add the /ZI option. And remove all /Z7, /Zi, /ZI doesn't work.

The only way that solved the issue is by adding the line below in CmakeLists.txt:

add_compile_options(/ZI-)

But it gives me tons of the following warnings

Command line warning D9025: overriding '/Zi' with '/ZI'
Command line warning D9002: ignoring unknown option '/Z-'

Is there a way to turn off /ZI without the warnings?

W.H
  • 1,838
  • 10
  • 24
  • Maybe try enabling/allowing inline function expansion with `/Ob1` or `/Ob2`? Maybe the debug build sets `/Ob0` (disable inlining) by default? – Adrian Mole Sep 29 '22 at 15:05
  • @AdrianMole No luck, and I got tons of `Command line warning D9025: overriding '/Ob0' with '/Ob1'` – W.H Sep 29 '22 at 15:11

1 Answers1

1

CMake is setting /Zi and /Ob0 for debug builds automatically. You can search in CMakeCache.txt for both flags, you will find them in CMAKE_CXX_FLAGS_DEBUG. The cmake script responsible for that is located in <cmake-path>\Modules\Platform\Windows-MSVC.cmake.

You could now remove both flags (as you said, just use CMAKE_CXX_FLAGS_DEBUG). Consider using a custom build configuration instead of changing the debug configuration.

local-ninja
  • 1,198
  • 4
  • 11