[CMake] Get Visual Studio target Arch

Gregor Jasny gjasny at googlemail.com
Mon Sep 8 15:06:00 EDT 2014


On 06/09/14 16:02, Alexey Petruchik wrote:
> I want to use different library folders for x64/x86/arm architectures.
> Cmake has different generators for each arch: "Visual Studio 12
> 2013", "Visual Studio 12 2013 ARM", "Visual Studio 12 2013 Win64". Is there
> any cmake var to get visual studio target arch? CMAKE_SYSTEM_PROCESSOR is
> always AMD64 for me no matter what generator I'm using.

All the already available stuff in cmake is not sufficient. Especially
if you start to cross compile.

I use the pre-defined C/C++ preprocessor symbols for that:

include(CheckSymbolExists)

if(WIN32)
  check_symbol_exists("_M_AMD64" "" RTC_ARCH_X64)
  if(NOT RTC_ARCH_X64)
    check_symbol_exists("_M_IX86" "" RTC_ARCH_X86)
  endif(NOT RTC_ARCH_X64)
  # add check for arm here
  # see http://msdn.microsoft.com/en-us/library/b0084kay.aspx
else(WIN32)
  check_symbol_exists("__i386__" "" RTC_ARCH_X86)
  check_symbol_exists("__x86_64__" "" RTC_ARCH_X64)
  check_symbol_exists("__arm__" "" RTC_ARCH_ARM)
endif(WIN32)

Now you could write:

if(RTC_ARCH_X64)
  set(MY_LIB_DIR x64)
elseif(RTC_ARCH_X86)
  set(MY_LIB_DIR x86)
elseif(RTC_ARCH_ARM)
  set(MY_LIB_DIR x86)
else()
  message(FATAL_ERROR "Unknown architecture")
endif()

I hope this helps.

Thanks,
Gregor


More information about the CMake mailing list