|
| 1 | +# ------------------------------------------------------------------------------ |
| 2 | +# Compiler features definition and flags |
| 3 | +# ------------------------------------------------------------------------------ |
| 4 | + |
| 5 | +# Initialize ALL_COMPILER_FEATURES as empty list. |
| 6 | +set(ALL_COMPILER_FEATURES "float128") |
| 7 | + |
| 8 | +# Making sure ALL_COMPILER_FEATURES is sorted. |
| 9 | +list(SORT ALL_COMPILER_FEATURES) |
| 10 | + |
| 11 | +# Function to check whether the compiler supports the provided set of features. |
| 12 | +# Usage: |
| 13 | +# compiler_supports( |
| 14 | +# <output variable> |
| 15 | +# <list of cpu features> |
| 16 | +# ) |
| 17 | +function(compiler_supports output_var features) |
| 18 | + _intersection(var "${LIBC_CPU_FEATURES}" "${features}") |
| 19 | + if("${var}" STREQUAL "${features}") |
| 20 | + set(${output_var} TRUE PARENT_SCOPE) |
| 21 | + else() |
| 22 | + unset(${output_var} PARENT_SCOPE) |
| 23 | + endif() |
| 24 | +endfunction() |
| 25 | + |
| 26 | +# ------------------------------------------------------------------------------ |
| 27 | +# Internal helpers and utilities. |
| 28 | +# ------------------------------------------------------------------------------ |
| 29 | + |
| 30 | +# Computes the intersection between two lists. |
| 31 | +function(_intersection output_var list1 list2) |
| 32 | + foreach(element IN LISTS list1) |
| 33 | + if("${list2}" MATCHES "(^|;)${element}(;|$)") |
| 34 | + list(APPEND tmp "${element}") |
| 35 | + endif() |
| 36 | + endforeach() |
| 37 | + set(${output_var} ${tmp} PARENT_SCOPE) |
| 38 | +endfunction() |
| 39 | + |
| 40 | +set(AVAILABLE_COMPILER_FEATURES "") |
| 41 | + |
| 42 | +# Try compile a C file to check if flag is supported. |
| 43 | +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
| 44 | +foreach(feature IN LISTS ALL_COMPILER_FEATURES) |
| 45 | + try_compile( |
| 46 | + has_feature |
| 47 | + ${CMAKE_CURRENT_BINARY_DIR}/compiler_features |
| 48 | + SOURCES ${LIBC_SOURCE_DIR}/cmake/modules/compiler_features/check_${feature}.cpp |
| 49 | + COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${LIBC_COMPILE_OPTIONS_NATIVE} |
| 50 | + ) |
| 51 | + if(has_feature) |
| 52 | + list(APPEND AVAILABLE_COMPILER_FEATURES ${feature}) |
| 53 | + if(${feature} STREQUAL "float128") |
| 54 | + set(LIBC_COMPILER_HAS_FLOAT128 TRUE) |
| 55 | + endif() |
| 56 | + endif() |
| 57 | +endforeach() |
| 58 | + |
| 59 | +message(STATUS "Compiler features available: ${AVAILABLE_COMPILER_FEATURES}") |
0 commit comments