[CMake] Detecting the target architecture

Jake Petroules jake.petroules at petroules.com
Fri Aug 17 07:58:16 EDT 2012


Hey CMake Developers,

I recently came across the need to detect the architecture of the compilation target in CMake (i.e. i386, x86_64, ppc, ia64, etc.). I was rather surprised to find that CMake apparently doesn't have a function or variable to do this, as such can be useful for things like generating filenames of distribution packages built with CPack, for example.

So I devised a rather creative way to exploit the C preprocessor in combination with try_run in order to do this. It even works when cross compiling (try Visual Studio Itanium!); I've tested it with every generator I had easy access to, including Windows + VS 2008 and 2010 (all variants), NMake, MSYS, OS X + Xcode and regular Unix Makefiles, and Linux with Unix Makefiles.

During my development I did notice one oddity unrelated to my venture - CMake will fail to configure for Itanium using Visual Studio 2010 (works fine on 2008) giving error:
LNK1112: module machine type 'IA64' conflicts with target machine type 'x64'

Anyways, I think that detecting the target architecture is something that could benefit CMake as a whole, so I've uploaded my code to GitHub and if anyone would like to take a look at it and let me know of any potential problems they see with it, suggestions, etc., that would be really helpful. If it could eventually get into mainstream CMake that would be ideal.

https://github.com/jakepetroules/CMakeTargetArch

Thanks!

Jake Petroules
Petroules Corporation (www.petroules.com)
Email: jake.petroules at petroules.com
Telephone: +1 (970) 587-3821

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120817/5ed667a7/attachment.htm>


More information about the CMake mailing list