views:

1860

answers:

3

Hello I want to build a project with intel compiler.

With default gcc I usually run:

cmake -DCMAKE_CXX_FLAGS=-I/some/path  /path/to/project

And this works fine.

cmake -DCMAKE_CXX_COMPILER=icpc -DCMAKE_C_COMPILER=icc  -DCMAKE_CXX_FLAGS=-I/some/path  /path/to/project

When I try to use non-default compiler it does not path CMAKE_CXX_FLAGS variable content to compiler at all.

How to fix this?

Correct Answer is:

  1. You need to specify the type of the CMAKE_CXX_FLAGS variable:

    -DCMAKE_CXX_FLAGS:STRING=-I/some/path
    
  2. You need to provide full path to C and C++ compilers:

    cmake -DCMAKE_C_COMPILER=/opt/intel/bin/icc -DCMAKE_CXX_COMPILER=/opt/intel/bin/icpc -DCMAKE_CXX_FLAGS:STRING=-some-flag
    
A: 

Is there some reason that you can't add the include path (from your CMAKE_CXX_FLAGS) to your CMakeLists.txt file?

add_includes(/some/path)
greyfade
Yes. I do not want to edit CMakeLists.txt because it is generic file, I just want to add some specifications for specific build. CMake file should not know any kind of local paths of user.
Artyom
Your reasoning doesn't make any sense to me. For the build to work for other people, they would also need the files found in that include path. If that's the case, and it's a 3rd-party library that you can't add to the project, then you should have a Find module for it. Putting additional include paths in the CXX_FLAGS variable is the Wrong Way to do it.
greyfade
"they would also need the files found in **that** include path." Why do you think so, I point with these flags to some custom-non-standard location of my foo-bar library.Your assumptions are wrong. Also... CMakeLists.txt is under source control, so I don't want accidentially put irrelevant changes that point to my local files to upcoming tree.
Artyom
That's what the Find module is for. You add your custom path to the search list and commit it to the tree. Other developers who have it in a different location will never see a problem. Take a look at the implementations of some existing Find modules - they're in the CMake Modules directory.
greyfade
+2  A: 

The good way to do what you expect is to use:

export CC=icc CXX=icpc cmake -DCMAKE_CXX_FLAGS=-I/some/path  /path/to/project
Nadir SOUALEM
Thanks that had worked ;)
Artyom
A: 

I know you don't want to edit the CMakeLists.txt file, but what about editing it allowing the user to select the compiler -- something like

SET(MYVAR TRUE CACHE BOOL "Use intel compiler?")

And later on, if MYVAR variable is set, do the add_includes()..? You can also use some package finding utilities (CMAKE provides some) to find the specific compiler include files, etc.

lorenzog