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

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

    Yep, according to source code there are no support for LTO for gcc/clang compilers. They have some support for Intel compiler only.

    I have some grep output for cmake 3.4.3:

    grep -HiR 'INTERPROCEDURAL_OPTIMIZATION' *
    Help/manual/cmake-properties.7.rst:  
    /prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG
    Help/manual/cmake-properties.7.rst:  
    /prop_dir/INTERPROCEDURAL_OPTIMIZATION
    Help/manual/cmake-properties.7.rst:  
    /prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG
    Help/manual/cmake-properties.7.rst:  
    /prop_tgt/INTERPROCEDURAL_OPTIMIZATION
    Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION.rst:INTERPROCEDURAL_OPTIMIZATION
    Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst:INTERPROCEDURAL_OPTIMIZATION_GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION"))
    Source/cmGeneratorTarget.cxx:          
    "INTERPROCEDURAL_OPTIMIZATION", config))
    Source/cmMakefileLibraryTargetGenerator.cxx: 
    if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION") &&
    Tests/IPO/CMakeLists.txt:set_property(DIRECTORY PROPERTY
    INTERPROCEDURAL_OPTIMIZATION 1)
    

    As you can see we have only Intel platform module.

    So I have created feature request for this extremely useful feature: https://cmake.org/Bug/view.php?id=15939

提交回复
热议问题