8

In CMake, what are the different possible values of CMAKE_SYSTEM_PROCESSOR? At least, the values for common processor families by AMD, Intel, Apple, Qualcomm and such?

I couldn't find this information in the CMake documentation.

starball
  • 20,030
  • 7
  • 43
  • 238
einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

9

According to the documentation, "when not cross-compiling, this variable has the same value as the CMAKE_HOST_SYSTEM_PROCESSOR variable". In the former scenario, the variable is set by the toolchain file, which I assume is what you're interested in doing.

In the latter case, the documentation says that CMAKE_HOST_SYSTEM_PROCESSOR is determined by inspecting the environment in the following way:

  • On Windows, the value of the PROCESSOR_ARCHITECTURE environment variable is used.
  • On macOS, the value of uname -m is used by default. However, since this might vary based on whether you're using x86 or ARM CMake, version 3.19.2+ will use the value of CMAKE_APPLE_SILICON_PROCESSOR (either CMake or environment variable) instead, if it is set. It also normalizes Power Macintosh to powerpc.
    • As far as I am aware, the possible values here are x86_64, arm64, and powerpc.
  • On OpenBSD, it uses the arch -s command.
    • Not sure what the full list is here. Unfortunately, the man page doesn't have anything to say about this.
  • On Linux and related systems (Cygwin, MSYS, Android, GNU), it uses uname -m
  • Otherwise, it looks for the uname command and tries uname -p first. If it returns a non-zero exit status, it resorts to uname -m
    • No telling what this could be.

But what really matters is how CMake will use the value of CMAKE_SYSTEM_PROCESSOR. Here are the functions I'm aware of:

  • The default value of CPACK_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}.
  • The language modules Modules/CMake<LANG>Information.cmake all optionally include platform modules suffixed with -${CMAKE_SYSTEM_PROCESSOR}.cmake
    • In most cases, no such modules exist. On Android, very many platform modules exist with processor-specific variants.
  • The FindJNI module uses it to guide its search
  • It is passed to ARMClang via --mcpu (compile) and --cpu (link)
Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
  • `Source: this SuperUser answer.` it's really clear in the source: https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CMakeDetermineSystem.cmake#L35 -> `$ENV{PROCESSOR_ARCHITECTURE}` on windows. – KamilCuk Dec 27 '21 at 18:11
  • 1
    @KamilCuk - that is the source only for the possible values of `PROCESSOR_ARCHITECTURE` – Alex Reinking Dec 27 '21 at 18:13
  • 1
    But - how can it make sense for this value to be OS-dependent? It's supposed to only depend on the actual processor architecture. – einpoklum Dec 27 '21 at 18:27
  • @einpoklum - That is a question for the CMake developers. I don't understand why the values aren't normalized either. – Alex Reinking Dec 27 '21 at 18:29
  • @AlexReinking: Ok, fair enough, but how can we use these non-normalized values? Check all the variations for each processor we care about? (I guess that's a rhetorical question.) – einpoklum Dec 27 '21 at 18:38
  • @einpoklum - I guess that depends on what you're trying to do with that information. If you're interested in determining available instruction sets, for example, you might find `CheckSourceCompiles` to be less brittle. – Alex Reinking Dec 27 '21 at 18:49