1#===-- runtime/Float128Math/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-exception 6# 7#===------------------------------------------------------------------------===# 8 9# FortranFloat128 implements IEEE-754 128-bit float math functions. 10# It is a thin wapper and it currently relies on third-party 11# 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 provided 14# will have a dependency on the third-party library that is being 15# used for building this FortranFloat128Math library. 16 17include(CheckLibraryExists) 18 19set(sources 20 acos.cpp 21 acosh.cpp 22 asin.cpp 23 asinh.cpp 24 atan.cpp 25 atan2.cpp 26 atanh.cpp 27 ceil.cpp 28 complex-math.c 29 cos.cpp 30 cosh.cpp 31 erf.cpp 32 erfc.cpp 33 exp.cpp 34 exponent.cpp 35 floor.cpp 36 fma.cpp 37 fraction.cpp 38 hypot.cpp 39 j0.cpp 40 j1.cpp 41 jn.cpp 42 lgamma.cpp 43 llround.cpp 44 log.cpp 45 log10.cpp 46 lround.cpp 47 mod-real.cpp 48 modulo-real.cpp 49 nearest.cpp 50 nearbyint.cpp 51 norm2.cpp 52 pow.cpp 53 random.cpp 54 remainder.cpp 55 round.cpp 56 rrspacing.cpp 57 scale.cpp 58 set-exponent.cpp 59 sin.cpp 60 sinh.cpp 61 spacing.cpp 62 sqrt.cpp 63 tan.cpp 64 tanh.cpp 65 tgamma.cpp 66 trunc.cpp 67 y0.cpp 68 y1.cpp 69 yn.cpp 70 ) 71 72include_directories(AFTER "${CMAKE_CURRENT_SOURCE_DIR}/..") 73add_library(FortranFloat128MathILib INTERFACE) 74target_include_directories(FortranFloat128MathILib INTERFACE 75 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> 76 ) 77 78if (FLANG_RUNTIME_F128_MATH_LIB) 79 if (${FLANG_RUNTIME_F128_MATH_LIB} STREQUAL "libquadmath") 80 check_include_file(quadmath.h FOUND_QUADMATH_HEADER) 81 if(FOUND_QUADMATH_HEADER) 82 add_compile_definitions(HAS_QUADMATHLIB) 83 else() 84 message(FATAL_ERROR 85 "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_ERROR 91 "Unsupported third-party library for Fortran F128 math runtime: " 92 "${FLANG_RUNTIME_F128_MATH_LIB}" 93 ) 94 endif() 95 96 add_flang_library(FortranFloat128Math STATIC INSTALL_WITH_TOOLCHAIN 97 ${sources}) 98 99 if (DEFINED MSVC) 100 set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded) 101 add_flang_library(FortranFloat128Math.static STATIC INSTALL_WITH_TOOLCHAIN 102 ${sources} 103 ) 104 set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug) 105 add_flang_library(FortranFloat128Math.static_dbg STATIC INSTALL_WITH_TOOLCHAIN 106 ${sources} 107 ) 108 add_dependencies(FortranFloat128Math FortranFloat128Math.static 109 FortranFloat128Math.static_dbg 110 ) 111 endif() 112elseif (HAVE_LDBL_MANT_DIG_113) 113 # We can use 'long double' versions from libc. 114 check_library_exists(m sinl "" FOUND_LIBM) 115 if (FOUND_LIBM) 116 target_compile_definitions(FortranFloat128MathILib INTERFACE 117 HAS_LIBM 118 ) 119 target_sources(FortranFloat128MathILib INTERFACE ${sources}) 120 else() 121 message(FATAL_ERROR "FortranRuntime cannot build without libm") 122 endif() 123else() 124 # We can use '__float128' version from libc, if it has them. 125 check_library_exists(m sinf128 "" FOUND_LIBMF128) 126 if (FOUND_LIBMF128) 127 target_compile_definitions(FortranFloat128MathILib INTERFACE 128 HAS_LIBMF128 129 ) 130 # Enable this, when math-entries.h and complex-math.h is ready. 131 # target_sources(FortranFloat128MathILib INTERFACE ${sources}) 132 endif() 133endif() 134