[llvm] [cmake] Don't generate per-file "__SHORT_FILE__" defines on MSVC builds (PR #151167)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 08:01:21 PDT 2025


https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/151167

As reported on #150677 - this prevents build parallelisation as cmake is repeatedly updating the cache

>From 8080a6382692fc74130d2b2f837bba009b35a08c Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Tue, 29 Jul 2025 16:00:12 +0100
Subject: [PATCH] [cmake] Don't generate per-file "__SHORT_FILE__" defines on
 MSVC builds

As reported on #150677 - this prevents build parallelisation as cmake is repeatedly updating the cache
---
 llvm/cmake/modules/LLVMProcessSources.cmake | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/llvm/cmake/modules/LLVMProcessSources.cmake b/llvm/cmake/modules/LLVMProcessSources.cmake
index a7f9517ad767c..e3f9a7637b506 100644
--- a/llvm/cmake/modules/LLVMProcessSources.cmake
+++ b/llvm/cmake/modules/LLVMProcessSources.cmake
@@ -58,14 +58,16 @@ function(llvm_process_sources OUT_VAR)
   set(sources ${ARG_UNPARSED_ARGUMENTS})
   llvm_check_source_file_list(${sources})
 
-  foreach(fn ${sources})
-    get_filename_component(suf ${fn} EXT)
-    if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c")
-      get_filename_component(short_name ${fn} NAME)
-      set_source_files_properties(${fn} PROPERTIES COMPILE_DEFINITIONS "__SHORT_FILE__=\"${short_name}\"")
-    endif()
-  endforeach()
-
+  # Don't generate __SHORT_FILE__ on MSVC builds as it can force repeated cache regeneration.
+  if(NOT MSVC)
+    foreach(fn ${sources})
+      get_filename_component(suf ${fn} EXT)
+      if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c")
+        get_filename_component(short_name ${fn} NAME)
+        set_source_files_properties(${fn} PROPERTIES COMPILE_DEFINITIONS "__SHORT_FILE__=\"${short_name}\"")
+      endif()
+    endforeach()
+  endif()
 
   # This adds .td and .h files to the Visual Studio solution:
   add_td_sources(sources)



More information about the llvm-commits mailing list