File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,12 @@ check_cxx_compiler_flag("-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
244
244
# Check whether -fno-lto is supported.
245
245
check_cxx_compiler_flag(-fno-lto FLANG_RT_HAS_FNO_LTO_FLAG)
246
246
247
+ # Check whether -Wl,--as-needed is supported.
248
+ check_linker_flag(C "LINKER:--as-needed" LINKER_SUPPORTS_AS_NEEDED)
249
+ if (LINKER_SUPPORTS_AS_NEEDED)
250
+ set (LINKER_AS_NEEDED_OPT "LINKER:--as-needed" )
251
+ endif ()
252
+
247
253
# Different platform may have different name for the POSIX thread library.
248
254
# For example, libpthread.a on AIX. Search for it as it is needed when
249
255
# building the shared flang_rt.runtime.so.
Original file line number Diff line number Diff line change @@ -145,6 +145,20 @@ function (add_flangrt_library name)
145
145
if (Threads_FOUND)
146
146
target_link_libraries (${name_shared} PUBLIC Threads::Threads)
147
147
endif ()
148
+
149
+ # Special dependencies handling for shared libraries only:
150
+ #
151
+ # flang-rt libraries must not depend on libc++/libstdc++,
152
+ # so set the linker language to C to avoid the unnecessary
153
+ # library dependence. Note that libc++/libstdc++ may still
154
+ # come through CMAKE_CXX_IMPLICIT_LINK_LIBRARIES.
155
+ set_target_properties (${name_shared} PROPERTIES LINKER_LANGUAGE C)
156
+ # Use --as-needed to avoid unnecessary dependencies.
157
+ if (LINKER_AS_NEEDED_OPT)
158
+ target_link_options (${name_shared} BEFORE PRIVATE
159
+ "${LINKER_AS_NEEDED_OPT} "
160
+ )
161
+ endif ()
148
162
endif ()
149
163
150
164
if (libtargets)
You can’t perform that action at this time.
0 commit comments