From b204f06ec3cd654bea1aad03bc7c19596a7d6a8b Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Fri, 24 Nov 2023 21:20:38 +1100 Subject: [PATCH] cmake: use `nproc` if _num_cores is zero The previous workaround set _num_cores to 1 if cmake thought NUMBER_OF_LOGICAL_CORES was zero. That worked fine, but it'd be much better to take advantage of all possible cores. This version runs `nproc` which seems to work just fine under qemu-aarch64 and gives us the actual number of CPUs. Fixes: b6669263cacd56ff589529784066b9f637f79e87 Signed-off-by: Tim Serong --- cmake/modules/LimitJobs.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/modules/LimitJobs.cmake b/cmake/modules/LimitJobs.cmake index 41dd3e509cae4d..2114830a0f78f1 100644 --- a/cmake/modules/LimitJobs.cmake +++ b/cmake/modules/LimitJobs.cmake @@ -5,7 +5,11 @@ cmake_host_system_information(RESULT _num_cores QUERY NUMBER_OF_LOGICAL_CORES) # This will never be zero on a real system, but it can be if you're doing # weird things like trying to cross-compile using qemu emulation. if(_num_cores EQUAL 0) - set(_num_cores 1) + execute_process( + COMMAND "nproc" + OUTPUT_VARIABLE _num_cores + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(WARNING "Unable to query NUMBER_OF_LOGICAL_CORES, defaulting to nproc (${_num_cores})") endif() cmake_host_system_information(RESULT _total_mem QUERY TOTAL_PHYSICAL_MEMORY)