[CMake] CMAKE_SYSTEM_PROCESSOR says x86 on Win64

John Drescher drescherjm at gmail.com
Thu Feb 21 14:50:17 EST 2013


On Thu, Feb 21, 2013 at 2:46 PM, Martin Koller <martin.koller at etm.at> wrote:
> Hi all,
>
> I found an old cmake bug entry (see below) for the problem I have:
>
> I downloaded and installed the 32bit cmake exe on a 64bit windows
> and wanted to build our project as 64bit executable. However in our
> cmake files (which are used for Linux, Solaris, windows) we often check
> for the current processor architecture we build for as we need to link
> against external libraries which are stored in different subdirs etc.
>
> Problem is: as cmake is a 32bit exe, wincrap always returns a value
> of "x86" even on a 64bit machine as described here:
> http://blogs.msdn.com/b/david.wang/archive/2006/03/26/howto-detect-process-bitness.aspx
>
> In brief - they say to detect the current CPU shall be done as:
>
> IF PROCESSOR_ARCHITECTURE == amd64 OR
>    PROCESSOR_ARCHITEW6432 == amd64 THEN
>    // OS is 64bit
> ELSE
>    // OS is 32bit
> END IF
>
> I think this should really be fixed in cmake directly to be able
> to use this cmake variable in a true platform independant way
> (at least it already works perfectly for all other platforms)
> and the cmake doc suggest that it tells me excactly that:
> "CMAKE_SYSTEM_PROCESSOR: The name of the CPU CMake is building for."
> which is not correct in this case.
>

Here is what works for me:

if (CMAKE_SIZEOF_VOID_P MATCHES 8)
	set( PROJECT_ARCH "x86_64" )
else(CMAKE_SIZEOF_VOID_P MATCHES 8)
	set( PROJECT_ARCH "x86" )
endif(CMAKE_SIZEOF_VOID_P MATCHES 8)

John


More information about the CMake mailing list