[CMake] Order of operations in CMakeLists.txt file?

Hendrik Sattler post at hendrik-sattler.de
Fri Dec 18 03:12:21 EST 2009


Zitat von Eric LaFranchi <eric.lafranchi at voltage.com>:

> I'm confused about the following documentation.
>
> The CMake FAQ section "How do I use a different compiler?" states:
> "Set the appropriate CMAKE_FOO_COMPILER variable(s) to a valid   
> compiler name or full path in a list file using set(). This must be   
> done before any language is set (ie before any project() or   
> enable_language() command)."
>
> I want to conditionally choose the compiler based on platform. My   
> CMakeList.txt contains code similar to the following:
> cmake_minimum_required (VERSION 2.6)
> if (CMAKE_SYSTEM_NAME STREQUAL "Platform1")
>     set (CMAKE_C_COMPILER cc1)
>     set (CMAKE_C_FLAGS -XYZ1)
> elseif (CMAKE_SYSTEM_NAME STREQUAL "platform2")
>     set (CMAKE_C_COMPILER cc2)
>     set (CMAKE_C_FLAGS -XYZ2)
> endif()
> project(test)
> ...
>
> However, before "project()"  is called, the CMAKE_SYSTEM_NAME   
> appears undefined. When is CMAKE_SYSTEM_NAME defined?
> Is another option available to switch on the system before   
> "project()" is invoked?

use
   project(test NONE)
to not enable any language. Then CMAKE_SYSTEM_NAME should be defined.
OTOH, you may want to think again about your approach of doing things.  
It makes it impossible to change compilers on a platform without  
changing the CMakeList.txt file. What exactly is your use-case for the  
above stuff?

HS




More information about the CMake mailing list