[CMake] Hi and some newbie questions

wim van hoydonck wim.van.hoydonck at gmail.com
Fri Sep 14 08:10:36 EDT 2007


On 9/14/07, Jack Kelly wrote:
> Goswin von Brederlow wrote:
> > Jack Kelly writes:
> >> # One way would be to have a file i486.cmake:
> >> SET(ARCH i486)
> >> # and whatever else...
> >
> > And cmake automatically includes the right file then?
> >
> >> # A file called x86_64.cmake:
> >> SET(ARCH x86_64)
> >> # ...
> >>
> >> # Put this in the CMakeLists.txt:
> >> INCLUDE(${PLATFORM})
> >>
> >> # and invoke cmake like so:
> >> # cmake -DPLATFORM=x86_64 /path/to/build
> >
> > That would be stupid. It should know itself what architecture to pick.
> I agree, but I can't see a way to let CMake do that. Anyone else have
> any ideas? If you were on a *ix system you could FIND_PROGRAM a copy of
> config.guess and parse its output. Yuk.

On a Unix-like OS, you can execute "uname -m" to get the machine
architecture (but this is probably not really portable to M$...):

EXECUTE_PROCESS(COMMAND uname -m
                RESULT_VARIABLE UNAME_RESULT
                OUTPUT_VARIABLE MACHINE_ARCH)

# test for "not uname_result", since succes is defined as 0
IF (NOT ${UNAME_RESULT})
  MESSAGE(STATUS "machine architecture is ${MACHINE_ARCH}")
ELSE (NOT ${UNAME_RESULT})
  MESSAGE(ERROR "machine architecture is not defined")
ENDIF (NOT ${UNAME_RESULT})


More information about the CMake mailing list