推荐方式通过配置选项与ICC使用CMake的? [英] Recommended ways to use CMake with icc via configuration options?
问题描述
我想用英特尔编译器ICC(或ICPC)与基于CMake的项目(在Linux上为它的价值)。我可以在调用cmake的,例如当当然导出CXX变量像
I would like to use the Intel compiler icc (or icpc) with a CMake-based project (on Linux for what it's worth). I can of course export the CXX variable when calling cmake, e.g. like
CXX=icpc cmake ../
和这工作得很好。不过,我想提出通过自定义选项中提供这种选择。为此,我解析自定义选项,例如
and this works fine. I would however like to make this choice available via a custom option. For this I parse custom option, e.g.
cmake -DMY_COMPILER_OPTION=Intel ..
为
IF (MY_COMPILER_OPTION STREQUAL "Intel")
MESSAGE(STATUS "** Compiling with Intel settings **")
SET(CMAKE_CXX_COMPILER "icpc")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -w")
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
ENDIF ()
和一些编译器标志设置 CMAKE_CXX_COMPILER
在一起。这也适用,但有一个重要的,而是。
and set CMAKE_CXX_COMPILER
together with some compiler flags. This also works, however there is an important "but".
我也想使用的选项与ICC编译时 -ipo
(间优化)为我的code再加上我需要编译中的静态库构建过程。对于这项工作,我需要使用英特尔的 xiar
(也是 xilink
我猜的)。
I would also like to use the option -ipo
(interprocedural optimization) for my code when compiling with icc plus I need to compile a static library within the build process. For this to work, I need to use Intel's xiar
(and also xilink
I guess).
cmake的实际上提供了一个特殊的属性此
cmake actually offers a special property for this
set_property(TARGET mytarget PROPERTY INTERPROCEDURAL_OPTIMIZATION 1)
然而,这似乎只工作正常时,编译器已通过环境变量(当时xiar使用)设置。当通过 CMAKE_CXX_COMPILER
则忽略该属性设置编译器。
however this only seems to works properly when the compiler has been set via the environment variable (then xiar is used). When setting the compiler via CMAKE_CXX_COMPILER
this property is ignored.
有另一种方式做到这一点?一些推荐的方法是什么?或至少一个变通?
Is there another way to do this?. Some recommended way? Or at least a work-around?
推荐答案
好吧,既然已经在这里没有答案,我也转向的有关此问题的帮助CMake的邮件列表名单。专家的同意外,似乎是我试图做到这一点的方式是一个相当糟糕的主意。其原因是,我的定制旗解析恰好在初始化过程晚。因此,人们应该依靠通过设置环境变量编译器,让C进行初始配置运行期间做它的魔力。我将修改我的做法。
Ok, since there have been no answers here, I've also turned to the CMake mailing list list for help on this issue. The consent of the experts there seems to be that the way I was trying to do this is a rather bad idea. The reason is that the parsing of my custom flags happens to late in the initialization process. One should therefore rely on setting the compiler via environment variables and let CMake do its magic during the initial configuration run. I will modify my approach..
这篇关于推荐方式通过配置选项与ICC使用CMake的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!