Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a script to detect the number of core.
[simgrid.git] / buildtools / Cmake / Modules / FindNbCore.cmake
1 if(NOT DEFINED PROCESSOR_COUNT)
2   # Unknown:
3   set(PROCESSOR_COUNT 0)
4
5   # Linux:
6   set(cpuinfo_file "/proc/cpuinfo")
7   if(EXISTS "${cpuinfo_file}")
8     file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$")
9     list(LENGTH procs PROCESSOR_COUNT)
10   endif()
11
12   # Mac:
13   if(APPLE)
14     find_program(cmd_sys_pro "system_profiler")
15     if(cmd_sys_pro)
16       execute_process(COMMAND ${cmd_sys_pro} OUTPUT_VARIABLE info)
17       string(REGEX REPLACE "^.*Total Number Of Cores: ([0-9]+).*$" "\\1"
18         PROCESSOR_COUNT "${info}")
19     endif()
20   endif()
21
22   # Windows:
23   if(WIN32)
24     set(PROCESSOR_COUNT "$ENV{NUMBER_OF_PROCESSORS}")
25   endif()
26 endif()
27
28 message(STATUS "Number of core ${PROCESSOR_COUNT}")