[CMake] Where to change default link line on Cmake
Bill Hoffman
bill.hoffman at kitware.com
Wed May 5 09:07:02 EDT 2010
On 5/4/2010 6:26 PM, Rene Salmon wrote:
>
>
>> Set environment variables to choose your compiler:
>>
>> $ rm -rf build
>> $ mkdir build
>> $ cd build
>> $ export CC=xlc CXX=xlC FC=xlf
>> $ cmake ..
>
> OK. That works. Thanks. But I guess that brings up another question.
>
>
> I have this in my CMakeLists.txt file so that (I thought) would not have to
> set the CC, CXX, and FC environment variables.
>
> # flags ppc64
> if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
> # choose c c++ compilers and flags
> set (CMAKE_C_COMPILER xlc_r)
> set (CMAKE_CXX_COMPILER xlc++_r)
> set (CMAKE_C_FLAGS "-O3 -qhot")
> # choose fortran compilers and flags
> set (CMAKE_Fortran_COMPILER xfl_r)
> set (CMAKE_Fortran_FLAGS "-O3 -qhot)
> endif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
>
>
> The above seems to somewhat work with ccmake as I can do a configure and
> then a generate. I guess it does not work with cmake. How do I pick
> compilers using the CMakeLists.txt file rather than setting environment
> variables.
>
CMake was not really designed to do that. The idea of a cross platform
build system is that it should not force a compiler choice from the
build files. CMake has an order of picking compilers, if there is more
than one on the system, it is going to pick the wrong one some of the
time by definition. So, you have tell it which one to use. If you
really want to do this, you would have to set those variables BEFORE the
project command. However, at that point you would not have
CMAKE_SYSTEM_* or any other vars set. So, you would have to call uname
or something from execute_process to figure that out. However, I would
not recommend this, as someone might want to use a different compiler
some day with your project, and this will not allow that.
-Bill
More information about the CMake
mailing list