From b6669263cacd56ff589529784066b9f637f79e87 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Thu, 23 Nov 2023 15:59:10 +1100 Subject: [PATCH] cmake: workaround _num_cores being 0 under qemu emulation If you're doing something weird like trying to cross compile bits of ceph using qemu emulation, cmake can think there are zero CPU cores. This is because cmake counts "processor" lines in /proc/cpuinfo, which don't exist when running under qemu-aarch64: # cat /proc/cpuinfo Processor : ARMv7 Processor rev 5 (v7l) BogoMIPS : 799.53 Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3 CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x2 CPU part : 0xc08 CPU revision : 5 Hardware : Genesi Efika MX (Smarttop) Revision : 51030 Serial : 0000000000000000 This in turn causes heavy_compile_job_pool to not be set, which later makes the build fail, as that pool is referenced in src/tools/ceph-dencoder/CMakeLists.txt. We can work around the problem by setting _num_cores to 1 in this case. Signed-off-by: Tim Serong --- cmake/modules/LimitJobs.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/modules/LimitJobs.cmake b/cmake/modules/LimitJobs.cmake index 591a9321b668d..41dd3e509cae4 100644 --- a/cmake/modules/LimitJobs.cmake +++ b/cmake/modules/LimitJobs.cmake @@ -2,6 +2,11 @@ set(MAX_COMPILE_MEM 3500 CACHE INTERNAL "maximum memory used by each compiling j set(MAX_LINK_MEM 4500 CACHE INTERNAL "maximum memory used by each linking job (in MiB)") cmake_host_system_information(RESULT _num_cores QUERY NUMBER_OF_LOGICAL_CORES) +# This will never be zero on a real system, but it can be if you're doing +# weird things like trying to cross-compile using qemu emulation. +if(_num_cores EQUAL 0) + set(_num_cores 1) +endif() cmake_host_system_information(RESULT _total_mem QUERY TOTAL_PHYSICAL_MEMORY) math(EXPR _avg_compile_jobs "${_total_mem} / ${MAX_COMPILE_MEM}")