Skip to content

Commit

Permalink
cmake: use nproc if _num_cores is zero
Browse files Browse the repository at this point in the history
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: b666926
Signed-off-by: Tim Serong <[email protected]>
  • Loading branch information
tserong committed Nov 24, 2023
1 parent 70d8c11 commit d20b0f7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmake/modules/LimitJobs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d20b0f7

Please sign in to comment.