source: PSPA/madxPSPA/cmake/setupProcessorCount.cmake @ 478

Last change on this file since 478 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 977 bytes
Line 
1# small script that detects number of processors.
2# after this script, you can add the following
3# to your ctest script:
4#
5# if(PROCESSOR_COUNT)
6#  set(CTEST_BUILD_FLAGS "-j${PROCESSOR_COUNT}")
7# endif()
8#
9# Source: http://www.kitware.com/blog/home/post/63
10if(NOT DEFINED PROCESSOR_COUNT)
11  # Unknown:
12  set(PROCESSOR_COUNT 0)
13
14  # Linux:
15  set(cpuinfo_file "/proc/cpuinfo")
16  if(EXISTS "${cpuinfo_file}")
17    file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$")
18    list(LENGTH procs PROCESSOR_COUNT)
19  endif()
20
21  # Mac:
22  if(APPLE)
23    find_program(cmd_sys_pro "system_profiler")
24    if(cmd_sys_pro)
25      execute_process(COMMAND ${cmd_sys_pro} OUTPUT_VARIABLE info)
26      string(REGEX REPLACE "^.*Total Number Of Cores: ([0-9]+).*$" "\\1"
27        PROCESSOR_COUNT "${info}")
28    endif()
29  endif()
30
31  # Windows:
32  if(WIN32)
33    set(PROCESSOR_COUNT "$ENV{NUMBER_OF_PROCESSORS}")
34  endif()
35endif()
36
37message(STATUS "Number of processors found: ${PROCESSOR_COUNT}")
Note: See TracBrowser for help on using the repository browser.