diff options
Diffstat (limited to 'neozip/cmake/detect-arch.cmake')
| -rw-r--r-- | neozip/cmake/detect-arch.cmake | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/neozip/cmake/detect-arch.cmake b/neozip/cmake/detect-arch.cmake new file mode 100644 index 0000000000..991fe18296 --- /dev/null +++ b/neozip/cmake/detect-arch.cmake @@ -0,0 +1,173 @@ +# detect-arch.cmake -- Detect compiler architecture and set ARCH and BASEARCH +# Copyright (C) 2019 Hans Kristian Rosbach +# Licensed under the Zlib license, see LICENSE.md for details +if(CMAKE_OSX_ARCHITECTURES) + # If multiple architectures are requested (universal build), pick only the first + list(GET CMAKE_OSX_ARCHITECTURES 0 ARCH) +elseif(MSVC) + set(ARCH ${MSVC_C_ARCHITECTURE_ID}) +elseif(EMSCRIPTEN) + set(ARCH "wasm32") +endif() + +if(NOT ARCH OR ARCH STREQUAL "") + # Compile detect-arch.c and read the architecture name from the binary + try_compile( + COMPILE_RESULT + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_LIST_DIR}/detect-arch.c + CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/detect-arch.bin + ) + if(COMPILE_RESULT) + # Find archfound tag, and extract the arch word into ARCH variable + file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/detect-arch.bin RAWOUTPUT REGEX "archfound [a-zA-Z0-9_]+") + string(REGEX REPLACE ".*archfound ([a-zA-Z0-9_]+).*" "\\1" ARCH "${RAWOUTPUT}") + + # Find archversion tag, and extract the archversion word into ARCHVERSION variable + file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/detect-arch.bin RAWOUTPUT REGEX "archversion [0-9]+") + string(REGEX REPLACE ".*archversion ([0-9]+).*" "\\1" ARCHVERSION "${RAWOUTPUT}") + endif() + + if(NOT ARCH) + set(ARCH unknown) + endif() + if(NOT ARCHVERSION) + set(ARCHVERSION 0) + endif() +endif() + +# Make sure we have ARCH set +if(NOT ARCH OR ARCH STREQUAL "unknown") + set(ARCH ${CMAKE_SYSTEM_PROCESSOR}) + message(STATUS "Arch not recognized, falling back to cmake arch: '${ARCH}'") +else() + message(STATUS "Arch detected: '${ARCH}'") +endif() + +# Convert ARCH to lowercase +string(TOLOWER "${ARCH}" ARCH) + +# Base arch detection +if("${ARCH}" MATCHES "(x86(_32|_64)?|amd64|x64|i[3-6]86)") + set(BASEARCH "x86") + set(BASEARCH_X86_FOUND TRUE) + if("${ARCH}" MATCHES "(x86_64|amd64|x64)") + set(ARCH_BITS 64) + else() + set(ARCH_BITS 32) + endif() +elseif("${ARCH}" MATCHES "(aarch64|arm64(ec)?|aarch32|arm(v[0-9])?|cortex)") + set(BASEARCH "arm") + set(BASEARCH_ARM_FOUND TRUE) + if("${ARCH}" MATCHES "(aarch64|arm64(ec)?)") + set(ARCH_BITS 64) + else() + set(ARCH_BITS 32) + endif() +elseif("${ARCH}" MATCHES "(ppc|powerpc)(64)?(le)?") + set(BASEARCH "ppc") + set(BASEARCH_PPC_FOUND TRUE) + if("${ARCH}" MATCHES "(ppc|powerpc)64(le)?") + set(ARCH_BITS 64) + else() + set(ARCH_BITS 32) + endif() +elseif("${ARCH}" MATCHES "alpha") + set(BASEARCH "alpha") + set(BASEARCH_ALPHA_FOUND TRUE) + set(ARCH_BITS 64) +elseif("${ARCH}" MATCHES "blackfin") + set(BASEARCH "blackfin") + set(BASEARCH_BLACKFIN_FOUND TRUE) + set(ARCH_BITS 32) +elseif("${ARCH}" MATCHES "ia64") + set(BASEARCH "ia64") + set(BASEARCH_IA64_FOUND TRUE) + set(ARCH_BITS 64) +elseif("${ARCH}" MATCHES "mips(isa)?(64)?") + set(BASEARCH "mips") + set(BASEARCH_MIPS_FOUND TRUE) + if("${ARCH}" MATCHES "mips(isa)?64") + set(ARCH_BITS 64) + else() + set(ARCH_BITS 32) + endif() +elseif("${ARCH}" MATCHES "m68k") + set(BASEARCH "m68k") + set(BASEARCH_M68K_FOUND TRUE) + set(ARCH_BITS 32) +elseif("${ARCH}" MATCHES "sh") + set(BASEARCH "sh") + set(BASEARCH_SH_FOUND TRUE) + set(ARCH_BITS 32) +elseif("${ARCH}" MATCHES "sparc(v)?[89]?(64)?") + set(BASEARCH "sparc") + set(BASEARCH_SPARC_FOUND TRUE) + if("${ARCH}" MATCHES "(sparc64|sparc(v)?9)") + set(ARCH_BITS 64) + else() + set(ARCH_BITS 32) + endif() +elseif("${ARCH}" MATCHES "s3[679]0x?") + set(BASEARCH "s360") + set(BASEARCH_S360_FOUND TRUE) + if("${ARCH}" MATCHES "s3[679]0x") + set(ARCH_BITS 64) + else() + set(ARCH_BITS 32) + endif() +elseif("${ARCH}" MATCHES "(parisc|hppa)(64)?") + set(BASEARCH "parisc") + set(BASEARCH_PARISC_FOUND TRUE) + if("${ARCH}" MATCHES "(parisc|hppa)64") + set(ARCH_BITS 64) + else() + set(ARCH_BITS 32) + endif() +elseif("${ARCH}" MATCHES "rs6000") + set(BASEARCH "rs6000") + set(BASEARCH_RS6000_FOUND TRUE) + set(ARCH_BITS 32) +elseif("${ARCH}" MATCHES "riscv(32|64)") + set(BASEARCH "riscv") + set(BASEARCH_RISCV_FOUND TRUE) + if("${ARCH}" MATCHES "riscv64") + set(ARCH_BITS 64) + else() + set(ARCH_BITS 32) + endif() +elseif("${ARCH}" MATCHES "(loong64|loongarch64)") + set(BASEARCH "loongarch") + set(BASEARCH_LOONGARCH_FOUND TRUE) + set(ARCH_BITS 64) +elseif("${ARCH}" MATCHES "wasm(32|64)") + set(BASEARCH "wasm32") + set(BASEARCH_WASM32_FOUND TRUE) + if("${ARCH}" MATCHES "wasm64") + set(ARCH_BITS 64) + else() + set(ARCH_BITS 32) + endif() +elseif("${ARCH}" MATCHES "e2k") + set(BASEARCH "e2k") + set(BASEARCH_E2K_FOUND TRUE) + set(ARCH_BITS 64) + + message(STATUS "Arch version ${BASEARCH}v${ARCHVERSION}.") +else() + set(BASEARCH "x86") + set(BASEARCH_X86_FOUND TRUE) + set(ARCH_BITS 32) + message(STATUS "Basearch '${ARCH}' not recognized, defaulting to 'x86'.") +endif() + +if (ARCH_BITS EQUAL 64) + set(ARCH_64BIT TRUE) + set(ARCH_32BIT FALSE) +else() + set(ARCH_64BIT FALSE) + set(ARCH_32BIT TRUE) +endif() + +message(STATUS "Basearch of '${ARCH}' (${ARCH_BITS}bit) has been detected as: '${BASEARCH}'") |
