Skip to content

Commit b05c9a0

Browse files
committed
[Flang-RT] Build libflang_rt.so
1 parent f670816 commit b05c9a0

File tree

7 files changed

+283
-128
lines changed

7 files changed

+283
-128
lines changed

Diff for: flang-rt/CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ endif ()
115115
extend_path(FLANG_RT_INSTALL_RESOURCE_LIB_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
116116
cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_DIR)
117117
cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_PATH)
118+
# FIXME: For the libflang_rt.so, the toolchain resource lib dir is not a good
119+
# destination because it is not a ld.so default search path.
120+
# The machine where the executable is eventually executed may not be the
121+
# machine where the Flang compiler and its resource dir is installed, so
122+
# setting RPath by the driver is not an solution. It should belong into
123+
# /usr/lib/<triple>/libflang_rt.so, like e.g. libgcc_s.so.
124+
# But the linker as invoked by the Flang driver also requires
125+
# libflang_rt.so to be found when linking and the resource lib dir is
126+
# the only reliable location.
118127
cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_LIB_DIR)
119128
cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
120129

@@ -129,6 +138,27 @@ cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
129138
option(FLANG_RT_INCLUDE_TESTS "Generate build targets for the flang-rt unit and regression-tests." "${LLVM_INCLUDE_TESTS}")
130139

131140

141+
option(FLANG_RT_ENABLE_STATIC "Build Flang-RT as a static library." ON)
142+
if (WIN32)
143+
# Windows DLL currently not implemented.
144+
set(FLANG_RT_ENABLE_SHARED OFF)
145+
else ()
146+
# TODO: Enable by default to increase test coverage, and which version of the
147+
# library should be the user's choice anyway.
148+
# Currently, the Flang driver adds `-L"libdir" -lflang_rt` as linker
149+
# argument, which leaves the choice which library to use to the linker.
150+
# Since most linkers prefer the shared library, this would constitute a
151+
# breaking change unless the driver is changed.
152+
option(FLANG_RT_ENABLE_SHARED "Build Flang-RT as a shared library." OFF)
153+
endif ()
154+
if (NOT FLANG_RT_ENABLE_STATIC AND NOT FLANG_RT_ENABLE_SHARED)
155+
message(FATAL_ERROR "
156+
Must build at least one type of library
157+
(FLANG_RT_ENABLE_STATIC=ON, FLANG_RT_ENABLE_SHARED=ON, or both)
158+
")
159+
endif ()
160+
161+
132162
set(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT "" CACHE STRING "Compile Flang-RT with GPU support (CUDA or OpenMP)")
133163
set_property(CACHE FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT PROPERTY STRINGS
134164
""

0 commit comments

Comments
 (0)