[CMake] Determining good GCC parameters

Antti S. Lankila alankila at bel.fi
Tue Aug 22 06:06:39 EDT 2006


Is there a facility for determining good GCC parameters for compiling 
C/C++ source for host system?

I know that gcc 4.1/4.2 is on the verge of getting "-march=native" or 
some such that will compile code suitable to run on the host system. In 
this model, GCC will detect the supported instruction capabilities and 
CPU type and set the -march=foo parameter automatically to close match 
of the host type. But until -march=native can be relied on, gcc versions 
3.x and 4.0 at least should have some method to specify -march=pentium4 
for a P4 system, and so on. Additionally, for athlon64 I'd like to 
manually specify -msse3 because the architecture supports most of SSE3 
(only missing out on support for some hyperthreading instructions).

On the other hand, a wide range of customizability is required on top of 
good automatic default. For instance, distributors who wish to support 
wider architecture base are unlikely to want to specify a recent 
architecture or SSE3, probably option to some generic -mcpu=pentium4 
-mtune=crusoe or something such. Clearly, one aspect of the problem is 
"generic build" vs. "machine-optimised build".

Finally, some options also depend on the compiler version, for instance, 
if the compiler is gcc 4.x, -ftree-vectorize option might produce 
significantly better code for some DSP-type loops without user 
explicitly coding for SSE/SSE2/mmx/3dnow/what-have-you.

To this end, I was wondering: what kind of facilities are there in cmake 
to support different host targets? I'm aware of the BUILD_TYPE variable, 
but the axis between debug build and release build is just one axis of a 
wider configuration space.

1) how would I find out the version of GCC I'm running on?

2) how would I obtain precise knowledge about the host architecture I'm 
running on?

3) how would an user best configure the cmake build system to do a 
generic instead of native build?

-- 
Antti


More information about the CMake mailing list