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

前端 未结 4 1895
执念已碎
执念已碎 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:34

    Edit: as of 28 October, 2015 on CMake IRC

    jcelerier | I have a question about INTERPROCEDURAL_OPTIMIZATION
    jcelerier | it sounds like it should enable -flto on gcc
    +ngladitz | jcelerier: its only implemented for the intel compiler
    jcelerier | ngladitz: ah, okay
    jcelerier | are there other switches for pgo / lto ?
    jcelerier | or must it be done by hand ?
    +ngladitz | there currently is no first class support otherwise     
    

    Related CMake issue: https://gitlab.kitware.com/cmake/cmake/issues/15245


    CMake has the INTERPROCEDURAL_OPTIMIZATION property on targets, which sounds like it may enable LTO on some platforms.

    Link : http://www.cmake.org/cmake/help/v3.0/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html

    To enable it on a target MyLib :

    add_library(MyLib ...)
    ...
    set_property(TARGET MyLib PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
    

提交回复
热议问题