[llvm] [cmake] Serialize native builds for Make generator (PR #121021)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 00:44:55 PST 2025


================
@@ -2,14 +2,18 @@ include(ExternalProject)
 
 # llvm_ExternalProject_BuildCmd(out_var target)
 #   Utility function for constructing command lines for external project targets
-function(llvm_ExternalProject_BuildCmd out_var target bin_dir)
+function(llvm_ExternalProject_BuildCmd out_var target bin_dir stamp_dir)
   cmake_parse_arguments(ARG "" "CONFIGURATION" "" ${ARGN})
   if(NOT ARG_CONFIGURATION)
     set(ARG_CONFIGURATION "$<CONFIG>")
   endif()
   if (CMAKE_GENERATOR MATCHES "Make")
     # Use special command for Makefiles to support parallelism.
-    set(${out_var} "$(MAKE)" "-C" "${bin_dir}" "${target}" PARENT_SCOPE)
+    set(make_cmd "$(MAKE)" "-C" "${bin_dir}" "${target}")
+    set(file_lock_script "${LLVM_CMAKE_DIR}/FileLock.cmake")
+    set(${out_var} ${CMAKE_COMMAND} "-DLOCK_FILE_PATH=${stamp_dir}/cmake.lock"
+                                    "-DCOMMAND='${make_cmd}'"
----------------
arthurqiu wrote:

I did a quick test and it looks like `ExternalProject_Add_Step` would wrap command with `sh -c`, i.e. it has the same behavior as `add_custom_command` without `VERBATIM`, and unfortunately `ExternalProject_Add_Step` does not have a `VERBATIM` argument. So it would break code [here](https://github.com/llvm/llvm-project/blob/53c7fe50d869386459226aeac5ec72ee918737c9/llvm/cmake/modules/LLVMExternalProjectUtils.cmake#L414) if either `|` or `\;` is used as separator because they have special meaning in shell.

For now, I use `@` as separator. We can choose something different if `@` is too common. I'm not familiar with how to test CMake flow [here](https://github.com/llvm/llvm-project/blob/53c7fe50d869386459226aeac5ec72ee918737c9/llvm/cmake/modules/LLVMExternalProjectUtils.cmake#L414). So I just ran some CMake unit test to verify cmd parsing works as expected with/without VERBATIM mode on both linux/windows.

https://github.com/llvm/llvm-project/pull/121021


More information about the llvm-commits mailing list