diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt index 9f890a015621a..b516a5a1d0131 100644 --- a/flang-rt/CMakeLists.txt +++ b/flang-rt/CMakeLists.txt @@ -245,6 +245,10 @@ check_cxx_compiler_flag("-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG) # Check whether -fno-lto is supported. check_cxx_compiler_flag(-fno-lto FLANG_RT_HAS_FNO_LTO_FLAG) +# Different platform may have different name for the POSIX thread library. +# For example, libpthread.a on AIX. Search for it as it is needed when +# building the shared flang_rt.runtime.so. +find_package(Threads) # function checks find_package(Backtrace) diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake index a43f1c332187a..c9a180e16163a 100644 --- a/flang-rt/cmake/modules/AddFlangRT.cmake +++ b/flang-rt/cmake/modules/AddFlangRT.cmake @@ -142,6 +142,9 @@ function (add_flangrt_library name) endif () if (build_shared) add_library("${name_shared}" SHARED ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS}) + if (Threads_FOUND) + target_link_libraries(${name_shared} PUBLIC Threads::Threads) + endif () endif () if (libtargets)