[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:31:02 PDT 2025
https://github.com/RKSimon updated https://github.com/llvm/llvm-project/pull/151167
>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 1/2] [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)
>From 4184bdb566c8dcdcd8b06ad6add335b2e2518a7a Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Tue, 29 Jul 2025 16:30:36 +0100
Subject: [PATCH 2/2] Limit to VS builds so other MSVC builds can still use
"__SHORT_FILE__" define
---
llvm/cmake/modules/LLVMProcessSources.cmake | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/cmake/modules/LLVMProcessSources.cmake b/llvm/cmake/modules/LLVMProcessSources.cmake
index e3f9a7637b506..b6d5aee4d8a22 100644
--- a/llvm/cmake/modules/LLVMProcessSources.cmake
+++ b/llvm/cmake/modules/LLVMProcessSources.cmake
@@ -58,8 +58,8 @@ function(llvm_process_sources OUT_VAR)
set(sources ${ARG_UNPARSED_ARGUMENTS})
llvm_check_source_file_list(${sources})
- # Don't generate __SHORT_FILE__ on MSVC builds as it can force repeated cache regeneration.
- if(NOT MSVC)
+ # Don't generate __SHORT_FILE__ on VS builds as it can prevent build parallelisation.
+ if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
foreach(fn ${sources})
get_filename_component(suf ${fn} EXT)
if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c")
More information about the llvm-commits
mailing list