Skip to content

Commit 8e21a00

Browse files
committed
Addressed review comments.
1 parent 76c2d56 commit 8e21a00

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

flang-rt/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ check_cxx_compiler_flag("-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
246246
check_cxx_compiler_flag(-fno-lto FLANG_RT_HAS_FNO_LTO_FLAG)
247247

248248
# Check whether -Wl,--as-needed is supported.
249-
check_linker_flag(C "-Wl,--as-needed" LINKER_SUPPORTS_AS_NEEDED)
249+
check_linker_flag(C "LINKER:--as-needed" LINKER_SUPPORTS_AS_NEEDED)
250250
if (LINKER_SUPPORTS_AS_NEEDED)
251-
set(LINKER_AS_NEEDED_OPT "-Wl,--as-needed")
251+
set(LINKER_AS_NEEDED_OPT "LINKER:--as-needed")
252252
endif()
253253

254254
# Different platform may have different name for the POSIX thread library.
@@ -301,6 +301,7 @@ elseif (FLANG_RT_GCC_RESOURCE_DIR)
301301
endif ()
302302

303303

304+
304305
#####################
305306
# Build Preparation #
306307
#####################

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ function (add_flangrt_library name)
145145
if (Threads_FOUND)
146146
target_link_libraries(${name_shared} PUBLIC Threads::Threads)
147147
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()
148162
endif ()
149163

150164
if (libtargets)
@@ -186,17 +200,6 @@ function (add_flangrt_library name)
186200
else ()
187201
set_target_properties(${tgtname} PROPERTIES FOLDER "Flang-RT/Libraries")
188202
endif ()
189-
190-
# flang-rt libraries must not depend on libc++/libstdc++,
191-
# so set the linker language to C to avoid the unnecessary
192-
# library dependence. Note that libc++/libstdc++ may still
193-
# come through CMAKE_CXX_IMPLICIT_LINK_LIBRARIES.
194-
set_target_properties(${tgtname} PROPERTIES LINKER_LANGUAGE C)
195-
# Use --as-needed to avoid unnecessary dependencies.
196-
if (LINKER_AS_NEEDED_OPT)
197-
set_property(TARGET ${tgtname} APPEND_STRING PROPERTY
198-
LINK_FLAGS "${LINKER_AS_NEEDED_OPT}")
199-
endif()
200203
endforeach ()
201204

202205
# Define how to compile and link the library.

0 commit comments

Comments
 (0)