diff options
-rw-r--r-- | Help/release/3.19.rst | 17 | ||||
-rw-r--r-- | Help/release/3.20.rst | 8 | ||||
-rw-r--r-- | Help/variable/MSVC_IDE.rst | 7 | ||||
-rw-r--r-- | Modules/CMakeDetermineCUDACompiler.cmake | 7 | ||||
-rw-r--r-- | Modules/CMakePlatformId.h.in | 3 | ||||
-rw-r--r-- | Modules/Compiler/IAR-ASM.cmake | 5 | ||||
-rw-r--r-- | Modules/Compiler/IAR-C.cmake | 4 | ||||
-rw-r--r-- | Modules/Compiler/IAR-CXX.cmake | 4 | ||||
-rw-r--r-- | Modules/Compiler/IAR-DetermineCompiler.cmake | 2 | ||||
-rw-r--r-- | Modules/Compiler/IAR-FindBinUtils.cmake | 3 | ||||
-rw-r--r-- | Modules/Compiler/IntelLLVM.cmake | 1 | ||||
-rw-r--r-- | Modules/FindCUDA.cmake | 7 | ||||
-rw-r--r-- | Modules/FindCUDAToolkit.cmake | 7 | ||||
-rw-r--r-- | Modules/FindGDAL.cmake | 59 | ||||
-rw-r--r-- | Modules/FindMPI.cmake | 4 | ||||
-rw-r--r-- | Source/kwsys/SystemInformation.cxx | 246 |
16 files changed, 265 insertions, 119 deletions
diff --git a/Help/release/3.19.rst b/Help/release/3.19.rst index d819e8c..d8f4f9d 100644 --- a/Help/release/3.19.rst +++ b/Help/release/3.19.rst @@ -408,3 +408,20 @@ Changes made since CMake 3.19.0 include the following. variable introduced in 3.19.0 previously worked only with the :generator:`Visual Studio 14 2015` generator. It has now been fixed to work with :ref:`Visual Studio Generators` for later VS versions too. + + +3.19.5 +------ + +* When :prop_tgt:`IOS_INSTALL_COMBINED` is enabled and the :generator:`Xcode` + generator is used, it is now possible to initiate an install or package + creation by running ``cmake --install`` or ``cpack`` from the command line. + When using the Xcode new build system, these are the only supported methods + due to a limitation of Xcode. Initiating these operations by building the + ``install`` or ``package`` targets in Xcode is only supported when using + the legacy build system. + +* The framework handling introduced in 3.19.0 as part of supporting Xcode's + *Link Binaries With Libraries* build phase broke the ability to switch + between device and simulator builds without reconfiguring. That capability + has now been restored. diff --git a/Help/release/3.20.rst b/Help/release/3.20.rst index 0f0d67b..b36d1c2 100644 --- a/Help/release/3.20.rst +++ b/Help/release/3.20.rst @@ -58,6 +58,8 @@ Compilers The Intel oneAPI Classic compilers (``icc``, ``icpc``, and ``ifort``) continue to be supported with compiler id ``Intel``. +* Support was added for the IAR STM8 compiler. + Platforms --------- @@ -186,6 +188,12 @@ Modules toolkits when ``nvcc`` is a symbolic link, for example due to a ``ccache`` or ``colornvcc`` wrapper script. +* The :module:`FindGDAL` module has been improved to document and mark as + advanced its cache variables. There is a new ``FindGDAL_SKIP_GDAL_CONFIG`` + variable which may be used to skip over the ``gdal-config``-based search. + Users may also set ``GDAL_ADDITIONAL_LIBRARY_VERSIONS`` to add additional + versions to the library name search strategy. + * The :module:`FindIntl` module now provides an imported target. * The :module:`FindOpenSSL` module learned to support a version range. diff --git a/Help/variable/MSVC_IDE.rst b/Help/variable/MSVC_IDE.rst index 027d1bc..18e9983 100644 --- a/Help/variable/MSVC_IDE.rst +++ b/Help/variable/MSVC_IDE.rst @@ -5,3 +5,10 @@ MSVC_IDE Set to ``true`` when the target platform is the Microsoft Visual C++ IDE, as opposed to the command line compiler. + +.. note:: + + This variable is only available after compiler detection has been performed, + so it is not available to toolchain files or before the first + :command:`project` or :command:`enable_language` call which uses an + MSVC-like compiler. diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index 468b8a1..dd539b7 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -175,14 +175,15 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) # Given that NVCC can be provided by multiple different sources (NVIDIA HPC SDK, CUDA Toolkit, distro) # each of which has a different layout, we need to extract the CUDA toolkit root from the compiler # itself, allowing us to support numerous different scattered toolkit layouts - execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR) - if(NVCC_ERR MATCHES "TOP=([^\r\n]*)") + execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" + OUTPUT_VARIABLE _CUDA_NVCC_OUT ERROR_VARIABLE _CUDA_NVCC_OUT) + if(_CUDA_NVCC_OUT MATCHES "TOP=([^\r\n]*)") get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_MATCH_1}" ABSOLUTE) else() get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${_CUDA_NVCC_EXECUTABLE}" DIRECTORY) get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}" DIRECTORY) endif() - unset(NVCC_ERR) + unset(_CUDA_NVCC_OUT) set(CMAKE_CUDA_DEVICE_LINKER "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/bin/nvlink${CMAKE_EXECUTABLE_SUFFIX}") set(CMAKE_CUDA_FATBINARY "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/bin/fatbinary${CMAKE_EXECUTABLE_SUFFIX}") diff --git a/Modules/CMakePlatformId.h.in b/Modules/CMakePlatformId.h.in index c0cab71..1dc12c0 100644 --- a/Modules/CMakePlatformId.h.in +++ b/Modules/CMakePlatformId.h.in @@ -186,6 +186,9 @@ # elif defined(__ICC8051__) # define ARCHITECTURE_ID "8051" +# elif defined(__ICCSTM8__) +# define ARCHITECTURE_ID "STM8" + # else /* unknown architecture */ # define ARCHITECTURE_ID "" # endif diff --git a/Modules/Compiler/IAR-ASM.cmake b/Modules/Compiler/IAR-ASM.cmake index 936d4ae..e3ca16e 100644 --- a/Modules/Compiler/IAR-ASM.cmake +++ b/Modules/Compiler/IAR-ASM.cmake @@ -47,6 +47,11 @@ elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "8051") __compiler_iar_xlink(ASM) set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s51;asm;msa) +elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "STM8") + set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>") + __compiler_iar_ilink(ASM) + set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa) + else() message(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID not detected. This should be automatic.") endif() diff --git a/Modules/Compiler/IAR-C.cmake b/Modules/Compiler/IAR-C.cmake index e27fdfc..054ee74 100644 --- a/Modules/Compiler/IAR-C.cmake +++ b/Modules/Compiler/IAR-C.cmake @@ -70,6 +70,10 @@ elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "8051") __compiler_check_default_language_standard(C 6.10 90 8.10 99) set(CMAKE_C_OUTPUT_EXTENSION ".r51") +elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "STM8") + __compiler_iar_ilink(C) + __compiler_check_default_language_standard(C 3.11 90 3.11 99) + else() message(FATAL_ERROR "CMAKE_C_COMPILER_ARCHITECTURE_ID not detected. This should be automatic.") endif() diff --git a/Modules/Compiler/IAR-CXX.cmake b/Modules/Compiler/IAR-CXX.cmake index eca89c5..d93b272 100644 --- a/Modules/Compiler/IAR-CXX.cmake +++ b/Modules/Compiler/IAR-CXX.cmake @@ -78,6 +78,10 @@ elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "8051") __compiler_check_default_language_standard(CXX 6.10 98) set(CMAKE_C_OUTPUT_EXTENSION ".r51") +elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "STM8") + __compiler_iar_ilink(CXX) + __compiler_check_default_language_standard(CXX 3.11 98) + else() message(FATAL_ERROR "CMAKE_CXX_COMPILER_ARCHITECTURE_ID not detected. This should be automatic." ) endif() diff --git a/Modules/Compiler/IAR-DetermineCompiler.cmake b/Modules/Compiler/IAR-DetermineCompiler.cmake index 0a026b2..443b09c 100644 --- a/Modules/Compiler/IAR-DetermineCompiler.cmake +++ b/Modules/Compiler/IAR-DetermineCompiler.cmake @@ -31,7 +31,7 @@ set(_compiler_id_version_compute " # define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(((__VER__) / 1000) % 1000) # define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@((__VER__) % 1000) # define @PREFIX@COMPILER_VERSION_INTERNAL @MACRO_DEC@(__IAR_SYSTEMS_ICC__) -# elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__)) +# elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__) || defined(__ICCSTM8__)) # define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@((__VER__) / 100) # define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@((__VER__) - (((__VER__) / 100)*100)) # define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__SUBVERSION__) diff --git a/Modules/Compiler/IAR-FindBinUtils.cmake b/Modules/Compiler/IAR-FindBinUtils.cmake index 6ef3759..6c67d34 100644 --- a/Modules/Compiler/IAR-FindBinUtils.cmake +++ b/Modules/Compiler/IAR-FindBinUtils.cmake @@ -14,7 +14,8 @@ if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "A "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RX" OR "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RH850" OR "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RL78" OR - "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RISCV") + "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RISCV" OR + "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" STREQUAL "STM8") string(TOLOWER "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ARCHITECTURE_ID}" _archid_lower) diff --git a/Modules/Compiler/IntelLLVM.cmake b/Modules/Compiler/IntelLLVM.cmake index 43eb13a..14b7ad8 100644 --- a/Modules/Compiler/IntelLLVM.cmake +++ b/Modules/Compiler/IntelLLVM.cmake @@ -18,7 +18,6 @@ set(__pch_header_OBJCXX "objective-c++-header") if(CMAKE_HOST_WIN32) # MSVC-like macro(__compiler_intel_llvm lang) - set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-imsvc ") if(NOT "x${lang}" STREQUAL "xFortran") set(CMAKE_${lang}_COMPILE_OPTIONS_INVALID_PCH -Winvalid-pch) endif() diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 3d10aef..620e32a 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -837,14 +837,15 @@ if(NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING) # Given that NVCC can be provided by multiple different sources (NVIDIA HPC SDK, CUDA Toolkit, distro) # each of which has a different layout, we need to extract the CUDA toolkit root from the compiler # itself, allowing us to support numerous different scattered toolkit layouts - execute_process(COMMAND ${CUDA_TOOLKIT_ROOT_DIR_NVCC} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR) - if(NVCC_ERR MATCHES "TOP=([^\r\n]*)") + execute_process(COMMAND ${CUDA_TOOLKIT_ROOT_DIR_NVCC} "-v" "__cmake_determine_cuda" + OUTPUT_VARIABLE _CUDA_NVCC_OUT ERROR_VARIABLE _CUDA_NVCC_OUT) + if(_CUDA_NVCC_OUT MATCHES "TOP=([^\r\n]*)") get_filename_component(CUDA_TOOLKIT_ROOT_DIR "${CMAKE_MATCH_1}" ABSOLUTE CACHE) else() get_filename_component(CUDA_TOOLKIT_ROOT_DIR "${CUDA_TOOLKIT_ROOT_DIR_NVCC}" DIRECTORY) get_filename_component(CUDA_TOOLKIT_ROOT_DIR "${CUDA_TOOLKIT_ROOT_DIR}" DIRECTORY CACHE) endif() - unset(NVCC_ERR) + unset(_CUDA_NVCC_OUT) string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR}) # We need to force this back into the cache. diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake index 256c98f..de2b068 100644 --- a/Modules/FindCUDAToolkit.cmake +++ b/Modules/FindCUDAToolkit.cmake @@ -522,13 +522,14 @@ else() # If NVCC exists then invoke it to find the toolkit location. # This allows us to support wrapper scripts (e.g. ccache or colornvcc), CUDA Toolkit, # NVIDIA HPC SDK, and distro's splayed layouts - execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR) - if(NVCC_ERR MATCHES "TOP=([^\r\n]*)") + execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" + OUTPUT_VARIABLE _CUDA_NVCC_OUT ERROR_VARIABLE _CUDA_NVCC_OUT) + if(_CUDA_NVCC_OUT MATCHES "TOP=([^\r\n]*)") get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_MATCH_1}/bin" ABSOLUTE) else() get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY) endif() - unset(NVCC_ERR) + unset(_CUDA_NVCC_OUT) mark_as_advanced(CUDAToolkit_BIN_DIR) set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE) diff --git a/Modules/FindGDAL.cmake b/Modules/FindGDAL.cmake index 406a738..5237e15 100644 --- a/Modules/FindGDAL.cmake +++ b/Modules/FindGDAL.cmake @@ -45,6 +45,15 @@ Hints Set ``GDAL_DIR`` or ``GDAL_ROOT`` in the environment to specify the GDAL installation prefix. + +The following variables may be set to modify the search strategy: + +``FindGDAL_SKIP_GDAL_CONFIG`` + If set, ``gdal-config`` will not be used. This can be useful if there are + GDAL libraries built with autotools (which provide the tool) and CMake (which + do not) in the same environment. +``GDAL_ADDITIONAL_LIBRARY_VERSIONS`` + Extra versions of library names to search for. #]=======================================================================] # $GDALDIR is an environment variable that would @@ -68,12 +77,14 @@ find_path(GDAL_INCLUDE_DIR gdal.h ENV GDAL_DIR ENV GDAL_ROOT PATH_SUFFIXES - include/gdal - include/GDAL - include + include/gdal + include/GDAL + include + DOC "Path to the GDAL include directory" ) +mark_as_advanced(GDAL_INCLUDE_DIR) -if(UNIX) +if(UNIX AND NOT FindGDAL_SKIP_GDAL_CONFIG) # Use gdal-config to obtain the library version (this should hopefully # allow us to -lgdal1.x.y where x.y are correct version) # For some reason, libgdal development packages do not contain @@ -83,10 +94,12 @@ if(UNIX) ENV GDAL_DIR ENV GDAL_ROOT PATH_SUFFIXES bin + DOC "Path to the gdal-config tool" ) + mark_as_advanced(GDAL_CONFIG) if(GDAL_CONFIG) - exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS) + execute_process(COMMAND ${GDAL_CONFIG} --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS) if(GDAL_CONFIG_LIBS) # treat the output as a command line and split it up @@ -134,14 +147,30 @@ if(UNIX) endif() endif() +# GDAL name its library when built with CMake as `gdal${major}${minor}`. +set(_gdal_versions + ${GDAL_ADDITIONAL_LIBRARY_VERSIONS} 3.0 2.4 2.3 2.2 2.1 2.0 1.11 1.10 1.9 1.8 1.7 1.6 1.5 1.4 1.3 1.2) + +set(_gdal_libnames) +foreach (_gdal_version IN LISTS _gdal_versions) + string(REPLACE "." "" _gdal_version "${_gdal_version}") + list(APPEND _gdal_libnames "gdal${_gdal_version}" "GDAL${_gdal_version}") +endforeach () +unset(_gdal_version) +unset(_gdal_versions) + find_library(GDAL_LIBRARY - NAMES ${_gdal_lib} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL + NAMES ${_gdal_lib} ${_gdal_libnames} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL HINTS ENV GDAL_DIR ENV GDAL_ROOT ${_gdal_libpath} PATH_SUFFIXES lib + DOC "Path to the GDAL library" ) +mark_as_advanced(GDAL_LIBRARY) +unset(_gdal_libnames) +unset(_gdal_lib) if (EXISTS "${GDAL_INCLUDE_DIR}/gdal_version.h") file(STRINGS "${GDAL_INCLUDE_DIR}/gdal_version.h" _gdal_version @@ -157,12 +186,14 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL VERSION_VAR GDAL_VERSION REQUIRED_VARS GDAL_LIBRARY GDAL_INCLUDE_DIR) -if (GDAL_FOUND AND NOT TARGET GDAL::GDAL) - add_library(GDAL::GDAL UNKNOWN IMPORTED) - set_target_properties(GDAL::GDAL PROPERTIES - IMPORTED_LOCATION "${GDAL_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${GDAL_INCLUDE_DIR}") -endif () +if (GDAL_FOUND) + set(GDAL_LIBRARIES ${GDAL_LIBRARY}) + set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR}) -set(GDAL_LIBRARIES ${GDAL_LIBRARY}) -set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR}) + if (NOT TARGET GDAL::GDAL) + add_library(GDAL::GDAL UNKNOWN IMPORTED) + set_target_properties(GDAL::GDAL PROPERTIES + IMPORTED_LOCATION "${GDAL_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GDAL_INCLUDE_DIR}") + endif () +endif () diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake index 8cc39ac..195ca49 100644 --- a/Modules/FindMPI.cmake +++ b/Modules/FindMPI.cmake @@ -1428,7 +1428,9 @@ foreach(LANG IN ITEMS C CXX Fortran) endif() else() set(_MPI_FIND_${LANG} FALSE) - string(APPEND _MPI_FAIL_REASON "MPI component '${LANG}' was requested, but language ${LANG} is not enabled. ") + if(${LANG} IN_LIST MPI_FIND_COMPONENTS) + string(APPEND _MPI_FAIL_REASON "MPI component '${LANG}' was requested, but language ${LANG} is not enabled. ") + endif() endif() if(_MPI_FIND_${LANG}) if( ${LANG} STREQUAL CXX AND NOT MPICXX IN_LIST MPI_FIND_COMPONENTS ) diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index 9607c00..7743eab 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -448,6 +448,7 @@ public: HP, Hygon, Zhaoxin, + Apple, UnknownManufacturer }; @@ -1752,6 +1753,8 @@ const char* SystemInformationImplementation::GetVendorID() return "Chengdu Haiguang IC Design Co., Ltd."; case Zhaoxin: return "Shanghai Zhaoxin Semiconductor Co., Ltd."; + case Apple: + return "Apple"; case UnknownManufacturer: default: return "Unknown Manufacturer"; @@ -2135,6 +2138,8 @@ void SystemInformationImplementation::FindManufacturer( this->ChipManufacturer = Motorola; // Motorola Microelectronics else if (family.compare(0, 7, "PA-RISC") == 0) this->ChipManufacturer = HP; // Hewlett-Packard + else if (this->ChipID.Vendor == "Apple") + this->ChipManufacturer = Apple; // Apple else this->ChipManufacturer = UnknownManufacturer; // Unknown manufacturer } @@ -4503,33 +4508,62 @@ unsigned int SystemInformationImplementation::GetNumberOfPhysicalCPU() const return this->NumberOfPhysicalCPU; } -/** For Mac use sysctlbyname calls to find system info */ +#if defined(__APPLE__) +static int kw_sysctlbyname_int32(const char* name, int32_t* value) +{ + size_t len = sizeof(int32_t); + int err = sysctlbyname(name, value, &len, nullptr, 0); + if (err == 0) { + assert(len == sizeof(int32_t)); + } + return err; +} + +static int kw_sysctlbyname_int64(const char* name, int64_t* value) +{ + size_t len = sizeof(int64_t); + int err = sysctlbyname(name, value, &len, nullptr, 0); + if (err == 0) { + assert(len == sizeof(int64_t)); + } + return err; +} +#endif + +/** For Apple use sysctlbyname calls to find system info */ bool SystemInformationImplementation::ParseSysCtl() { #if defined(__APPLE__) - char retBuf[128]; + char tempBuff[128]; + int32_t tempInt32 = 0; + int64_t tempInt64 = 0; int err = 0; - uint64_t value = 0; - size_t len = sizeof(value); - sysctlbyname("hw.memsize", &value, &len, nullptr, 0); - this->TotalPhysicalMemory = static_cast<size_t>(value / 1048576); + size_t len; + + this->TotalPhysicalMemory = 0; + err = kw_sysctlbyname_int64("hw.memsize", &tempInt64); + if (err == 0) { + this->TotalPhysicalMemory = static_cast<size_t>(tempInt64 / 1024 / 1024); + } - // Parse values for Mac this->AvailablePhysicalMemory = 0; vm_statistics_data_t vmstat; mach_msg_type_number_t count = HOST_VM_INFO_COUNT; if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) == KERN_SUCCESS) { - len = sizeof(value); - err = sysctlbyname("hw.pagesize", &value, &len, nullptr, 0); - int64_t available_memory = - (vmstat.free_count + vmstat.inactive_count) * value; - this->AvailablePhysicalMemory = - static_cast<size_t>(available_memory / 1048576); + err = kw_sysctlbyname_int64("hw.pagesize", &tempInt64); + if (err == 0) { + int64_t available_memory = + (vmstat.free_count + vmstat.inactive_count) * tempInt64; + this->AvailablePhysicalMemory = + static_cast<size_t>(available_memory / 1024 / 1024); + } } -# ifdef VM_SWAPUSAGE // Virtual memory. + this->AvailableVirtualMemory = 0; + this->TotalVirtualMemory = 0; +# ifdef VM_SWAPUSAGE int mib[2] = { CTL_VM, VM_SWAPUSAGE }; unsigned int miblen = static_cast<unsigned int>(sizeof(mib) / sizeof(mib[0])); @@ -4538,78 +4572,98 @@ bool SystemInformationImplementation::ParseSysCtl() err = sysctl(mib, miblen, &swap, &len, nullptr, 0); if (err == 0) { this->AvailableVirtualMemory = - static_cast<size_t>(swap.xsu_avail / 1048576); - this->TotalVirtualMemory = static_cast<size_t>(swap.xsu_total / 1048576); + static_cast<size_t>(swap.xsu_avail / 1024 / 1024); + this->TotalVirtualMemory = + static_cast<size_t>(swap.xsu_total / 1024 / 1024); } -# else - this->AvailableVirtualMemory = 0; - this->TotalVirtualMemory = 0; # endif // CPU Info - len = sizeof(this->NumberOfPhysicalCPU); - sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len, nullptr, 0); - len = sizeof(this->NumberOfLogicalCPU); - sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, nullptr, 0); - - int cores_per_package = 0; - len = sizeof(cores_per_package); - err = sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, &len, - nullptr, 0); - // That name was not found, default to 1 - this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = - err != 0 ? 1 : static_cast<unsigned char>(cores_per_package); + this->NumberOfPhysicalCPU = 1; + err = kw_sysctlbyname_int32("hw.physicalcpu", &tempInt32); + if (err == 0) { + this->NumberOfPhysicalCPU = tempInt32; + } - len = sizeof(value); - sysctlbyname("hw.cpufrequency", &value, &len, nullptr, 0); - this->CPUSpeedInMHz = static_cast<float>(value) / 1000000; + this->NumberOfLogicalCPU = 1; + err = kw_sysctlbyname_int32("hw.logicalcpu", &tempInt32); + if (err == 0) { + this->NumberOfLogicalCPU = tempInt32; + } + + this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = 1; + err = kw_sysctlbyname_int32("machdep.cpu.cores_per_package", &tempInt32); + if (err == 0) { + this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = tempInt32; + } + + this->CPUSpeedInMHz = 0; + err = kw_sysctlbyname_int64("hw.cpufrequency", &tempInt64); + if (err == 0) { + this->CPUSpeedInMHz = static_cast<float>(tempInt64) / 1000000.0f; + } // Chip family - len = sizeof(this->ChipID.Family); - // Seems only the intel chips will have this name so if this fails it is - // probably a PPC machine - err = - sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len, nullptr, 0); + // Seems only the Intel chips will have this name so if this fails it is + // a PowerPC or ARM, or something unknown + this->ChipID.Vendor = ""; + this->ChipID.Family = 0; + this->ChipID.Model = 0; + this->ChipID.Revision = 0; + err = kw_sysctlbyname_int32("machdep.cpu.family", &tempInt32); if (err != 0) // Go back to names we know but are less descriptive { - this->ChipID.Family = 0; - ::memset(retBuf, 0, 128); - len = 32; - err = sysctlbyname("hw.machine", &retBuf, &len, nullptr, 0); - std::string machineBuf(retBuf); - if (machineBuf.find_first_of("Power") != std::string::npos) { - this->ChipID.Vendor = "IBM"; - len = sizeof(this->ChipID.Family); - err = sysctlbyname("hw.cputype", &this->ChipID.Family, &len, nullptr, 0); - len = sizeof(this->ChipID.Model); - err = - sysctlbyname("hw.cpusubtype", &this->ChipID.Model, &len, nullptr, 0); - this->FindManufacturer(); + ::memset(tempBuff, 0, sizeof(tempBuff)); + len = sizeof(tempBuff) - 1; // leave a byte for null termination + err = sysctlbyname("hw.machine", &tempBuff, &len, nullptr, 0); + if (err == 0) { + std::string machineBuf(tempBuff); + if (machineBuf.find_first_of("Power") != std::string::npos) { + this->ChipID.Vendor = "IBM"; + + err = kw_sysctlbyname_int32("hw.cputype", &tempInt32); + if (err == 0) { + this->ChipID.Family = tempInt32; + } + + err = kw_sysctlbyname_int32("hw.cpusubtype", &tempInt32); + if (err == 0) { + this->ChipID.Model = tempInt32; + } + + this->FindManufacturer(); + } else if (machineBuf.find_first_of("arm64") != std::string::npos) { + this->ChipID.Vendor = "Apple"; + + this->FindManufacturer(); + } + } + } else { + // Should be an Intel Chip. + err = kw_sysctlbyname_int32("machdep.cpu.family", &tempInt32); + if (err == 0) { + this->ChipID.Family = tempInt32; } - } else // Should be an Intel Chip. - { - len = sizeof(this->ChipID.Family); - err = sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len, - nullptr, 0); - ::memset(retBuf, 0, 128); - len = 128; - err = sysctlbyname("machdep.cpu.vendor", retBuf, &len, nullptr, 0); // Chip Vendor - this->ChipID.Vendor = retBuf; + ::memset(tempBuff, 0, sizeof(tempBuff)); + len = sizeof(tempBuff) - 1; // leave a byte for null termination + err = sysctlbyname("machdep.cpu.vendor", tempBuff, &len, nullptr, 0); + if (err == 0) { + this->ChipID.Vendor = tempBuff; + } this->FindManufacturer(); // Chip Model - len = sizeof(value); - err = sysctlbyname("machdep.cpu.model", &value, &len, nullptr, 0); - this->ChipID.Model = static_cast<int>(value); + err = kw_sysctlbyname_int32("machdep.cpu.model", &tempInt32); + if (err == 0) { + this->ChipID.Model = tempInt32; + } // Chip Stepping - len = sizeof(value); - value = 0; - err = sysctlbyname("machdep.cpu.stepping", &value, &len, nullptr, 0); - if (!err) { - this->ChipID.Revision = static_cast<int>(value); + err = kw_sysctlbyname_int32("machdep.cpu.stepping", &tempInt32); + if (err == 0) { + this->ChipID.Revision = tempInt32; } // feature string @@ -4632,36 +4686,36 @@ bool SystemInformationImplementation::ParseSysCtl() len = allocSize - 2; // keep space for leading and trailing space err = sysctlbyname("machdep.cpu.features", buf + 1, &len, nullptr, 0); } - if (!err && buf && len) { + if (err == 0 && buf && len) { // now we can match every flags as space + flag + space buf[len + 1] = ' '; std::string cpuflags(buf, len + 2); - if ((cpuflags.find(" FPU ") != std::string::npos)) { + if (cpuflags.find(" FPU ") != std::string::npos) { this->Features.HasFPU = true; } - if ((cpuflags.find(" TSC ") != std::string::npos)) { + if (cpuflags.find(" TSC ") != std::string::npos) { this->Features.HasTSC = true; } - if ((cpuflags.find(" MMX ") != std::string::npos)) { + if (cpuflags.find(" MMX ") != std::string::npos) { this->Features.HasMMX = true; } - if ((cpuflags.find(" SSE ") != std::string::npos)) { + if (cpuflags.find(" SSE ") != std::string::npos) { this->Features.HasSSE = true; } - if ((cpuflags.find(" SSE2 ") != std::string::npos)) { + if (cpuflags.find(" SSE2 ") != std::string::npos) { this->Features.HasSSE2 = true; } - if ((cpuflags.find(" APIC ") != std::string::npos)) { + if (cpuflags.find(" APIC ") != std::string::npos) { this->Features.HasAPIC = true; } - if ((cpuflags.find(" CMOV ") != std::string::npos)) { + if (cpuflags.find(" CMOV ") != std::string::npos) { this->Features.HasCMOV = true; } - if ((cpuflags.find(" MTRR ") != std::string::npos)) { + if (cpuflags.find(" MTRR ") != std::string::npos) { this->Features.HasMTRR = true; } - if ((cpuflags.find(" ACPI ") != std::string::npos)) { + if (cpuflags.find(" ACPI ") != std::string::npos) { this->Features.HasACPI = true; } } @@ -4669,21 +4723,29 @@ bool SystemInformationImplementation::ParseSysCtl() } // brand string - ::memset(retBuf, 0, sizeof(retBuf)); - len = sizeof(retBuf); - err = sysctlbyname("machdep.cpu.brand_string", retBuf, &len, nullptr, 0); - if (!err) { - this->ChipID.ProcessorName = retBuf; - this->ChipID.ModelName = retBuf; + this->ChipID.ProcessorName = ""; + this->ChipID.ModelName = ""; + ::memset(tempBuff, 0, sizeof(tempBuff)); + len = sizeof(tempBuff) - 1; // leave a byte for null termination + err = sysctlbyname("machdep.cpu.brand_string", tempBuff, &len, nullptr, 0); + if (err == 0) { + this->ChipID.ProcessorName = tempBuff; + this->ChipID.ModelName = tempBuff; } - // Cache size - len = sizeof(value); - err = sysctlbyname("hw.l1icachesize", &value, &len, nullptr, 0); - this->Features.L1CacheSize = static_cast<int>(value); - len = sizeof(value); - err = sysctlbyname("hw.l2cachesize", &value, &len, nullptr, 0); - this->Features.L2CacheSize = static_cast<int>(value); + // L1 Cache size + this->Features.L1CacheSize = 0; + err = kw_sysctlbyname_int64("hw.l1icachesize", &tempInt64); + if (err == 0) { + this->Features.L1CacheSize = static_cast<int>(tempInt64); + } + + // L2 Cache size + this->Features.L2CacheSize = 0; + err = kw_sysctlbyname_int64("hw.l2cachesize", &tempInt64); + if (err == 0) { + this->Features.L2CacheSize = static_cast<int>(tempInt64); + } return true; #else |