如何使用CMake启用链接时间优化(LTO)? [英] How do I enable link time optimization (LTO) with CMake?
问题描述
我具有最新的cmake构建,并尝试了所有构建配置(Debug,MinSizeRel,RelWithDebugInfo,Release,General),但在生成的makefile中,字符串 -lto $ c却无处可见(文本搜索) $ c>,或者功能仍然不存在,或者需要手动换档(在这种情况下,对文档进行LTO或链接时间优化的文本搜索)不会产生任何结果,因此我在官方文档中看不到任何启用方法LTO。
是否有任何方法可以全局启用(对于所有编译器)LTO,而无需手动指定可能仅由GCC支持的标志?
编辑:截至2015年10月28日,在CMake IRC上
jcelerier |我对INTERPROCEDURAL_OPTIMIZATION
jcelerier有疑问|听起来应该在gcc
+ ngladitz上启用-flto | jcelerier:仅针对intel编译器
实现。 ngladitz:好的,
jcelerier | pgo / lto还有其他开关吗?
jcelerier |还是必须手工完成?
+ ngladitz |当前没有一流的支持,否则
相关的CMake问题: https://gitlab.kitware.com/cmake/cmake/issues/15245
CMake在目标上具有 INTERPROCEDURAL_OPTIMIZATION
属性,这听起来像可以在某些平台上启用LTO。 / p>
链接: http://www.cmake.org/cmake/help/v3.0/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html
要在目标MyLib上启用它:
add_library(MyLib ...)
...
set_property(TARGET MyLib PROPERTY INTERPROCEDURAL_OPTIMIZATION True )
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 the string -lto
, so or the functionality is still not present, or it requires manual intervertion (in that case a text search for LTO or Link time optimization) over the documentation gives no result, so I see nowhere in official documentation a way to enable LTO.
Is there any way to enable LTO "globally" (for all compilers) without specifying manually flags that could be at worst supported only by GCC?
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)
这篇关于如何使用CMake启用链接时间优化(LTO)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!