| 1 |
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
# SPDX-License-Identifier: Apache-2.0. |
| 3 |
|
| 4 |
# This function detects the local host's c runtime and writes a tag into the supplied output variable |
| 5 |
# Output is "cruntime" on non-Linux platforms. Output is "glibc" or "musl" on Linux platforms. |
| 6 |
# |
| 7 |
# Intended usage is for managed language CRTs to use this function to build native artifact paths, facilitating |
| 8 |
# support for alternative C runtimes like Musl. |
| 9 |
# |
| 10 |
function(aws_determine_local_c_runtime target) |
| 11 |
if (CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 12 |
execute_process(COMMAND "ldd" "--version" OUTPUT_VARIABLE AWS_LDD_OUTPUT ERROR_VARIABLE AWS_LDD_OUTPUT) |
| 13 |
string(TOLOWER "${AWS_LDD_OUTPUT}" AWS_LDD_OUTPUT_LOWER) |
| 14 |
message(STATUS "ldd output lower: ${AWS_LDD_OUTPUT_LOWER}") |
| 15 |
string(FIND "${AWS_LDD_OUTPUT_LOWER}" "musl" AWS_MUSL_INDEX) |
| 16 |
string(FIND "${AWS_LDD_OUTPUT_LOWER}" "glibc" AWS_GLIBC_INDEX) |
| 17 |
string(FIND "${AWS_LDD_OUTPUT_LOWER}" "gnu" AWS_GNU_INDEX) |
| 18 |
if (NOT(${AWS_MUSL_INDEX} EQUAL -1)) |
| 19 |
message(STATUS "MUSL libc detected") |
| 20 |
set(${target} "musl" PARENT_SCOPE) |
| 21 |
else() |
| 22 |
if ((NOT(${AWS_GLIBC_INDEX} EQUAL -1)) OR (NOT(${AWS_GNU_INDEX} EQUAL -1))) |
| 23 |
message(STATUS "Gnu libc detected") |
| 24 |
else() |
| 25 |
message(STATUS "Could not determine C runtime, defaulting to gnu libc") |
| 26 |
endif() |
| 27 |
set(${target} "glibc" PARENT_SCOPE) |
| 28 |
endif() |
| 29 |
else() |
| 30 |
set(${target} "cruntime" PARENT_SCOPE) |
| 31 |
endif() |
| 32 |
endfunction() |