mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 16:32:14 -06:00
ProcessorCount: Return the container CPU count instead of the host count
On Linux containers (tested with LXC and Docker) getconf returns the host CPU count. Use nproc with a higher priority if available to get the container's allocated CPUs instead of the non-accessible host count.
This commit is contained in:
@@ -69,6 +69,20 @@ function(ProcessorCount var)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT count)
|
||||
# Linux (systems with nproc):
|
||||
# Prefer nproc to getconf if available as getconf may return the host CPU count in Linux containers
|
||||
find_program(ProcessorCount_cmd_nproc nproc)
|
||||
mark_as_advanced(ProcessorCount_cmd_nproc)
|
||||
if(ProcessorCount_cmd_nproc)
|
||||
execute_process(COMMAND ${ProcessorCount_cmd_nproc}
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
OUTPUT_VARIABLE count)
|
||||
#message("ProcessorCount: trying nproc '${ProcessorCount_cmd_nproc}'")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT count)
|
||||
# Linux (systems with getconf):
|
||||
find_program(ProcessorCount_cmd_getconf getconf)
|
||||
|
||||
Reference in New Issue
Block a user