[llvm] [cmake] Don't generate per-file "__SHORT_FILE__" defines on visual studio builds (PR #151167)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 30 00:26:15 PDT 2025
https://github.com/RKSimon updated https://github.com/llvm/llvm-project/pull/151167
>From 061cfbd3520279624d45d19378693d2bc9fffe6e 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 | 23 ++++++++++++---------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/llvm/cmake/modules/LLVMProcessSources.cmake b/llvm/cmake/modules/LLVMProcessSources.cmake
index 6282b26bddded..e3c53aea8d9a4 100644
--- a/llvm/cmake/modules/LLVMProcessSources.cmake
+++ b/llvm/cmake/modules/LLVMProcessSources.cmake
@@ -58,16 +58,19 @@ 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_property(
- SOURCE ${fn}
- APPEND
- PROPERTY 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_property(
+ SOURCE ${fn}
+ APPEND
+ PROPERTY COMPILE_DEFINITIONS __SHORT_FILE__="${short_name}")
+ endif()
+ endforeach()
+ endif()
# This adds .td and .h files to the Visual Studio solution:
>From a7c24e3f25da95ac2268af70e339a4035c982249 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 e3c53aea8d9a4..cf358a88f5fb6 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