Skip to content

Commit 96fcaf0

Browse files
committed
[openmp] Fix building for mingw targets after import library changes
06d9bf5 (https://reviews.llvm.org/D143431) did a large restructuring of how the import library is created; previously, a second step to tweak the import library was only done for MSVC style targets, but after this commit, that logic was applied for mingw targets too. Since LIBOMP_GENERATED_IMP_LIB_FILENAME and LIBOMP_IMP_LIB_FILE are equal on mingw targets (both are "libomp.dll.a", while they are "libomp.dll.lib" and "libomp.lib" for MSVC targets), this caused a conflict, with errors like this: ninja: error: build.ninja:875: multiple rules generate runtime/src/libomp.dll.a [-w dupbuild=err] Skip the logic with a second step to recreate the import library for mingw targets. The MSVC specific logic for this relies on running the static archiver with CMAKE_LINK_DEF_FILE_FLAG, which with MS lib.exe (and llvm-lib) ignore the input object files and just generates an import library - but mingw style tools don't support this mode of operation. (By attemptinig the same, mingw tools would generate a static library with the def file as one member.) With mingw tools, the same can be achieved by invoking the dlltool executable instead. Instead of adding alternative logic for invoking dlltool, just skip the second import library step, since neither GNU nor LLVM mingw tools actually generate import libraries that link by ordinal - so there's no need for a second import library. Differential Revision: https://reviews.llvm.org/D143992
1 parent cb5f239 commit 96fcaf0

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

openmp/runtime/cmake/LibompMicroTests.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
# get library location
4141
if(WIN32)
4242
get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY)
43-
get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ompimp ARCHIVE_OUTPUT_DIRECTORY)
43+
get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ${LIBOMP_IMP_LIB_TARGET} ARCHIVE_OUTPUT_DIRECTORY)
4444
if(NOT LIBOMPIMP_OUTPUT_DIRECTORY)
4545
set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
4646
endif()

openmp/runtime/src/CMakeLists.txt

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ if(WIN32)
272272
ARCHIVE_OUTPUT_NAME ${LIBOMP_GENERATED_IMP_LIB_FILENAME}
273273
)
274274

275+
if(MSVC)
276+
set(LIBOMP_IMP_LIB_TARGET ompimp)
277+
else()
278+
set(LIBOMP_IMP_LIB_TARGET omp)
279+
endif()
280+
275281
# Create def files to designate exported functions
276282
libomp_get_gdflags(LIBOMP_GDFLAGS) # generate-def.pl flags (Windows only)
277283
libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS)
@@ -289,18 +295,31 @@ if(WIN32)
289295
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
290296
)
291297

292-
# Regenerate the import library to import by name, not ordinal
293-
add_library(ompimp STATIC ${LIBOMP_SOURCE_FILES})
294-
set_target_properties(ompimp PROPERTIES
295-
PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}"
296-
LINKER_LANGUAGE C
297-
)
298-
set_target_properties(ompimp PROPERTIES STATIC_LIBRARY_OPTIONS
299-
"${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE_IMP}"
300-
)
301-
add_dependencies(ompimp libomp-needed-headers)
302-
303-
298+
if (MSVC)
299+
# Regenerate the import library to import by name, not ordinal.
300+
#
301+
# For mingw, we can't regenerate an import library by passing
302+
# CMAKE_LINK_DEF_FILE_FLAG to the static library archiver; that just
303+
# ends up creating a regular static library that contains the def file.
304+
# For mingw, we would have to call the suitable dlltool for regenerating
305+
# an import library. However, neither GNU nor LLVM based mingw tools
306+
# generate import libraries that actually link by ordinal, so this step
307+
# isn't strictly necessary.
308+
#
309+
# Also, in mingw builds, LIBOMP_GENERATED_IMP_LIB_FILENAME and
310+
# LIBOMP_IMP_LIB_FILE currently end up equal, while they need to differ
311+
# for this second step to work.
312+
add_library(ompimp STATIC ${LIBOMP_SOURCE_FILES})
313+
set_target_properties(ompimp PROPERTIES
314+
PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}"
315+
LINKER_LANGUAGE C
316+
)
317+
set_target_properties(ompimp PROPERTIES STATIC_LIBRARY_OPTIONS
318+
"${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE_IMP}"
319+
)
320+
add_dependencies(ompimp libomp-needed-headers)
321+
endif()
322+
304323
endif()
305324

306325
# Building the Fortran module files
@@ -357,7 +376,7 @@ add_dependencies(libomp-micro-tests libomp-test-deps)
357376
# We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR}
358377
if(WIN32)
359378
install(TARGETS omp RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
360-
install(TARGETS ompimp ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
379+
install(TARGETS ${LIBOMP_IMP_LIB_TARGET} ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
361380
# Create aliases (regular copies) of the library for backwards compatibility
362381
set(LIBOMP_ALIASES "libiomp5md")
363382
foreach(alias IN LISTS LIBOMP_ALIASES)

0 commit comments

Comments
 (0)