Skip to content

Commit ad1e650

Browse files
committed
Backport from flang_runtime_shared
1 parent 746a9a2 commit ad1e650

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function (add_flangrt_library name)
103103
)
104104
endif ()
105105

106-
# Flang-rt's public headers
106+
# Flang-RT's public headers
107107
target_include_directories(${name} PRIVATE "${FLANG_RT_SOURCE_DIR}/include")
108108

109109
# For ISO_Fortran_binding.h to be found by the runtime itself (Accessed as #include "flang/ISO_Fortran_binding.h")
@@ -121,12 +121,24 @@ function (add_flangrt_library name)
121121
endif ()
122122

123123
# Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI
124-
# should only depend on msv(u)crt. LLVM still emits libgcc/compiler-rt
124+
# should only depend on msvcrt/ucrt. LLVM still emits libgcc/compiler-rt
125125
# functions in some cases like 128-bit integer math (__udivti3, __modti3,
126126
# __fixsfti, __floattidf, ...) that msvc does not support. We are injecting a
127127
# dependency to Compiler-RT's builtin library where these are implemented.
128-
if (MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") AND FLANG_RT_BUILTINS_LIBRARY)
129-
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:-Xclang>$<$<COMPILE_LANGUAGE:Fortran>:-Xflang>" "--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}")
128+
if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
129+
if (FLANG_RT_BUILTINS_LIBRARY)
130+
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:-Xclang>" "--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}")
131+
endif ()
132+
endif ()
133+
if (MSVC AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
134+
if (FLANG_RT_BUILTINS_LIBRARY)
135+
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:-Xflang>" "--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}")
136+
else ()
137+
message(WARNING "Did not find libclang_rt.builtins.lib.
138+
LLVM may emit builtins that are not implemented in msvcrt/ucrt and
139+
instead falls back to builtins from Compiler-RT. Linking with ${name}
140+
may result in a linker error.")
141+
endif ()
130142
endif ()
131143

132144
# Non-GTest unittests depend on LLVMSupport
@@ -158,7 +170,7 @@ function (add_flangrt_library name)
158170
)
159171
endif ()
160172

161-
# flang-rt should build all the flang-rt targets that are built in an
173+
# flang-rt should build all the Flang-RT targets that are built in an
162174
# 'all' build.
163175
if (NOT ARG_EXCLUDE_FROM_ALL)
164176
add_dependencies(flang-rt ${name})

flang-rt/lib/FortranFloat128Math/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ if (FLANG_RUNTIME_F128_MATH_LIB)
9696

9797
if (WIN32)
9898
# Do not create a FortranFloat128Math library under Windows, the Flang
99-
# driver never links it. Instead, add the sources to the flang_rt itself.
99+
# driver never links it. Instead, add the sources to flang_rt itself.
100100
target_sources(FortranFloat128MathILib INTERFACE ${sources})
101101
target_compile_definitions(FortranFloat128MathILib INTERFACE HAS_QUADMATHLIB)
102102
else ()
103103
add_flangrt_library(FortranFloat128Math STATIC INSTALL_WITH_TOOLCHAIN
104104
${sources})
105-
endif ()
106-
target_include_directories(FortranFloat128Math PRIVATE
107-
"${FLANG_RT_SOURCE_DIR}/lib/flang_rt"
108-
)
105+
target_include_directories(FortranFloat128Math PRIVATE
106+
"${FLANG_RT_SOURCE_DIR}/lib/flang_rt"
107+
)
108+
endif ()
109109
elseif (HAVE_LDBL_MANT_DIG_113)
110110
# We can use 'long double' versions from libc.
111111
check_library_exists(m sinl "" FOUND_LIBM)

flang-rt/lib/Testing/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ file(GLOB_RECURSE public_headers
1212
)
1313

1414
add_flangrt_library(NonGTestTesting EXCLUDE_FROM_ALL LINK_TO_LLVM
15-
${FLANG_SOURCE_DIR}/lib/Testing/testing.cpp
16-
${FLANG_SOURCE_DIR}/lib/Testing/fp-testing.cpp
17-
ADDITIONAL_HEADERS
18-
${public_headers}
19-
)
15+
${FLANG_SOURCE_DIR}/lib/Testing/testing.cpp
16+
${FLANG_SOURCE_DIR}/lib/Testing/fp-testing.cpp
17+
18+
ADDITIONAL_HEADERS
19+
${public_headers}
20+
)

flang-rt/unittests/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# output. Therefore it also needs to include files from LLVM. Unfortunately,
1111
# LLVM/GTest doesn't add the include search path itself. Limiting the scope
1212
# using target_include_directories does not work because with
13-
# LLVM_INSTALL_GTEST=ON, llvm_gtest is an IMPORT library.
13+
# LLVM_INSTALL_GTEST=ON, as llvm_gtest is an IMPORT library.
1414
include_directories("${LLVM_INCLUDE_DIR}" "${LLVM_MAIN_INCLUDE_DIR}")
1515

1616
# Add GTest if not already present.
@@ -94,8 +94,10 @@ function(add_flangrt_nongtest_unittest test_name)
9494
add_executable(${test_name}${suffix} ${ARG_UNPARSED_ARGUMENTS})
9595
set_target_properties(${test_name}${suffix} PROPERTIES FOLDER "Flang-RT/Tests/Unit")
9696

97-
target_include_directories(${test_name}${suffix} PRIVATE "${FLANG_RT_SOURCE_DIR}/include")
98-
target_include_directories(${test_name}${suffix} PRIVATE "${FLANG_SOURCE_DIR}/include")
97+
target_include_directories(${test_name}${suffix} PRIVATE
98+
"${FLANG_RT_SOURCE_DIR}/include"
99+
"${FLANG_SOURCE_DIR}/include"
100+
)
99101
target_link_libraries(${test_name}${suffix} PRIVATE NonGTestTesting ${ARG_LINK_LIBS})
100102

101103
if(NOT ARG_SLOW_TEST)

0 commit comments

Comments
 (0)