@@ -44,9 +44,6 @@ function (add_flangrt_library name)
4444 " )
4545 endif ()
4646
47- # Also add header files to IDEs to list as part of the library
48- set_source_files_properties (${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON )
49-
5047 # Forward libtype to add_library
5148 set (extra_args "" )
5249 if (ARG_SHARED)
@@ -62,6 +59,9 @@ function (add_flangrt_library name)
6259 list (APPEND extra_args EXCLUDE_FROM_ALL )
6360 endif ()
6461
62+ # Also add header files to IDEs to list as part of the library.
63+ set_source_files_properties (${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON )
64+
6565 add_library (${name} ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS} )
6666
6767 if (ARG_INSTALL_WITH_TOOLCHAIN)
@@ -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
@@ -146,19 +158,15 @@ function (add_flangrt_library name)
146158 if (ARG_INSTALL_WITH_TOOLCHAIN)
147159 set_target_properties (${name}
148160 PROPERTIES
149- LIBRARY_OUTPUT_DIRECTORY "${FLANG_RT_BUILD_TOOLCHAIN_LIB_DIR} "
150- ARCHIVE_OUTPUT_DIRECTORY "${FLANG_RT_BUILD_TOOLCHAIN_LIB_DIR} "
151- RUNTIME_OUTPUT_DIRECTORY "${FLANG_RT_BUILD_TOOLCHAIN_LIB_DIR} "
161+ ARCHIVE_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR} "
152162 )
153163
154164 install (TARGETS ${name}
155- LIBRARY DESTINATION "${FLANG_RT_INSTALL_TOOLCHAIN_LIB_DIR} "
156- ARCHIVE DESTINATION "${FLANG_RT_INSTALL_TOOLCHAIN_LIB_DIR} "
157- RUNTIME DESTINATION "${FLANG_RT_INSTALL_TOOLCHAIN_LIB_DIR} "
165+ ARCHIVE DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH} "
158166 )
159167 endif ()
160168
161- # flang-rt should build all the flang-rt targets that are built in an
169+ # flang-rt should build all the Flang-RT targets that are built in an
162170 # 'all' build.
163171 if (NOT ARG_EXCLUDE_FROM_ALL)
164172 add_dependencies (flang-rt ${name} )
0 commit comments