From: navarro Date: Tue, 24 Jan 2012 10:32:04 +0000 (+0100) Subject: Add a script to detect the number of core. X-Git-Tag: exp_20120216~119^2~21 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/39b99d7659c7f2ecd789c141a8fced9bf9684cff?hp=6cee149e4ad8077a5c4db40ed591232dfaff1224 Add a script to detect the number of core. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 54b68d11d4..10b14d897f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,6 +233,9 @@ else(NOT WIN32) include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDocWin.cmake) endif(NOT WIN32) +### Print NbCore +include(FindNbCore) + ### Print ARGS include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake) diff --git a/buildtools/Cmake/Modules/FindNbCore.cmake b/buildtools/Cmake/Modules/FindNbCore.cmake new file mode 100644 index 0000000000..a3c1809176 --- /dev/null +++ b/buildtools/Cmake/Modules/FindNbCore.cmake @@ -0,0 +1,28 @@ +if(NOT DEFINED PROCESSOR_COUNT) + # Unknown: + set(PROCESSOR_COUNT 0) + + # Linux: + set(cpuinfo_file "/proc/cpuinfo") + if(EXISTS "${cpuinfo_file}") + file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$") + list(LENGTH procs PROCESSOR_COUNT) + endif() + + # Mac: + if(APPLE) + find_program(cmd_sys_pro "system_profiler") + if(cmd_sys_pro) + execute_process(COMMAND ${cmd_sys_pro} OUTPUT_VARIABLE info) + string(REGEX REPLACE "^.*Total Number Of Cores: ([0-9]+).*$" "\\1" + PROCESSOR_COUNT "${info}") + endif() + endif() + + # Windows: + if(WIN32) + set(PROCESSOR_COUNT "$ENV{NUMBER_OF_PROCESSORS}") + endif() +endif() + +message(STATUS "Number of core ${PROCESSOR_COUNT}") \ No newline at end of file