-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspsHardware.cmake
31 lines (26 loc) · 1.07 KB
/
spsHardware.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Define a reusable function for getting processor count and other hardware info
function(sps_get_processor_count MAX_CONCURRENCY_VAR)
if (UNIX)
# Execute a system command to get the processor count
execute_process(COMMAND nproc OUTPUT_VARIABLE PROCESSOR_COUNT OUTPUT_STRIP_TRAILING_WHITESPACE)
# Fallback if the result is empty
if (PROCESSOR_COUNT STREQUAL "")
message(WARNING "Processor count could not be determined. Defaulting to 1.")
set(PROCESSOR_COUNT 1)
endif()
message(STATUS "Detected ${PROCESSOR_COUNT} processors.")
else()
include(ProcessorCount)
# Get the processor count
ProcessorCount(PROCESSOR_COUNT)
# Check if processor count was successfully retrieved
if (PROCESSOR_COUNT EQUAL 0)
message(WARNING "Processor count could not be determined. Defaulting to 1.")
set(PROCESSOR_COUNT 1)
else()
message(STATUS "Detected ${PROCESSOR_COUNT} processors.")
endif()
endif()
# Assign outputs to the provided variables
set(${MAX_CONCURRENCY_VAR} ${PROCESSOR_COUNT} PARENT_SCOPE)
endfunction()