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

Eric LaFranchi eric.lafranchi at voltage.com
Thu Dec 17 19:05:31 EST 2009


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?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091217/022245ad/attachment-0001.htm>


More information about the CMake mailing list