brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · c01afa4 Raw
87 lines · plain
1#===-- cmake/modules/FlangCommon.txt ----------------------------===#2#3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4# See https://llvm.org/LICENSE.txt for license information.5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6#7#===------------------------------------------------------------------------===#8#9# CMake definitions shared between Flang and Flang-RT10#11#===------------------------------------------------------------------------===#12 13include(CheckCSourceCompiles)14include(CheckIncludeFile)15 16# The out of tree builds of the compiler and the Fortran runtime17# must use the same setting of FLANG_RUNTIME_F128_MATH_LIB18# to be composable. Failure to synchronize this setting may result19# in linking errors or fatal failures in F128 runtime functions.20set(FLANG_RUNTIME_F128_MATH_LIB "" CACHE STRING21  "Specifies the target library used for implementing IEEE-754 128-bit float \22  math in F18 runtime, e.g. it might be libquadmath for targets where \23  REAL(16) is mapped to __float128, or libm for targets where REAL(16) \24  is mapped to long double, etc."25  )26if (FLANG_RUNTIME_F128_MATH_LIB)27  add_compile_definitions(FLANG_RUNTIME_F128_MATH_LIB="${FLANG_RUNTIME_F128_MATH_LIB}")28endif()29 30# Check if 128-bit float computations can be done via long double31# Note that '-nostdinc++' might be implied when this code kicks in32# (see 'runtimes/CMakeLists.txt'), so we cannot use 'cfloat' C++ header33# file in the test below.34# Compile it as C.35check_c_source_compiles(36  "#include <float.h>37   #if LDBL_MANT_DIG != 11338   #error LDBL_MANT_DIG != 11339   #endif40   int main() { return 0; }41  "42  HAVE_LDBL_MANT_DIG_113)43 44# Discover the GCC installation, when the build compiler is Clang,45# and try to find quadmath.h there. Set FLANG_INCLUDE_QUADMATH_H46# to the path to quadmath.h, if found.47if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")48  if (NOT DEFINED FLANG_GCC_RESOURCE_DIR)49    set(FLANG_GCC_RESOURCE_DIR "FLANG_GCC_RESOURCE_DIR-NOTFOUND")50    # Prepare CMAKE_CXX_FLAGS so that they can be passed to execute_process51    # as separate flags.52    separate_arguments(flags UNIX_COMMAND "${CMAKE_CXX_FLAGS}")53    execute_process(54      COMMAND "${CMAKE_CXX_COMPILER}" ${flags} -v "-###"55      ERROR_FILE "${CMAKE_CURRENT_BINARY_DIR}/clang_gcc_root_result"56    )57    file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/clang_gcc_root_result" _errorresult)58    foreach (_line IN LISTS _errorresult)59      string(REGEX MATCH60        "^Selected GCC installation: (.+)$"61        _match62        "${_line}")63      if (CMAKE_MATCH_1)64        set(FLANG_GCC_RESOURCE_DIR "${CMAKE_MATCH_1}")65        message(STATUS "Found GCC installation selected by Clang: ${FLANG_GCC_RESOURCE_DIR}")66        break()67      endif ()68    endforeach ()69    set(FLANG_GCC_RESOURCE_DIR "${FLANG_GCC_RESOURCE_DIR}" CACHE INTERNAL "Path to GCC's resource dir selected by Clang" FORCE)70  endif ()71endif ()72 73check_include_file("quadmath.h" FOUND_QUADMATH_H)74if (FOUND_QUADMATH_H)75  message(STATUS "quadmath.h found without additional include paths")76  set(FLANG_INCLUDE_QUADMATH_H "<quadmath.h>")77elseif (FLANG_GCC_RESOURCE_DIR)78  cmake_push_check_state()79    list(APPEND CMAKE_REQUIRED_INCLUDES "${FLANG_GCC_RESOURCE_DIR}/include")80    check_include_file("quadmath.h" FOUND_GCC_QUADMATH_H)81  cmake_pop_check_state()82  if (FOUND_GCC_QUADMATH_H)83    message(STATUS "quadmath.h found in Clang's selected GCC installation")84    set(FLANG_INCLUDE_QUADMATH_H "\"${FLANG_GCC_RESOURCE_DIR}/include/quadmath.h\"")85  endif ()86endif ()87