如何在Windows下使用cmake生成使用Intel编译器的Visual Studio项目 [英] How to generate a Visual Studio project that uses the Intel Compiler using cmake under Windows

查看:566
本文介绍了如何在Windows下使用cmake生成使用Intel编译器的Visual Studio项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C开发跨平台(Linux/Windows)应用程序.我已经厌倦了维护可用的Makefile和Visual Studio解决方案/项目,因此我想过渡到cmake.我在两个平台上都使用Intel编译器.

I'm developing a cross-platform (Linux/Windows) application in C. I've gotten tired of maintaining both a usable Makefile and the Visual Studio solution/projects so I wanted to transition to cmake. I'm using the Intel Compiler on both platforms.

我已经在Windows上下载了cmake 3.0,在Linux上下载了cmake 2.8(这是ubuntu 12.04存储库中的一个).在Linux上,一切进展顺利,Makefiles已成功生成.运行一个简单的问题即可:CC=icc CXX=icc cmake ...

I've downloaded cmake 3.0 on Windows and cmake 2.8 on Linux (it's the one in ubuntu 12.04 repositories). On Linux everything went smooth and the Makefiles were generated successfully. It was a simple matter of running: CC=icc CXX=icc cmake ...

但是,在Windows上,无论我尝试执行什么命令,都无法使用Intel编译器.输出vcxproj始终使用MSVC编译器.

On Windows, however, no matter what command I try I cannot use the Intel Compiler. The output vcxproj is always using the MSVC compiler.

我尝试了以下命令:

cmake -G "Visual Studio 11 2012 Win64" -D CMAKE_C_COMPILER="C:/Program Files (x86)/Intel/Composer XE/bin/intel64/icl.exe" -D CMAKE_CXX_COMPILER="C:/Program Files (x86)/Intel/Composer XE/bin/intel64/icl.exe" ..

输出为:

-- The C compiler identification is MSVC 17.0.61030.0
-- The CXX compiler identification is MSVC 17.0.61030.0
-- Check for working C compiler using: Visual Studio 11 2012 Win64
-- Check for working C compiler using: Visual Studio 11 2012 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 11 2012 Win64
-- Check for working CXX compiler using: Visual Studio 11 2012 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done

当我将生成器更改为"NMake Makefiles"时,将icc设置为编译器.

When I change the generator to "NMake Makefiles" then icc is set as the compiler.

-- The C compiler identification is Intel 14.0.3.20140422
-- The CXX compiler identification is Intel 14.0.3.20140422
-- Check for working C compiler: C:/Program Files (x86)/Intel/Composer XE/bin/intel64/icl.exe

我正在一个只有一个源文件的非常基本的项目上对此进行测试,因此我的CMakeLists.txt文件仅包含:

I'm testing this on a pretty basic project with only one source file, so my CMakeLists.txt file contains only:

project(dummy_cmake)

add_executable(hellonikola main.c)

任何帮助将不胜感激!

P.S.

cmake-gui的行为相同.我选择指定其他本机编译器,并提供icc的路径,并获得上述输出.

cmake-gui behaves the same. I select to specify a different native compiler and give the path to icc and get the above outputs as well.

我也尝试在Windows上使用cmake 2.8,其行为是相同的.

I've tried using cmake 2.8 on Windows as well and the behaviour is the same.

推荐答案

我找到了答案,所以我将其发布,以防其他人遇到相同的问题.

I've found the answer so I'm posting it in case anyone else has the same problem.

解决方案是将此行添加到CMakeLists.txt

The solution was to add this line to the CMakeLists.txt

set(CMAKE_GENERATOR_TOOLSET "Intel C++ Compiler XE 14.0" CACHE STRING "Platform Toolset" FORCE)

我在此博客上找到了并使其适合使用Intel编译器.

I found this out on this blog and adapted it to use the Intel Compiler.

这篇关于如何在Windows下使用cmake生成使用Intel编译器的Visual Studio项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆