How do I enable link time optimization (LTO) with CMake?

前端 未结 4 1893
执念已碎
执念已碎 2021-01-30 10:55

I have the most recent cmake build and trying all build configurations (Debug, MinSizeRel, RelWithDebugInfo, Release, General) I see nowhere (text search) in generated makefiles

4条回答
  •  借酒劲吻你
    2021-01-30 11:36

    At the moment both gcc and clang support lto. (See: https://clang.llvm.org/docs/CommandGuide/clang.html https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html ) You can enable it in via cmake: set (CMAKE_INTERPROCEDURAL_OPTIMIZATION True) However you need to have version cmake >= 3.9, and I think may be set some policy and check whether LTO is supported by the compiler / toolchain ( check CMAKE_IPO_AVAILABLE and throw error otherwise)

    And set flags for gcc/clang ( -flto and -ffat-lto-files for fcc >4.7 or -flto=full/thin for clang)

提交回复
热议问题