136 lines · plain
1#===-- lib/quadmath/CMakeLists.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# FortranFloat128 implements IEEE-754 128-bit float math functions.10# It is a thin wapper and it currently relies on third-party11# libraries available for the target.12# It is distributed as a static library only.13# Fortran programs/libraries that end up linking any of the provided14# will have a dependency on the third-party library that is being15# used for building this libflang_rt.quadmath library.16 17include(CheckLibraryExists)18include(CheckIncludeFile)19 20set(sources21 acos.cpp22 acosh.cpp23 asin.cpp24 asinh.cpp25 atan.cpp26 atan2.cpp27 atanh.cpp28 ceil.cpp29 complex-math.c30 cos.cpp31 cosh.cpp32 erf.cpp33 erfc.cpp34 exp.cpp35 exponent.cpp36 floor.cpp37 fma.cpp38 fraction.cpp39 hypot.cpp40 j0.cpp41 j1.cpp42 jn.cpp43 lgamma.cpp44 llround.cpp45 log.cpp46 log10.cpp47 lround.cpp48 mod-real.cpp49 modulo-real.cpp50 nearest.cpp51 nearbyint.cpp52 norm2.cpp53 pow.cpp54 random.cpp55 remainder.cpp56 round.cpp57 rrspacing.cpp58 scale.cpp59 set-exponent.cpp60 sin.cpp61 sinh.cpp62 spacing.cpp63 sqrt.cpp64 tan.cpp65 tanh.cpp66 tgamma.cpp67 trunc.cpp68 y0.cpp69 y1.cpp70 yn.cpp71 )72 73include_directories(AFTER "${CMAKE_CURRENT_SOURCE_DIR}/..")74add_library(FortranFloat128MathILib INTERFACE)75target_include_directories(FortranFloat128MathILib INTERFACE76 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>77 )78 79if (FLANG_RUNTIME_F128_MATH_LIB)80 if (${FLANG_RUNTIME_F128_MATH_LIB} STREQUAL "libquadmath")81 if(FLANG_INCLUDE_QUADMATH_H)82 add_compile_definitions(HAS_QUADMATHLIB)83 else()84 message(FATAL_ERROR85 "FLANG_RUNTIME_F128_MATH_LIB setting requires quadmath.h "86 "to be available: ${FLANG_RUNTIME_F128_MATH_LIB}"87 )88 endif()89 else()90 message(FATAL_ERROR91 "Unsupported third-party library for Fortran F128 math runtime: "92 "${FLANG_RUNTIME_F128_MATH_LIB}"93 )94 endif()95 96 if (WIN32)97 # Do not create a flang_rt.quadmath library under Windows, the Flang98 # driver never links it. Instead, add the sources to flang_rt.runtime.99 target_sources(FortranFloat128MathILib INTERFACE ${sources})100 target_compile_definitions(FortranFloat128MathILib INTERFACE HAS_QUADMATHLIB)101 else ()102 add_flangrt_library(flang_rt.quadmath STATIC INSTALL_WITH_TOOLCHAIN103 ${sources})104 target_include_directories(flang_rt.quadmath PRIVATE105 "${FLANG_RT_SOURCE_DIR}/lib/flang_rt"106 )107 endif ()108elseif (HAVE_LDBL_MANT_DIG_113)109 # We can use 'long double' versions from libc.110 check_library_exists(m sinl "" FOUND_LIBM)111 if (FOUND_LIBM)112 target_compile_definitions(FortranFloat128MathILib INTERFACE113 HAS_LIBM114 )115 target_include_directories(FortranFloat128MathILib INTERFACE116 "${FLANG_RT_SOURCE_DIR}/lib/flang_rt"117 )118 target_sources(FortranFloat128MathILib INTERFACE ${sources})119 else()120 message(FATAL_ERROR "Flang-RT cannot build without libm")121 endif()122else()123 # We can use '__float128' version from libc, if it has them.124 check_library_exists(m sinf128 "" FOUND_LIBMF128)125 if (FOUND_LIBMF128)126 target_compile_definitions(FortranFloat128MathILib INTERFACE127 HAS_LIBMF128128 )129 target_include_directories(FortranFloat128MathILib INTERFACE130 "${FLANG_RT_SOURCE_DIR}/lib/flang_rt"131 )132 # Enable this, when math-entries.h and complex-math.h is ready.133 # target_sources(FortranFloat128MathILib INTERFACE ${sources})134 endif()135endif()136