Skip to content

Commit

Permalink
cmake: workaround _num_cores being 0 under qemu emulation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tserong committed Nov 23, 2023
1 parent 9dcbde6 commit b666926
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmake/modules/LimitJobs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit b666926

Please sign in to comment.