niking
niking

Reputation: 494

How to generate a Visual Studio project that uses the Intel Compiler using cmake under Windows

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.

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 ...

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

I've tried the following command:

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 output is:

-- 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

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

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)

Any help is greatly appreciated!

P.S.

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.

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

Upvotes: 17

Views: 6108

Answers (1)

niking
niking

Reputation: 494

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

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)

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

Upvotes: 14

Related Questions