Skip to content

Instantly share code, notes, and snippets.

@webmaster128
Last active January 31, 2025 22:39
Show Gist options
  • Select an option

  • Save webmaster128/e08067641df1dd784eb195282fd0912f to your computer and use it in GitHub Desktop.

Select an option

Save webmaster128/e08067641df1dd784eb195282fd0912f to your computer and use it in GitHub Desktop.
//
// https://gist.github.com/webmaster128/e08067641df1dd784eb195282fd0912f
//
// The resulting values must not be defined as macros, which
// happens e.g. for 'i386', which is a macro in clang.
// For safety reasons, we undefine everything we output later
//
// For CMake literal compatibility, this file must have no double quotes
//
#ifdef _WIN32
#ifdef _WIN64
#undef x86_64
x86_64
#else
#undef x86
x86
#endif
#elif defined __APPLE__
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
#if TARGET_CPU_X86
#undef x86
x86
#elif TARGET_CPU_X86_64
#undef x86_64
x86_64
#elif TARGET_CPU_ARM
#undef armv7
armv7
#elif TARGET_CPU_ARM64
#undef armv8
armv8
#else
#error Unsupported platform
#endif
#elif TARGET_OS_MAC
#undef x86_64
x86_64
#else
#error Unsupported platform
#endif
#elif defined __linux
#ifdef __ANDROID__
#ifdef __i386__
#undef x86
x86
#elif defined __arm__
#undef armv7
armv7
#elif defined __aarch64__
#undef armv8
armv8
#else
#error Unsupported platform
#endif
#else
#ifdef __LP64__
#undef x86_64
x86_64
#else
#undef x86
x86
#endif
#endif
#else
#error Unsupported platform
#endif
@MarkCallow
Copy link
Copy Markdown

Thank you for this. I still need the -I to find TargetConditionals.h and I had to change the ANDROID_ABI part as follows to avoid "STREQUAL being taken as an argument to if rather than an operator.

    if(${ANDROID_ABI} AND ${ANDROID_ABI} STREQUAL "armeabi-v7a")
        set(${out} armv7 PARENT_SCOPE)
    elseif(${ANDROID_ABI} AND ${ANDROID_ABI} STREQUAL "arm64-v8a")
        set(${out} armv8 PARENT_SCOPE)
    elseif(${ANDROID_ABI} AND ${ANDROID_ABI} STREQUAL "x86")
        set(${out} x86_32 PARENT_SCOPE)
    elseif(${ANDROID_ABI} AND ${ANDROID_ABI} STREQUAL "x86_64")
        set(${out} x86_64 PARENT_SCOPE)

With those changes, it works!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment