[PATCH] D110489: Make windows resource generation more robust to misconfiguration.

Stella Laurenzo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 25 15:11:18 PDT 2021


stellaraccident created this revision.
Herald added a subscriber: mgorny.
stellaraccident requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I was experiencing this in an out-of-tree project when building a DLL in a context that didn't have LLVM_VERSION_* and friends set. It causes obscure errors in the resource compiler if not integers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110489

Files:
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -363,26 +363,39 @@
     ""
     ${ARGN})
 
+  # Set from arguments.
   if (NOT DEFINED ARG_VERSION_MAJOR)
     set(ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
   endif()
-
   if (NOT DEFINED ARG_VERSION_MINOR)
     set(ARG_VERSION_MINOR ${LLVM_VERSION_MINOR})
   endif()
-
   if (NOT DEFINED ARG_VERSION_PATCHLEVEL)
     set(ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
   endif()
-
   if (NOT DEFINED ARG_VERSION_STRING)
     set(ARG_VERSION_STRING ${PACKAGE_VERSION})
   endif()
-
   if (NOT DEFINED ARG_PRODUCT_NAME)
     set(ARG_PRODUCT_NAME "LLVM")
   endif()
 
+  # Make sure to default integer fields in the case that version information
+  # is not defaulted above (can happen in out of tree projects). Leaving these
+  # blank causes the resource compiler to fail with obscure errors.
+  if (NOT ARG_VERSION_MAJOR)
+    set(ARG_VERSION_MAJOR 0)
+  endif()
+  if (NOT ARG_VERSION_MINOR)
+    set(ARG_VERSION_MINOR 0)
+  endif()
+  if (NOT ARG_VERSION_PATCHLEVEL)
+    set(ARG_VERSION_PATCHLEVEL 0)
+  endif()
+  if (NOT ARG_VERSION_STRING)
+    set(ARG_VERSION_STRING 0)
+  endif()
+
   set_property(SOURCE ${resource_file}
                PROPERTY COMPILE_FLAGS /nologo)
   set_property(SOURCE ${resource_file}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110489.375070.patch
Type: text/x-patch
Size: 1403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210925/cc1ed14d/attachment.bin>


More information about the llvm-commits mailing list