[CMake] Properly Detecting Win64

Rolf Eike Beer eike at sf-mail.de
Wed Apr 13 03:47:16 EDT 2011


> Maybe you can base the package name by testing the generator name.

I need to do that to e.g. get a useful build naming in CTest scripts. At
that point CMAKE_SIZEOF_VOID_P is not available anyway. And I think that
using this is just a bad idea. How do you decide if it's IA64 or AMD64?

I use this at the moment:

FUNCTION(GET_NMAKE_VERSION_STRING var)
	IF(MSVC_VERSION EQUAL 1400)
		SET(ver_string "vs8")
	ELSEIF(MSVC_VERSION GREATER 1599)
		SET(ver_string "vs10")
	ELSEIF(MSVC_VERSION GREATER 1499)
		SET(ver_string "vs9")
	ELSEIF(CMAKE_COMPILER_2005)
		SET(ver_string "vs7")
	ELSE(MSVC_VERSION EQUAL 1400)
		SET(ver_string "vs6")
	ENDIF(MSVC_VERSION EQUAL 1400)
	SET(${var} "${ver_string}" PARENT_SCOPE)
ENDFUNCTION(GET_NMAKE_VERSION_STRING)

# CMAKE_SIZEOF_VOID_P doesn't work here because there
# was no compiler detection until now
IF (WIN32)
	SET(CMAKE_CXX_COMPILER cl)
	EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER}
			OUTPUT_VARIABLE _DEV_NULL
			ERROR_VARIABLE _COMPILER_OUTPUT)
	STRING(REGEX REPLACE " Version .*" "" CTEST_COMPILER ${_COMPILER_OUTPUT})
	IF (_COMPILER_OUTPUT MATCHES " for x64")
		SET(_BUILD_64_BIT TRUE)
	ELSE ()
		SET(_BUILD_64_BIT FALSE)
	ENDIF ()
...

A case for IA64 can be easily added at this point. Those CTest scripts are
only used with NMake at the moment so there is no case for Visual Studio
generators. But that can also easily be added with "IF (CMAKE_GENERATOR
MATCHES "AMD64$")" or something like that.

HTH

Eike


More information about the CMake mailing list