[CMake] Where to change default link line on Cmake

Brad King brad.king at kitware.com
Wed May 5 10:18:43 EDT 2010


Rene Salmon wrote:
> 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.

FYI, CMake is designed to let users choose their own compiler.  It is
possible to have a project-enforced choice but it is not officially
supported.

You could set the variables at the very top of the CMakeLists.txt
file, *before* the project() command.  However, at that point there
is no CMAKE_SYSTEM_PROCESSOR defined.  The project() command is
where the system and compiler environment is detected.  You might
be able to use execute_process() to run uname yourself though.

Another approach is to disable all languages at project() time and
enable them later with the enable_language() command:

  project(MyProject NONE)
  if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
    set (CMAKE_C_COMPILER xlc_r)
    set (CMAKE_CXX_COMPILER xlc++_r)
    set (CMAKE_C_FLAGS "-O3 -qhot")
    set (CMAKE_Fortran_COMPILER xfl_r)
    set (CMAKE_Fortran_FLAGS "-O3 -qhot)
  endif()
  enable_language(C)
  enable_language(CXX)
  enable_language(Fortran)

I've not tried this though.

-Brad


More information about the CMake mailing list