1

I use modules on RHEL5 and have various versions of compilers/binutils located on my machine. As such I end up defining environment variables that point to my tools and update paths accordingly so the old tools that shipped with RHEL5 are out of the picture.

Is there a simple method to have cmake load a corresponding environment variable?

For example in my environment:

CMAKE_CXX_COMPILER=/some/other/compiler
CMAKE_LINKER=/some/other/linker

Is there a way to have cmake grab these without passing them as arguments via the commandline?

The following didnt work for me in my CMakeLists.txt

SET(CMAKE_CXX_COMPILER, $ENV{CMAKE_CXX_COMPILER})

And not surprisingly the following also didnt work:

IF($ENV{CMAKE_CXX_COMPILER})
    SET(CMAKE_CXX_COMPILER, $ENV{CMAKE_CXX_COMPILER})
    MESSAGE("CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER}")
ENDIF()

Maybe it is a syntax issue or not the correct place to update such a cmake variable? It does work when I pass via the commandline (e.g. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}), but I dont want to do it that way.

Thanks

1
  • The comma should not be there (in either of the cases). Also, compiler setup is a specific beast in CMake. You'll find $ENV{XYZ} works just fine normally. Commented Jul 23, 2013 at 18:33

1 Answer 1

2

Never mind. It was a syntax error: SET(CMAKE_CXX_COMPILER, $ENV{CMAKE_CXX_COMPILER}) shouldn't have had a comma. The correct syntax is:

SET(CMAKE_CXX_COMPILER $ENV{CMAKE_CXX_COMPILER})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.