diff --git a/PrintVariables.cmake b/PrintVariables.cmake new file mode 100644 index 0000000000000000000000000000000000000000..b267e9c3d74511d0e3da84edc08888c5f8f71838 --- /dev/null +++ b/PrintVariables.cmake @@ -0,0 +1,152 @@ +# ------------------------- Begin Generic CMake Variable Logging ------------------ + +# /* C++ comment style not allowed */ + + +# if you are building in-source, this is the same as CMAKE_SOURCE_DIR, otherwise +# this is the top level directory of your build tree +MESSAGE( STATUS "CMAKE_BINARY_DIR: " ${CMAKE_BINARY_DIR} ) + +# if you are building in-source, this is the same as CMAKE_CURRENT_SOURCE_DIR, otherwise this +# is the directory where the compiled or generated files from the current CMakeLists.txt will go to +MESSAGE( STATUS "CMAKE_CURRENT_BINARY_DIR: " ${CMAKE_CURRENT_BINARY_DIR} ) + +# this is the directory, from which cmake was started, i.e. the top level source directory +MESSAGE( STATUS "CMAKE_SOURCE_DIR: " ${CMAKE_SOURCE_DIR} ) + +# this is the directory where the currently processed CMakeLists.txt is located in +MESSAGE( STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR} ) + +# contains the full path to the top level directory of your build tree +MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} ) + +# contains the full path to the root of your project source directory, +# i.e. to the nearest directory where CMakeLists.txt contains the PROJECT() command +MESSAGE( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} ) + +# set this variable to specify a common place where CMake should put all executable files +# (instead of CMAKE_CURRENT_BINARY_DIR) +MESSAGE( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} ) + +# set this variable to specify a common place where CMake should put all libraries +# (instead of CMAKE_CURRENT_BINARY_DIR) +MESSAGE( STATUS "LIBRARY_OUTPUT_PATH: " ${LIBRARY_OUTPUT_PATH} ) + +# tell CMake to search first in directories listed in CMAKE_MODULE_PATH +# when you use FIND_PACKAGE() or INCLUDE() +MESSAGE( STATUS "CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH} ) + +# this is the complete path of the cmake which runs currently (e.g. /usr/local/bin/cmake) +MESSAGE( STATUS "CMAKE_COMMAND: " ${CMAKE_COMMAND} ) + +# this is the CMake installation directory +MESSAGE( STATUS "CMAKE_ROOT: " ${CMAKE_ROOT} ) + +# this is the filename including the complete path of the file where this variable is used. +MESSAGE( STATUS "CMAKE_CURRENT_LIST_FILE: " ${CMAKE_CURRENT_LIST_FILE} ) + +# this is linenumber where the variable is used +MESSAGE( STATUS "CMAKE_CURRENT_LIST_LINE: " ${CMAKE_CURRENT_LIST_LINE} ) + +# this is used when searching for include files e.g. using the FIND_PATH() command. +MESSAGE( STATUS "CMAKE_INCLUDE_PATH: " ${CMAKE_INCLUDE_PATH} ) + +# this is used when searching for libraries e.g. using the FIND_LIBRARY() command. +MESSAGE( STATUS "CMAKE_LIBRARY_PATH: " ${CMAKE_LIBRARY_PATH} ) + +# the complete system name, e.g. "Linux-2.4.22", "FreeBSD-5.4-RELEASE" or "Windows 5.1" +MESSAGE( STATUS "CMAKE_SYSTEM: " ${CMAKE_SYSTEM} ) + +# the short system name, e.g. "Linux", "FreeBSD" or "Windows" +MESSAGE( STATUS "CMAKE_SYSTEM_NAME: " ${CMAKE_SYSTEM_NAME} ) + +# only the version part of CMAKE_SYSTEM +MESSAGE( STATUS "CMAKE_SYSTEM_VERSION: " ${CMAKE_SYSTEM_VERSION} ) + +# the processor name (e.g. "Intel(R) Pentium(R) M processor 2.00GHz") +MESSAGE( STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR} ) + +# is TRUE on all UNIX-like OS's, including Apple OS X and CygWin +MESSAGE( STATUS "UNIX: " ${UNIX} ) + +# is TRUE on Windows, including CygWin +MESSAGE( STATUS "WIN32: " ${WIN32} ) + +# is TRUE on Apple OS X +MESSAGE( STATUS "APPLE: " ${APPLE} ) + +# is TRUE when using the MinGW compiler in Windows +MESSAGE( STATUS "MINGW: " ${MINGW} ) + +# is TRUE on Windows when using the CygWin version of cmake +MESSAGE( STATUS "CYGWIN: " ${CYGWIN} ) + +# is TRUE on Windows when using a Borland compiler +MESSAGE( STATUS "BORLAND: " ${BORLAND} ) + +# Microsoft compiler +MESSAGE( STATUS "MSVC: " ${MSVC} ) +MESSAGE( STATUS "MSVC_IDE: " ${MSVC_IDE} ) +MESSAGE( STATUS "MSVC60: " ${MSVC60} ) +MESSAGE( STATUS "MSVC70: " ${MSVC70} ) +MESSAGE( STATUS "MSVC71: " ${MSVC71} ) +MESSAGE( STATUS "MSVC80: " ${MSVC80} ) +MESSAGE( STATUS "CMAKE_COMPILER_2005: " ${CMAKE_COMPILER_2005} ) + + +# set this to true if you don't want to rebuild the object files if the rules have changed, +# but not the actual source files or headers (e.g. if you changed the some compiler switches) +MESSAGE( STATUS "CMAKE_SKIP_RULE_DEPENDENCY: " ${CMAKE_SKIP_RULE_DEPENDENCY} ) + +# since CMake 2.1 the install rule depends on all, i.e. everything will be built before installing. +# If you don't like this, set this one to true. +MESSAGE( STATUS "CMAKE_SKIP_INSTALL_ALL_DEPENDENCY: " ${CMAKE_SKIP_INSTALL_ALL_DEPENDENCY} ) + +# If set, runtime paths are not added when using shared libraries. Default it is set to OFF +MESSAGE( STATUS "CMAKE_SKIP_RPATH: " ${CMAKE_SKIP_RPATH} ) + +# set this to true if you are using makefiles and want to see the full compile and link +# commands instead of only the shortened ones +MESSAGE( STATUS "CMAKE_VERBOSE_MAKEFILE: " ${CMAKE_VERBOSE_MAKEFILE} ) + +# this will cause CMake to not put in the rules that re-run CMake. This might be useful if +# you want to use the generated build files on another machine. +MESSAGE( STATUS "CMAKE_SUPPRESS_REGENERATION: " ${CMAKE_SUPPRESS_REGENERATION} ) + + +# A simple way to get switches to the compiler is to use ADD_DEFINITIONS(). +# But there are also two variables exactly for this purpose: + +# the compiler flags for compiling C sources +MESSAGE( STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS} ) + +# the compiler flags for compiling C++ sources +MESSAGE( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} ) + + +# Choose the type of build. Example: SET(CMAKE_BUILD_TYPE Debug) +MESSAGE( STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE} ) + +# if this is set to ON, then all libraries are built as shared libraries by default. +MESSAGE( STATUS "BUILD_SHARED_LIBS: " ${BUILD_SHARED_LIBS} ) + +# the compiler used for C files +MESSAGE( STATUS "CMAKE_C_COMPILER: " ${CMAKE_C_COMPILER} ) + +# the compiler used for C++ files +MESSAGE( STATUS "CMAKE_CXX_COMPILER: " ${CMAKE_CXX_COMPILER} ) + +# if the compiler is a variant of gcc, this should be set to 1 +MESSAGE( STATUS "CMAKE_COMPILER_IS_GNUCC: " ${CMAKE_COMPILER_IS_GNUCC} ) + +# if the compiler is a variant of g++, this should be set to 1 +MESSAGE( STATUS "CMAKE_COMPILER_IS_GNUCXX : " ${CMAKE_COMPILER_IS_GNUCXX} ) + +# the tools for creating libraries +MESSAGE( STATUS "CMAKE_AR: " ${CMAKE_AR} ) +MESSAGE( STATUS "CMAKE_RANLIB: " ${CMAKE_RANLIB} ) + +# +#MESSAGE( STATUS ": " ${} ) + +# ------------------------- End of Generic CMake Variable Logging ------------------ diff --git a/ProcessorCount.cmake b/ProcessorCount.cmake new file mode 100644 index 0000000000000000000000000000000000000000..7f6efa23a10c521ce0f2eed113c03f3bd5e9e5fd --- /dev/null +++ b/ProcessorCount.cmake @@ -0,0 +1,183 @@ +# - 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 implemented for AIX, cygwin, FreeBSD, HPUX, +# IRIX, Linux, Mac OS X, QNX, Sun and Windows. +# +# This function is guaranteed to return a positive integer (>=1) if it +# succeeds. It returns 0 if there's a problem determining the processor count. +# +# Example use, in a ctest -S dashboard script: +# +# include(ProcessorCount) +# ProcessorCount(N) +# if(NOT N EQUAL 0) +# set(CTEST_BUILD_FLAGS -j${N}) +# set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N}) +# endif() +# +# This function is intended to offer an approximation of the value of the +# number of compute cores available on the current machine, such that you +# may use that value for parallel building and parallel testing. It is meant +# to help utilize as much of the machine as seems reasonable. Of course, +# knowledge of what else might be running on the machine simultaneously +# should be used when deciding whether to request a machine's full capacity +# all for yourself. + +# 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 2010-2011 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 distribute 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}") + #message("ProcessorCount: WIN32, trying environment variable") + endif() + + if(NOT count) + # Mac, FreeBSD, OpenBSD (systems with sysctl): + find_program(ProcessorCount_cmd_sysctl sysctl + PATHS /usr/sbin /sbin) + if(ProcessorCount_cmd_sysctl) + execute_process(COMMAND ${ProcessorCount_cmd_sysctl} -n hw.ncpu + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE count) + #message("ProcessorCount: trying sysctl '${ProcessorCount_cmd_sysctl}'") + endif() + endif() + + if(NOT count) + # Linux (systems with getconf): + find_program(ProcessorCount_cmd_getconf getconf) + if(ProcessorCount_cmd_getconf) + execute_process(COMMAND ${ProcessorCount_cmd_getconf} _NPROCESSORS_ONLN + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE count) + #message("ProcessorCount: trying getconf '${ProcessorCount_cmd_getconf}'") + endif() + endif() + + if(NOT count) + # HPUX (systems with machinfo): + find_program(ProcessorCount_cmd_machinfo machinfo + PATHS /usr/contrib/bin) + if(ProcessorCount_cmd_machinfo) + execute_process(COMMAND ${ProcessorCount_cmd_machinfo} + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE machinfo_output) + string(REGEX MATCHALL "Number of CPUs = ([0-9]+)" procs "${machinfo_output}") + set(count "${CMAKE_MATCH_1}") + #message("ProcessorCount: trying machinfo '${ProcessorCount_cmd_machinfo}'") + endif() + endif() + + if(NOT count) + # IRIX (systems with hinv): + find_program(ProcessorCount_cmd_hinv hinv + PATHS /sbin) + if(ProcessorCount_cmd_hinv) + execute_process(COMMAND ${ProcessorCount_cmd_hinv} + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE hinv_output) + string(REGEX MATCHALL "([0-9]+) .* Processors" procs "${hinv_output}") + set(count "${CMAKE_MATCH_1}") + #message("ProcessorCount: trying hinv '${ProcessorCount_cmd_hinv}'") + endif() + endif() + + if(NOT count) + # AIX (systems with lsconf): + find_program(ProcessorCount_cmd_lsconf lsconf + PATHS /usr/sbin) + if(ProcessorCount_cmd_lsconf) + execute_process(COMMAND ${ProcessorCount_cmd_lsconf} + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE lsconf_output) + string(REGEX MATCHALL "Number Of Processors: ([0-9]+)" procs "${lsconf_output}") + set(count "${CMAKE_MATCH_1}") + #message("ProcessorCount: trying lsconf '${ProcessorCount_cmd_lsconf}'") + endif() + endif() + + if(NOT count) + # QNX (systems with pidin): + find_program(ProcessorCount_cmd_pidin pidin) + if(ProcessorCount_cmd_pidin) + execute_process(COMMAND ${ProcessorCount_cmd_pidin} info + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE pidin_output) + string(REGEX MATCHALL "Processor[0-9]+: " procs "${pidin_output}") + list(LENGTH procs count) + #message("ProcessorCount: trying pidin '${ProcessorCount_cmd_pidin}'") + endif() + endif() + + if(NOT count) + # Sun (systems where uname -X emits "NumCPU" in its output): + find_program(ProcessorCount_cmd_uname uname) + if(ProcessorCount_cmd_uname) + execute_process(COMMAND ${ProcessorCount_cmd_uname} -X + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE uname_X_output) + string(REGEX MATCHALL "NumCPU = ([0-9]+)" procs "${uname_X_output}") + set(count "${CMAKE_MATCH_1}") + #message("ProcessorCount: trying uname -X '${ProcessorCount_cmd_uname}'") + endif() + endif() + + # Execute this code when all previously attempted methods return empty + # output: + # + if(NOT count) + # 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) + #message("ProcessorCount: trying cpuinfo '${cpuinfo_file}'") + endif() + endif() + + # Since cygwin builds of CMake do not define WIN32 anymore, but they still + # run on Windows, and will still have this env var defined: + # + if(NOT count) + set(count "$ENV{NUMBER_OF_PROCESSORS}") + #message("ProcessorCount: last fallback, trying environment variable") + endif() + + # Ensure an integer return (avoid inadvertently returning an empty string + # or an error string)... If it's not a decimal integer, return 0: + # + if(NOT count MATCHES "^[0-9]+$") + set(count 0) + endif() + + set(${var} ${count} PARENT_SCOPE) +endfunction() \ No newline at end of file