Add ProcessorCount support for QNX via pidin. (#11302)

Thanks to Rolf Eike Beer <eike@sf-mail.de> for the code snippet
parsing the pidin output.
This commit is contained in:
David Cole 2010-11-08 09:37:04 -05:00 committed by Brad King
parent 4d6418f683
commit 3430955d5f
2 changed files with 27 additions and 3 deletions

View File

@ -42,7 +42,7 @@ function(ProcessorCount var)
message("ProcessorCount: using sysctl '${ProcessorCount_cmd_sysctl}'") message("ProcessorCount: using sysctl '${ProcessorCount_cmd_sysctl}'")
endif() endif()
else() else()
# Linux (and other systems with getconf): # Linux (systems with getconf):
find_program(ProcessorCount_cmd_getconf getconf) find_program(ProcessorCount_cmd_getconf getconf)
if(ProcessorCount_cmd_getconf) if(ProcessorCount_cmd_getconf)
execute_process(COMMAND ${ProcessorCount_cmd_getconf} _NPROCESSORS_ONLN execute_process(COMMAND ${ProcessorCount_cmd_getconf} _NPROCESSORS_ONLN
@ -50,9 +50,22 @@ function(ProcessorCount var)
OUTPUT_VARIABLE count) OUTPUT_VARIABLE count)
message("ProcessorCount: using getconf '${ProcessorCount_cmd_getconf}'") message("ProcessorCount: using getconf '${ProcessorCount_cmd_getconf}'")
endif() endif()
if(NOT count)
# QNX (systems with pidin):
find_program(ProcessorCount_cmd_pidin pidin)
if(ProcessorCount_cmd_pidin)
execute_process(COMMAND ${ProcessorCount_cmd_pidin} info
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE pidin_output)
string(REGEX MATCHALL "Processor[0-9]+: " procs "${pidin_output}")
list(LENGTH procs count)
message("ProcessorCount: using pidin '${ProcessorCount_cmd_pidin}'")
endif()
endif()
endif() endif()
# Execute this code when there is no 'sysctl' or 'getconf' or # Execute this code when there is no 'sysctl' or 'getconf' or 'pidin' or
# when previously executed methods return empty output: # when previously executed methods return empty output:
# #
if(NOT count) if(NOT count)
@ -65,5 +78,12 @@ function(ProcessorCount var)
endif() endif()
endif() endif()
# Ensure an integer return (avoid inadvertently returning an empty string
# or an error string)... If it's not a decimal integer, return 0:
#
if(NOT count MATCHES "^[0-9]+$")
set(count 0)
endif()
set(${var} ${count} PARENT_SCOPE) set(${var} ${count} PARENT_SCOPE)
endfunction() endfunction()

View File

@ -3,7 +3,11 @@ include(ProcessorCount)
ProcessorCount(processor_count) ProcessorCount(processor_count)
message("processor_count='${processor_count}'") message("processor_count='${processor_count}'")
if(NOT processor_count MATCHES "^[0-9]+$")
message(FATAL_ERROR "ProcessorCount function returned a non-integer")
endif()
if(processor_count EQUAL 0) if(processor_count EQUAL 0)
message(FATAL_ERROR "could not determine number of processors message(FATAL_ERROR "could not determine number of processors
- Additional code needed in ProcessorCount.cmake?") - Additional code for this platform needed in ProcessorCount.cmake?")
endif() endif()