@@ -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} )
0 commit comments