16

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.

1
  • I am having the same problem as you when using generator as "NMake Makefiles". Your solution didn't work in my case though. Jan 27, 2016 at 1:14

1 Answer 1

14

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.

4
  • 4
    You can use the same string on the command line: cmake -T"Intel C++ Compiler XE 14.0" ...
    – Avi Tevet
    Aug 26, 2015 at 5:08
  • 1
    N.B. the docs say unequivocally "The value of this variable should never be modified by project code."
    – imallett
    Apr 30, 2016 at 18:03
  • 1
    For current version toolset name is "Intel C++ Compiler 16.0"
    – Dženan
    Sep 5, 2016 at 20:57
  • Mirror of the blog link May 21, 2021 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.