Skip to content

Commit b827971

Browse files
ye-luollvmbot
authored andcommitted
[OpenMP] Create versioned libgomp softlinks (#112973)
Add libgomp.1.dylib for MacOS and libgomp.so.1 for Linux Linkers on Mac and Linux pick up versioned libgomp dynamic library files. The existing softlinks (libgomp.dylib for MacOS and libgomp.so for Linux) are insufficient. This helps alleviate the issue of mixing libgomp and libomp at runtime. (cherry picked from commit eccdb24)
1 parent d174e2a commit b827971

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

openmp/runtime/src/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ if(NOT WIN32)
244244
libiomp5${LIBOMP_LIBRARY_SUFFIX}
245245
WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}
246246
)
247+
if(LIBOMP_ENABLE_SHARED)
248+
if(APPLE)
249+
set(VERSIONED_LIBGOMP_NAME libgomp.1${LIBOMP_LIBRARY_SUFFIX})
250+
else()
251+
set(VERSIONED_LIBGOMP_NAME libgomp${LIBOMP_LIBRARY_SUFFIX}.1)
252+
endif()
253+
add_custom_command(TARGET omp POST_BUILD
254+
COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE} ${VERSIONED_LIBGOMP_NAME}
255+
WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}
256+
)
257+
endif()
247258
endif()
248259

249260
# Definitions for testing, for reuse when testing libomptarget-nvptx.
@@ -430,13 +441,18 @@ else()
430441

431442
if(${LIBOMP_INSTALL_ALIASES})
432443
# Create aliases (symlinks) of the library for backwards compatibility
444+
extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
433445
set(LIBOMP_ALIASES "libgomp;libiomp5")
434446
foreach(alias IN LISTS LIBOMP_ALIASES)
435-
extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
436447
install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
437448
\"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY
438449
\"\$ENV{DESTDIR}${outdir}\")")
439450
endforeach()
451+
if(LIBOMP_ENABLE_SHARED)
452+
install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
453+
\"${VERSIONED_LIBGOMP_NAME}\" WORKING_DIRECTORY
454+
\"\$ENV{DESTDIR}${outdir}\")")
455+
endif()
440456
endif()
441457
endif()
442458
install(

0 commit comments

Comments
 (0)