[Cmake-commits] CMake branch, next, updated. v2.8.3-542-gc12ea6d

David Cole david.cole at kitware.com
Fri Nov 5 09:04:17 EDT 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  c12ea6d54a09c1c87ee36a17ec02c55bfbee2277 (commit)
       via  b12df8e1048065fb26c850d4ee7d37501886260f (commit)
      from  c96b596c6e8ff4e31ac11fb4be3d115ba9289e68 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c12ea6d54a09c1c87ee36a17ec02c55bfbee2277
commit c12ea6d54a09c1c87ee36a17ec02c55bfbee2277
Merge: c96b596 b12df8e
Author:     David Cole <david.cole at kitware.com>
AuthorDate: Fri Nov 5 09:04:16 2010 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Fri Nov 5 09:04:16 2010 -0400

    Merge topic 'add-ProcessorCount-module' into next
    
    b12df8e Add module ProcessorCount.cmake (#11302)


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b12df8e1048065fb26c850d4ee7d37501886260f
commit b12df8e1048065fb26c850d4ee7d37501886260f
Author:     Michael Wild <themiwi at users.sourceforge.net>
AuthorDate: Fri Oct 8 09:16:04 2010 +0200
Commit:     David Cole <david.cole at kitware.com>
CommitDate: Fri Nov 5 08:55:31 2010 -0400

    Add module ProcessorCount.cmake (#11302)
    
    Credit goes to David Cole ( http://www.kitware.com/blog/home/post/63 ).
    
    Also add a script-based test of the new module.
    
    Signed-off-by: Michael Wild <themiwi at users.sourceforge.net>

diff --git a/Modules/ProcessorCount.cmake b/Modules/ProcessorCount.cmake
new file mode 100644
index 0000000..e4aea19
--- /dev/null
+++ b/Modules/ProcessorCount.cmake
@@ -0,0 +1,60 @@
+# - ProcessorCount(var)
+# Determine the number of processors/cores and save value in ${var}
+#
+# Sets the variable named ${var} to the number of physical cores available on
+# the machine if the information can be determined. Otherwise it is set to 0.
+# Currently this functionality is only implemented for Windows, Mac OS X and
+# Unix systems providing getconf or the /proc/cpuinfo interface (e.g. Linux).
+
+# A more reliable way might be to compile a small C program that uses the CPUID
+# instruction, but that again requires compiler support or compiling assembler
+# code.
+
+#=============================================================================
+# Copyright 2002-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distributed this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+function(ProcessorCount var)
+  # Unknown:
+  set(count 0)
+
+  if(WIN32)
+    # Windows:
+    set(count "$ENV{NUMBER_OF_PROCESSORS}")
+  elseif(APPLE)
+    # Mac:
+    find_program(ProcessorCount_cmd_sysctl sysctl
+      PATHS /usr/sbin)
+    if(ProcessorCount_cmd_sysctl)
+      execute_process(COMMAND ${ProcessorCount_cmd_sysctl} -n hw.ncpu
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+        OUTPUT_VARIABLE count)
+    endif()
+  else()
+    find_program(ProcessorCount_cmd_getconf getconf)
+    if(ProcessorCount_cmd_getconf)
+      # Linux and other systems with getconf:
+      execute_process(COMMAND ${ProcessorCount_cmd_getconf} _NPROCESSORS_ONLN
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+        OUTPUT_VARIABLE count)
+    else()
+      # Linux and other systems with /proc/cpuinfo:
+      set(cpuinfo_file /proc/cpuinfo)
+      if(EXISTS "${cpuinfo_file}")
+        file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$")
+        list(LENGTH procs count)
+      endif()
+    endif()
+  endif()
+
+  set(${var} ${count} PARENT_SCOPE)
+endfunction()
diff --git a/Tests/CMakeTests/CMakeLists.txt b/Tests/CMakeTests/CMakeLists.txt
index 8fd52df..9664872 100644
--- a/Tests/CMakeTests/CMakeLists.txt
+++ b/Tests/CMakeTests/CMakeLists.txt
@@ -27,6 +27,7 @@ AddCMakeTest(String "")
 AddCMakeTest(Math "")
 AddCMakeTest(CMakeMinimumRequired "")
 AddCMakeTest(CompilerIdVendor "")
+AddCMakeTest(ProcessorCount "")
 
 AddCMakeTest(FileDownload "")
 set_property(TEST CMake.FileDownload PROPERTY
diff --git a/Tests/CMakeTests/ProcessorCountTest.cmake.in b/Tests/CMakeTests/ProcessorCountTest.cmake.in
new file mode 100644
index 0000000..0815fd8
--- /dev/null
+++ b/Tests/CMakeTests/ProcessorCountTest.cmake.in
@@ -0,0 +1,9 @@
+include(ProcessorCount)
+
+ProcessorCount(processor_count)
+message("processor_count='${processor_count}'")
+
+if(processor_count EQUAL 0)
+  message(FATAL_ERROR "could not determine number of processors
+- Additional code needed in ProcessorCount.cmake?")
+endif()

-----------------------------------------------------------------------

Summary of changes:
 Modules/ProcessorCount.cmake                 |   60 ++++++++++++++++++++++++++
 Tests/CMakeTests/CMakeLists.txt              |    1 +
 Tests/CMakeTests/ProcessorCountTest.cmake.in |    9 ++++
 3 files changed, 70 insertions(+), 0 deletions(-)
 create mode 100644 Modules/ProcessorCount.cmake
 create mode 100644 Tests/CMakeTests/ProcessorCountTest.cmake.in


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list