|
| 1 | +# |
| 2 | +# This file is part of AtomVM. |
| 3 | +# |
| 4 | +# Copyright 2026 Peter M. <petermm@gmail.com> |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later |
| 13 | +# |
| 14 | + |
| 15 | +function(avm_get_system_architecture_string out_var) |
| 16 | + set(options) |
| 17 | + set(one_value_args PLATFORM_VENDOR PLATFORM_OS) |
| 18 | + cmake_parse_arguments(PARSE_ARGV 1 AVM "${options}" "${one_value_args}" "") |
| 19 | + |
| 20 | + execute_process( |
| 21 | + COMMAND ${CMAKE_C_COMPILER} -dumpmachine |
| 22 | + OUTPUT_VARIABLE avm_raw_system_architecture |
| 23 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 24 | + ERROR_QUIET |
| 25 | + ) |
| 26 | + |
| 27 | + if (avm_raw_system_architecture STREQUAL "") |
| 28 | + unset(${out_var} PARENT_SCOPE) |
| 29 | + return() |
| 30 | + endif() |
| 31 | + |
| 32 | + string(REPLACE "-" ";" avm_system_architecture_parts "${avm_raw_system_architecture}") |
| 33 | + list(LENGTH avm_system_architecture_parts avm_system_architecture_length) |
| 34 | + |
| 35 | + if (avm_system_architecture_length EQUAL 1) |
| 36 | + list(GET avm_system_architecture_parts 0 avm_architecture) |
| 37 | + if (DEFINED AVM_PLATFORM_VENDOR) |
| 38 | + set(avm_vendor "${AVM_PLATFORM_VENDOR}") |
| 39 | + else() |
| 40 | + set(avm_vendor "unknown") |
| 41 | + endif() |
| 42 | + set(avm_os "unknown") |
| 43 | + elseif (avm_system_architecture_length EQUAL 2) |
| 44 | + list(GET avm_system_architecture_parts 0 avm_architecture) |
| 45 | + if (DEFINED AVM_PLATFORM_VENDOR) |
| 46 | + set(avm_vendor "${AVM_PLATFORM_VENDOR}") |
| 47 | + else() |
| 48 | + set(avm_vendor "unknown") |
| 49 | + endif() |
| 50 | + list(GET avm_system_architecture_parts 1 avm_os) |
| 51 | + else() |
| 52 | + list(GET avm_system_architecture_parts 0 avm_architecture) |
| 53 | + list(GET avm_system_architecture_parts 1 avm_vendor) |
| 54 | + if (DEFINED AVM_PLATFORM_VENDOR AND (avm_vendor STREQUAL "none" OR avm_vendor STREQUAL "unknown")) |
| 55 | + set(avm_vendor "${AVM_PLATFORM_VENDOR}") |
| 56 | + endif() |
| 57 | + |
| 58 | + list(REMOVE_AT avm_system_architecture_parts 0 1) |
| 59 | + string(REPLACE ";" "_" avm_os "${avm_system_architecture_parts}") |
| 60 | + endif() |
| 61 | + |
| 62 | + if (DEFINED AVM_PLATFORM_OS) |
| 63 | + set(avm_os "${AVM_PLATFORM_OS}") |
| 64 | + endif() |
| 65 | + |
| 66 | + string(REPLACE "-" "_" avm_architecture "${avm_architecture}") |
| 67 | + string(REPLACE "-" "_" avm_vendor "${avm_vendor}") |
| 68 | + string(REPLACE "-" "_" avm_os "${avm_os}") |
| 69 | + |
| 70 | + set(${out_var} "${avm_architecture}-${avm_vendor}-${avm_os}" PARENT_SCOPE) |
| 71 | +endfunction() |
0 commit comments