mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-26 08:08:24 -05: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()
|
||||||
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)
|
if(NOT count)
|
||||||
# Linux (systems with getconf):
|
# Linux (systems with getconf):
|
||||||
find_program(ProcessorCount_cmd_getconf getconf)
|
find_program(ProcessorCount_cmd_getconf getconf)
|
||||||
|
|||||||
Reference in New Issue
Block a user