How do I enable IPO for Release build type only?

In my project I have the following code to enable link time optimization on non-debug builds.

include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
if(IPO_SUPPORTED AND (NOT CMAKE_BUILD_TYPE MATCHES Debug))
  set_target_properties(nvim PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

I wanted to rewrite this so that it worked for multi-config generators as well. But as I understand it generator expressions doesn’t work with target properties. How can I write this so that it supports both single and multi config generators?

Perhaps this helps: project_options/Optimization.cmake at main · aminya/project_options · GitHub

Hmm, I don’t think this’ll work for multi-config generators though since it relies on CMAKE_BUILD_TYPE?

There is INTERPROCEDURAL_OPTIMIZATION_<CONFIG>.

4 Likes

Oh wow, missed that completely. OK, thank you!