[CMake] Order of operations in CMakeLists.txt file?
Eric LaFranchi
eric.lafranchi at voltage.com
Fri Dec 18 13:34:12 EST 2009
Hendrik Sattler wrote:
> 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
We build on multiple platforms and some of the platforms have more than
one C/C++ compiler installed. In the CMakeLists.txt we set the compiler
and flags for each platform by switching on the platform based on
CMAKE_SYSTEM_NAME. Can you suggest other mechanisms for doing this type
of operation?
-- Eric
More information about the CMake
mailing list