[Openmp-commits] [PATCH] D130892: [OpenMP] Only include CMAKE_DL_LIBS on unix platforms

Martin Storsjö via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Aug 1 03:05:02 PDT 2022


mstorsjo created this revision.
mstorsjo added reviewers: AndreyChurbanov, JonChesterfield, jdoerfert.
Herald added subscribers: guansong, yaxunl, mgorny.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: OpenMP.

CMAKE_DL_LIBS is documented as "Name of library containing dlopen
and dlclose".

On Windows platforms, there's no system provided dlopen/dlclose, but
it can be argued that if you really intend to call dlopen/dlclose,
you're going to be using a third party compat library like
https://github.com/dlfcn-win32/dlfcn-win32, and CMAKE_DL_LIBS should
expand to its name.

This has been argued upstream in CMake in
https://gitlab.kitware.com/cmake/cmake/-/issues/17600 and
https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1642, that
CMAKE_DL_LIBS should expand to "dl" on mingw platforms.

The merge request wasn't merged though, as it caused some amount of
breakage, but in practice, Fedora still carries a custom CMake patch
with the same effect.

Thus, this patch fixes cross compiling OpenMP for mingw targets
on Fedora with their cutom-patched CMake.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130892

Files:
  openmp/runtime/src/CMakeLists.txt


Index: openmp/runtime/src/CMakeLists.txt
===================================================================
--- openmp/runtime/src/CMakeLists.txt
+++ openmp/runtime/src/CMakeLists.txt
@@ -139,6 +139,10 @@
   set(LIBOMP_LINKER_LANGUAGE CXX)
 endif()
 
+if(UNIX)
+  set(LIBOMP_DL_LIBS ${CMAKE_DL_LIBS})
+endif()
+
 # Add the OpenMP library
 libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS)
 
@@ -147,10 +151,10 @@
 if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMP_PROFILING))
   add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES})
   # Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS
-  target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${CMAKE_DL_LIBS})
+  target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS})
 else()
   add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES} PARTIAL_SOURCES_INTENDED
-    LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${CMAKE_DL_LIBS}
+    LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS}
     LINK_COMPONENTS Support
     )
   # libomp must be a C++ library such that it can link libLLVMSupport


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130892.448978.patch
Type: text/x-patch
Size: 1109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220801/3354e71e/attachment.bin>


More information about the Openmp-commits mailing list