[CMake] Intel compilers

Leif Walsh leif.walsh at gmail.com
Thu May 10 20:35:37 EDT 2012


On Thu, 10 May 2012, Mohammad Mirzadeh wrote:

> Hi,
> 
> I have just started using CMake for my projects and have some problems
> getting it do exactly the things I want. So these are couple of questions I
> have:
> 
> 1) How can I change the compiler from GNU g++ to my preferred compiler, in
> this case intel's icc? I have tried CC=icc; ccmake ../ but that again
> defaults to g++ and picks up wrong compiler flags

You generally need to set CC, CXX, LD, and AR.  I found that in some cases
even that didn't work.  I use this:

option(INTEL_CC "Use the Intel compiler." OFF)

if (INTEL_CC)
  find_program(CMAKE_C_COMPILER NAMES icc)
  find_program(CMAKE_CXX_COMPILER NAMES icpc)
  find_program(CMAKE_AR NAMES xiar)
  find_program(CMAKE_LINKER NAMES xild)

  if (CMAKE_C_COMPILER MATCHES CMAKE_C_COMPILER-NOTFOUND OR
      CMAKE_CXX_COMPILER MATCHES CMAKE_CXX_COMPILER-NOTFOUND OR
      CMAKE_AR MATCHES CMAKE_AR-NOTFOUND OR
      CMAKE_LINKER MATCHES CMAKE_LINKER-NOTFOUND)
    message(FATAL_ERROR "Cannot find Intel compiler.  You may need to run `. /opt/intel/bin/compilervars.sh intel64'")
  endif ()
endif (INTEL_CC)

> 2) When I use the -ipo flag for icc, intel compiler complains that there
> are unresolved references whereas if I omit that, or just use g++, I don't
> have linking problems. Does the order of compilation (except main) matter
> when using target_link_libraries?

What references is it missing?  I'm willing to bet it's having trouble
finding the intel libraries, maybe irc or imf.  Make sure you have sourced
the compiler vars script before running cmake.  Maybe if you tell me what
references it can't find I can help better.

> 3) How can I change from creating static libraries to just simply create
> object files and link to them?

Not sure why you want to do this, but the cmake way to do it is to list
the source files that generate those objects when creating the eventual
target you want to link.  This will compile the same source file multiple
times if it's listed in the declaration of multiple targets.  I suggest
just making a static library.

> Thanks
> 

-- 
Cheers,
Leif


More information about the CMake mailing list