Skip to content

Commit eccdb24

Browse files
authored
[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.
1 parent a0c3189 commit eccdb24

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
@@ -253,6 +253,17 @@ if(NOT WIN32)
253253
libiomp5${LIBOMP_LIBRARY_SUFFIX}
254254
WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}
255255
)
256+
if(LIBOMP_ENABLE_SHARED)
257+
if(APPLE)
258+
set(VERSIONED_LIBGOMP_NAME libgomp.1${LIBOMP_LIBRARY_SUFFIX})
259+
else()
260+
set(VERSIONED_LIBGOMP_NAME libgomp${LIBOMP_LIBRARY_SUFFIX}.1)
261+
endif()
262+
add_custom_command(TARGET omp POST_BUILD
263+
COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE} ${VERSIONED_LIBGOMP_NAME}
264+
WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}
265+
)
266+
endif()
256267
endif()
257268

258269
# Definitions for testing, for reuse when testing libomptarget-nvptx.
@@ -439,13 +450,18 @@ else()
439450

440451
if(${LIBOMP_INSTALL_ALIASES})
441452
# Create aliases (symlinks) of the library for backwards compatibility
453+
extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
442454
set(LIBOMP_ALIASES "libgomp;libiomp5")
443455
foreach(alias IN LISTS LIBOMP_ALIASES)
444-
extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
445456
install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
446457
\"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY
447458
\"\$ENV{DESTDIR}${outdir}\")")
448459
endforeach()
460+
if(LIBOMP_ENABLE_SHARED)
461+
install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
462+
\"${VERSIONED_LIBGOMP_NAME}\" WORKING_DIRECTORY
463+
\"\$ENV{DESTDIR}${outdir}\")")
464+
endif()
449465
endif()
450466
endif()
451467
install(

0 commit comments

Comments
 (0)