[libomptarget][NFC] Link plugins with threads support library due to std::call_once...
authorVyacheslav Zakharin <vyacheslav.p.zakharin@intel.com>
Wed, 27 Jan 2021 23:41:44 +0000 (15:41 -0800)
committerVyacheslav Zakharin <vyacheslav.p.zakharin@intel.com>
Thu, 28 Jan 2021 03:26:18 +0000 (19:26 -0800)
Differential Revision: https://reviews.llvm.org/D95572

openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
openmp/libomptarget/plugins/CMakeLists.txt
openmp/libomptarget/plugins/cuda/CMakeLists.txt
openmp/libomptarget/plugins/remote/server/CMakeLists.txt
openmp/libomptarget/plugins/remote/src/CMakeLists.txt

index 28165ac..317260c 100644 (file)
@@ -251,3 +251,28 @@ if (NOT LIBOMPTARGET_CUDA_TOOLKIT_ROOT_DIR_PRESET AND
     endif()
   endif()
 endif()
+
+if (OPENMP_STANDALONE_BUILD)
+  # This duplicates code from llvm/cmake/config-ix.cmake
+  if( WIN32 AND NOT CYGWIN )
+    # We consider Cygwin as another Unix
+    set(PURE_WINDOWS 1)
+  endif()
+
+  # library checks
+  if( NOT PURE_WINDOWS )
+    check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD)
+  endif()
+
+  if(HAVE_LIBPTHREAD)
+    # We want to find pthreads library and at the moment we do want to
+    # have it reported as '-l<lib>' instead of '-pthread'.
+    # TODO: switch to -pthread once the rest of the build system can deal with it.
+    set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
+    set(THREADS_HAVE_PTHREAD_ARG Off)
+    find_package(Threads REQUIRED)
+    set(OPENMP_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
+  endif()
+else()
+  set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB})
+endif()
index 210ee2f..9fb5476 100644 (file)
@@ -46,6 +46,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "${tmachine}$")
         ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES}
         ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
         dl
+        ${OPENMP_PTHREAD_LIB}
         "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports")
 
       list(APPEND LIBOMPTARGET_TESTED_PLUGINS
index cb4d5d3..7f77bcc 100644 (file)
@@ -52,6 +52,7 @@ target_link_libraries(omptarget.rtl.cuda
   MemoryManager
   ${LIBOMPTARGET_DEP_LIBRARIES}
   ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
+  ${OPENMP_PTHREAD_LIB}
   "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports"
   "-Wl,-z,defs")
 
index 667bb15..038a7ed 100644 (file)
@@ -27,4 +27,5 @@ add_executable(openmp-offloading-server
 target_link_libraries(openmp-offloading-server
         grpc++
         protobuf
+        ${OPENMP_PTHREAD_LIB}
         "-ldl" "-lomp" "-fopenmp" "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../../exports" ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES})
index 17eedc1..de3177f 100644 (file)
@@ -35,6 +35,7 @@ target_link_libraries(omptarget.rtl.rpc
   grpc++
   protobuf
   "-ldl"
+  ${OPENMP_PTHREAD_LIB}
   "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../../exports")
 
 # Report to the parent scope that we are building a plugin for RPC.