| 1 |
#===-- runtime/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 |
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 10 |
cmake_minimum_required(VERSION 3.20.0) |
| 11 |
|
| 12 |
project(FlangRuntime C CXX) |
| 13 |
|
| 14 |
set(CMAKE_CXX_STANDARD 17) |
| 15 |
set(CMAKE_CXX_STANDARD_REQUIRED TRUE) |
| 16 |
set(CMAKE_CXX_EXTENSIONS OFF) |
| 17 |
|
| 18 |
set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..") |
| 19 |
|
| 20 |
set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake") |
| 21 |
set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake") |
| 22 |
set(CLANG_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../clang/cmake") |
| 23 |
|
| 24 |
# Add path for custom modules |
| 25 |
list(INSERT CMAKE_MODULE_PATH 0 |
| 26 |
"${FLANG_SOURCE_DIR}/cmake" |
| 27 |
"${FLANG_SOURCE_DIR}/cmake/modules" |
| 28 |
"${LLVM_COMMON_CMAKE_UTILS}" |
| 29 |
"${LLVM_COMMON_CMAKE_UTILS}/Modules" |
| 30 |
"${LLVM_CMAKE_UTILS}" |
| 31 |
"${LLVM_CMAKE_UTILS}/modules" |
| 32 |
"${CLANG_CMAKE_UTILS}/modules" |
| 33 |
) |
| 34 |
|
| 35 |
include(AddClang) |
| 36 |
include(AddLLVM) |
| 37 |
include(AddFlang) |
| 38 |
include(HandleLLVMOptions) |
| 39 |
|
| 40 |
include(TestBigEndian) |
| 41 |
test_big_endian(IS_BIGENDIAN) |
| 42 |
if (IS_BIGENDIAN) |
| 43 |
add_compile_definitions(FLANG_BIG_ENDIAN=1) |
| 44 |
else () |
| 45 |
add_compile_definitions(FLANG_LITTLE_ENDIAN=1) |
| 46 |
endif () |
| 47 |
include_directories(BEFORE |
| 48 |
${FLANG_SOURCE_DIR}/include) |
| 49 |
|
| 50 |
# The out of tree builds of the compiler and the Fortran runtime |
| 51 |
# must use the same setting of FLANG_RUNTIME_F128_MATH_LIB |
| 52 |
# to be composable. Failure to synchronize this setting may result |
| 53 |
# in linking errors or fatal failures in F128 runtime functions. |
| 54 |
set(FLANG_RUNTIME_F128_MATH_LIB "" CACHE STRING |
| 55 |
"Specifies the target library used for implementing IEEE-754 128-bit float \ |
| 56 |
math in F18 runtime, e.g. it might be libquadmath for targets where \ |
| 57 |
REAL(16) is mapped to __float128, or libm for targets where REAL(16) \ |
| 58 |
is mapped to long double, etc." |
| 59 |
) |
| 60 |
endif() |
| 61 |
|
| 62 |
include(CheckCXXSymbolExists) |
| 63 |
include(CheckCXXSourceCompiles) |
| 64 |
check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R) |
| 65 |
# Can't use symbol exists here as the function is overloaded in C++ |
| 66 |
check_cxx_source_compiles( |
| 67 |
"#include <string.h> |
| 68 |
int main() { |
| 69 |
char buf[4096]; |
| 70 |
return strerror_s(buf, 4096, 0); |
| 71 |
} |
| 72 |
" |
| 73 |
HAVE_DECL_STRERROR_S) |
| 74 |
|
| 75 |
# Check if 128-bit float computations can be done via long double. |
| 76 |
check_cxx_source_compiles( |
| 77 |
"#include <cfloat> |
| 78 |
#if LDBL_MANT_DIG != 113 |
| 79 |
#error LDBL_MANT_DIG != 113 |
| 80 |
#endif |
| 81 |
int main() { return 0; } |
| 82 |
" |
| 83 |
HAVE_LDBL_MANT_DIG_113) |
| 84 |
|
| 85 |
check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG) |
| 86 |
if (FLANG_RUNTIME_HAS_FNO_LTO_FLAG) |
| 87 |
set(NO_LTO_FLAGS "-fno-lto") |
| 88 |
else() |
| 89 |
set(NO_LTO_FLAGS "") |
| 90 |
endif() |
| 91 |
|
| 92 |
configure_file(config.h.cmake config.h) |
| 93 |
# include_directories is used here instead of target_include_directories |
| 94 |
# because add_flang_library creates multiple objects (STATIC/SHARED, OBJECT) |
| 95 |
# with different names |
| 96 |
include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR}) |
| 97 |
|
| 98 |
append(${NO_LTO_FLAGS} CMAKE_C_FLAGS) |
| 99 |
append(${NO_LTO_FLAGS} CMAKE_CXX_FLAGS) |
| 100 |
|
| 101 |
# Disable libstdc++/libc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build, |
| 102 |
# to avoid an unwanted dependency on libstdc++/libc++.so. |
| 103 |
add_definitions(-U_GLIBCXX_ASSERTIONS) |
| 104 |
add_definitions(-U_LIBCPP_ENABLE_ASSERTIONS) |
| 105 |
|
| 106 |
add_subdirectory(Float128Math) |
| 107 |
|
| 108 |
set(sources |
| 109 |
ISO_Fortran_binding.cpp |
| 110 |
allocatable.cpp |
| 111 |
array-constructor.cpp |
| 112 |
assign.cpp |
| 113 |
buffer.cpp |
| 114 |
character.cpp |
| 115 |
command.cpp |
| 116 |
complex-powi.cpp |
| 117 |
complex-reduction.c |
| 118 |
connection.cpp |
| 119 |
copy.cpp |
| 120 |
derived-api.cpp |
| 121 |
derived.cpp |
| 122 |
descriptor-io.cpp |
| 123 |
descriptor.cpp |
| 124 |
dot-product.cpp |
| 125 |
edit-input.cpp |
| 126 |
edit-output.cpp |
| 127 |
environment.cpp |
| 128 |
exceptions.cpp |
| 129 |
execute.cpp |
| 130 |
extensions.cpp |
| 131 |
external-unit.cpp |
| 132 |
extrema.cpp |
| 133 |
file.cpp |
| 134 |
findloc.cpp |
| 135 |
format.cpp |
| 136 |
inquiry.cpp |
| 137 |
internal-unit.cpp |
| 138 |
io-api.cpp |
| 139 |
io-api-minimal.cpp |
| 140 |
io-error.cpp |
| 141 |
io-stmt.cpp |
| 142 |
iostat.cpp |
| 143 |
main.cpp |
| 144 |
matmul-transpose.cpp |
| 145 |
matmul.cpp |
| 146 |
memory.cpp |
| 147 |
misc-intrinsic.cpp |
| 148 |
namelist.cpp |
| 149 |
non-tbp-dio.cpp |
| 150 |
numeric.cpp |
| 151 |
pointer.cpp |
| 152 |
product.cpp |
| 153 |
pseudo-unit.cpp |
| 154 |
ragged.cpp |
| 155 |
random.cpp |
| 156 |
reduce.cpp |
| 157 |
reduction.cpp |
| 158 |
stat.cpp |
| 159 |
stop.cpp |
| 160 |
sum.cpp |
| 161 |
support.cpp |
| 162 |
temporary-stack.cpp |
| 163 |
terminator.cpp |
| 164 |
time-intrinsic.cpp |
| 165 |
tools.cpp |
| 166 |
transformational.cpp |
| 167 |
type-code.cpp |
| 168 |
type-info.cpp |
| 169 |
unit-map.cpp |
| 170 |
unit.cpp |
| 171 |
utf.cpp |
| 172 |
${FORTRAN_MODULE_OBJECTS} |
| 173 |
) |
| 174 |
|
| 175 |
include(AddFlangOffloadRuntime) |
| 176 |
|
| 177 |
# List of files that are buildable for all devices. |
| 178 |
set(supported_files |
| 179 |
ISO_Fortran_binding.cpp |
| 180 |
allocatable.cpp |
| 181 |
array-constructor.cpp |
| 182 |
assign.cpp |
| 183 |
buffer.cpp |
| 184 |
character.cpp |
| 185 |
connection.cpp |
| 186 |
copy.cpp |
| 187 |
derived-api.cpp |
| 188 |
derived.cpp |
| 189 |
descriptor.cpp |
| 190 |
descriptor-io.cpp |
| 191 |
dot-product.cpp |
| 192 |
edit-input.cpp |
| 193 |
edit-output.cpp |
| 194 |
environment.cpp |
| 195 |
extrema.cpp |
| 196 |
external-unit.cpp |
| 197 |
file.cpp |
| 198 |
findloc.cpp |
| 199 |
format.cpp |
| 200 |
inquiry.cpp |
| 201 |
internal-unit.cpp |
| 202 |
io-api.cpp |
| 203 |
io-api-minimal.cpp |
| 204 |
io-error.cpp |
| 205 |
io-stmt.cpp |
| 206 |
iostat.cpp |
| 207 |
matmul-transpose.cpp |
| 208 |
matmul.cpp |
| 209 |
memory.cpp |
| 210 |
misc-intrinsic.cpp |
| 211 |
namelist.cpp |
| 212 |
non-tbp-dio.cpp |
| 213 |
numeric.cpp |
| 214 |
pointer.cpp |
| 215 |
product.cpp |
| 216 |
pseudo-unit.cpp |
| 217 |
ragged.cpp |
| 218 |
stat.cpp |
| 219 |
sum.cpp |
| 220 |
support.cpp |
| 221 |
terminator.cpp |
| 222 |
tools.cpp |
| 223 |
transformational.cpp |
| 224 |
type-code.cpp |
| 225 |
type-info.cpp |
| 226 |
unit.cpp |
| 227 |
utf.cpp |
| 228 |
) |
| 229 |
|
| 230 |
enable_cuda_compilation(FortranRuntime "${supported_files}") |
| 231 |
enable_omp_offload_compilation("${supported_files}") |
| 232 |
|
| 233 |
if (NOT TARGET FortranFloat128Math) |
| 234 |
# If FortranFloat128Math is not defined, then we are not building |
| 235 |
# standalone FortranFloat128Math library. Instead, include |
| 236 |
# the relevant sources into FortranRuntime itself. |
| 237 |
# The information is provided via FortranFloat128MathILib |
| 238 |
# interface library. |
| 239 |
get_target_property(f128_sources |
| 240 |
FortranFloat128MathILib INTERFACE_SOURCES |
| 241 |
) |
| 242 |
if (f128_sources) |
| 243 |
# The interface may define special macros for Float128Math files, |
| 244 |
# so we need to propagate them. |
| 245 |
get_target_property(f128_defs |
| 246 |
FortranFloat128MathILib INTERFACE_COMPILE_DEFINITIONS |
| 247 |
) |
| 248 |
set_property(SOURCE ${f128_sources} |
| 249 |
APPEND PROPERTY COMPILE_DEFINITIONS |
| 250 |
${f128_defs} |
| 251 |
) |
| 252 |
list(APPEND sources ${f128_sources}) |
| 253 |
endif() |
| 254 |
endif() |
| 255 |
|
| 256 |
if (NOT DEFINED MSVC) |
| 257 |
add_flang_library(FortranRuntime |
| 258 |
${sources} |
| 259 |
LINK_LIBS |
| 260 |
FortranDecimal |
| 261 |
|
| 262 |
INSTALL_WITH_TOOLCHAIN |
| 263 |
) |
| 264 |
else() |
| 265 |
add_flang_library(FortranRuntime |
| 266 |
${sources} |
| 267 |
LINK_LIBS |
| 268 |
FortranDecimal |
| 269 |
) |
| 270 |
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded) |
| 271 |
add_flang_library(FortranRuntime.static ${sources} |
| 272 |
LINK_LIBS |
| 273 |
FortranDecimal.static |
| 274 |
INSTALL_WITH_TOOLCHAIN) |
| 275 |
set_target_properties(FortranRuntime.static PROPERTIES FOLDER "Flang/Runtime Libraries") |
| 276 |
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) |
| 277 |
add_flang_library(FortranRuntime.dynamic ${sources} |
| 278 |
LINK_LIBS |
| 279 |
FortranDecimal.dynamic |
| 280 |
INSTALL_WITH_TOOLCHAIN) |
| 281 |
set_target_properties(FortranRuntime.dynamic PROPERTIES FOLDER "Flang/Runtime Libraries") |
| 282 |
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug) |
| 283 |
add_flang_library(FortranRuntime.static_dbg ${sources} |
| 284 |
LINK_LIBS |
| 285 |
FortranDecimal.static_dbg |
| 286 |
INSTALL_WITH_TOOLCHAIN) |
| 287 |
set_target_properties(FortranRuntime.static_dbg PROPERTIES FOLDER "Flang/Runtime Libraries") |
| 288 |
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL) |
| 289 |
add_flang_library(FortranRuntime.dynamic_dbg ${sources} |
| 290 |
LINK_LIBS |
| 291 |
FortranDecimal.dynamic_dbg |
| 292 |
INSTALL_WITH_TOOLCHAIN) |
| 293 |
set_target_properties(FortranRuntime.dynamic_dbg PROPERTIES FOLDER "Flang/Runtime Libraries") |
| 294 |
add_dependencies(FortranRuntime FortranRuntime.static FortranRuntime.dynamic |
| 295 |
FortranRuntime.static_dbg FortranRuntime.dynamic_dbg) |
| 296 |
endif() |
| 297 |
set_target_properties(FortranRuntime PROPERTIES FOLDER "Flang/Runtime Libraries") |
| 298 |
|
| 299 |
# If FortranRuntime is part of a Flang build (and not a separate build) then |
| 300 |
# add dependency to make sure that Fortran runtime library is being built after |
| 301 |
# we have the Flang compiler available. This also includes the MODULE files |
| 302 |
# that compile when the 'flang-new' target is built. |
| 303 |
# |
| 304 |
# TODO: This is a workaround and should be updated when runtime build procedure |
| 305 |
# is changed to a regular runtime build. See discussion in PR #95388. |
| 306 |
if (TARGET flang-new AND TARGET module_files) |
| 307 |
add_dependencies(FortranRuntime flang-new module_files) |
| 308 |
endif() |
| 309 |
|