[Openmp-commits] [PATCH] D144419: Improvements to the OpenMP Windows build

Vadim Paretsky via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Feb 20 11:23:34 PST 2023


vadikp-intel created this revision.
vadikp-intel added reviewers: mstorsjo, natgla.
vadikp-intel added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
vadikp-intel requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: openmp-commits, sstefan1.

This check-in makes the following improvements to the OpenMP Windows build:

1. Only generate the second def file when necessary (native Windows builds).
2. Properly clean up .def file artifacts.
3. Minimize the regenerated import library build artifacts to the minimum.
4. Refactor the import library related portions of the script for clarity.

tested with MSVC and MinWG/gcc12.0


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144419

Files:
  openmp/runtime/src/CMakeLists.txt


Index: openmp/runtime/src/CMakeLists.txt
===================================================================
--- openmp/runtime/src/CMakeLists.txt
+++ openmp/runtime/src/CMakeLists.txt
@@ -235,10 +235,6 @@
 # Windows specific build rules
 if(WIN32)
   configure_file(libomp.rc.var libomp.rc @ONLY)
-
-  # Create .def and .rc file before compiling any sources
-  add_custom_target(libomp-needed-windows-files DEPENDS ${LIBOMP_LIB_NAME}.def)
-  add_dependencies(omp libomp-needed-windows-files)
   # z_Windows_NT-586_asm.asm requires definitions to be sent via command line
   # It only needs the architecture macro and OMPT_SUPPORT=0|1
   libomp_append(LIBOMP_MASM_DEFINITIONS "-D_M_IA32" IF_TRUE IA32)
@@ -272,54 +268,42 @@
     ARCHIVE_OUTPUT_NAME ${LIBOMP_GENERATED_IMP_LIB_FILENAME}
   )
 
-  if(MSVC)
-    set(LIBOMP_IMP_LIB_TARGET ompimp)
-  else()
-    set(LIBOMP_IMP_LIB_TARGET omp)
-  endif()
-
-  # Create def files to designate exported functions
-  libomp_get_gdflags(LIBOMP_GDFLAGS) # generate-def.pl flags (Windows only)
-  libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS)
+  set(LIBOMP_IMP_LIB_TARGET omp)
   set(LIBOMP_GENERATED_DEF_FILE ${LIBOMP_LIB_NAME}.def)
-  set(LIBOMPIMP_GENERATED_DEF_FILE_IMP ${LIBOMP_LIB_NAME}.imp.def)
+  add_custom_target(libomp-needed-def-file DEPENDS ${LIBOMP_GENERATED_DEF_FILE})
+  add_dependencies(omp libomp-needed-def-file)
+    
+  # Create the main def file with ordinals to use for building the runtime dll to maintain backwads compatible exports order
+  libomp_get_gdflags(LIBOMP_GDFLAGS)
+  libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS)
   add_custom_command(
-    OUTPUT  ${LIBOMP_LIB_NAME}.def
-    # one with ordinals to use for building the runtime dll to maintain backwads compatible exports order
+    OUTPUT  ${LIBOMP_GENERATED_DEF_FILE}
     COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} -D NAME=${LIBOMP_LIB_FILE}
             -o ${LIBOMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
-    # one without ordinals to use for building the import library to remove ordinal dependency going forward
-    COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} -D NAME=${LIBOMP_LIB_FILE} -D NOORDINALS
-            -o ${LIBOMPIMP_GENERATED_DEF_FILE_IMP} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
-    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
   )
 
-  if (MSVC)
-    # Regenerate the import library to import by name, not ordinal.
-    #
-    # For mingw, we can't regenerate an import library by passing
-    # CMAKE_LINK_DEF_FILE_FLAG to the static library archiver; that just
-    # ends up creating a regular static library that contains the def file.
-    # For mingw, we would have to call the suitable dlltool for regenerating
-    # an import library. However, neither GNU nor LLVM based mingw tools
-    # generate import libraries that actually link by ordinal, so this step
-    # isn't strictly necessary.
-    #
-    # Also, in mingw builds, LIBOMP_GENERATED_IMP_LIB_FILENAME and
-    # LIBOMP_IMP_LIB_FILE currently end up equal, while they need to differ
-    # for this second step to work.
-    add_library(ompimp STATIC ${LIBOMP_SOURCE_FILES})
-      set_target_properties(ompimp PROPERTIES
-        PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}"
-      LINKER_LANGUAGE C
-    )
-    set_target_properties(ompimp PROPERTIES STATIC_LIBRARY_OPTIONS
-        "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE_IMP}"
+  if(MSVC)
+    # For native Windows builds we need to regenerate the import library to import by name
+    set(LIBOMP_IMP_LIB_TARGET ompimp)
+    # Create the auxiliary def file wihtout ordinals to use for building the import library to import by name 
+    set(LIBOMPIMP_GENERATED_DEF_FILE ${LIBOMP_LIB_NAME}.imp.def)
+    add_custom_target(libompimp-needed-def-file DEPENDS ${LIBOMPIMP_GENERATED_DEF_FILE})
+    add_custom_command(
+      OUTPUT  ${LIBOMPIMP_GENERATED_DEF_FILE}
+      COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} -D NAME=${LIBOMP_LIB_FILE} -D NOORDINALS
+          -o ${LIBOMPIMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
+      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
     )
-    add_dependencies(ompimp libomp-needed-headers)
+    # while this is merely generating an import library off the one generated with the runtime dll,
+    # kmp_global.cpp will satisfy the librarian's apparent ask to see the actual exported DATA items
+    set_source_files_properties(${LIBOMP_GENERATED_IMP_LIB_FILENAME} PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE)
+    add_library(${LIBOMP_IMP_LIB_TARGET} STATIC ${LIBOMP_GENERATED_IMP_LIB_FILENAME} kmp_global.cpp)
+    set_target_properties(${LIBOMP_IMP_LIB_TARGET} PROPERTIES
+        PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}" LINKER_LANGUAGE C
+        STATIC_LIBRARY_OPTIONS "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE}")
+    add_dependencies(${LIBOMP_IMP_LIB_TARGET} omp libompimp-needed-def-file)
   endif()
-
 endif()
 
 # Building the Fortran module files


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144419.498918.patch
Type: text/x-patch
Size: 5336 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230220/cd67184a/attachment-0001.bin>


More information about the Openmp-commits mailing list