[Openmp-commits] [openmp] a129536 - This check-in makes the following improvements to the OpenMP Windows build:

Vadim Paretsky via Openmp-commits openmp-commits at lists.llvm.org
Thu Mar 2 15:52:17 PST 2023


Author: Vadim Paretsky (Intel Americas Inc)
Date: 2023-03-02T15:50:36-08:00
New Revision: a12953698dce01f46f33ea1c6058e3bb4128624a

URL: https://github.com/llvm/llvm-project/commit/a12953698dce01f46f33ea1c6058e3bb4128624a
DIFF: https://github.com/llvm/llvm-project/commit/a12953698dce01f46f33ea1c6058e3bb4128624a.diff

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

Only generate the second def file when necessary (native Windows import
library builds).
Properly clean up .def file artifacts.
Reduce the re-generated import library build artifacts to the minimum.
Refactor the import library related portions of the script for clarity.

Tested with MSVC and MinWG/gcc12.0

Differential Revision:https://reviews.llvm.org/D144419

Added: 
    

Modified: 
    openmp/runtime/src/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index aa087fe22312f..931975d9445b8 100644
--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -235,10 +235,6 @@ add_dependencies(omp libomp-needed-headers)
 # 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 @@ if(WIN32)
     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 backwards 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 
diff er
-    # 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 toolchains that generated the import library importing by ordinal, re-generate it to import by name
+    set(LIBOMP_IMP_LIB_TARGET ompimp)
+    # Create the auxiliary def file without 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


        


More information about the Openmp-commits mailing list