summaryrefslogtreecommitdiffstats
path: root/cmake/modules
diff options
context:
space:
mode:
authorKefu Chai <kchai@redhat.com>2021-04-14 09:06:50 +0200
committerGitHub <noreply@github.com>2021-04-14 09:06:50 +0200
commite09f8d7dd027735ecc015f0497a1668e6cbcf1d2 (patch)
tree0c4347e123f701fe7bacdffe92d4cdcc8f8dc0ff /cmake/modules
parentMerge pull request #40785 from tchaikov/wip-doc-list-spacing (diff)
parentcmake: use ninja job pool (diff)
downloadceph-e09f8d7dd027735ecc015f0497a1668e6cbcf1d2.tar.xz
ceph-e09f8d7dd027735ecc015f0497a1668e6cbcf1d2.zip
Merge pull request #40149 from tchaikov/wip-cmake-job-pool
cmake: use ninja job pool Reviewed-by: Patrick Donnelly <pdonnell@redhat.com>
Diffstat (limited to 'cmake/modules')
-rw-r--r--cmake/modules/LimitJobs.cmake47
1 files changed, 47 insertions, 0 deletions
diff --git a/cmake/modules/LimitJobs.cmake b/cmake/modules/LimitJobs.cmake
new file mode 100644
index 00000000000..7d411026f36
--- /dev/null
+++ b/cmake/modules/LimitJobs.cmake
@@ -0,0 +1,47 @@
+set(MAX_COMPILE_MEM 2500 CACHE INTERNAL "maximum memory used by each compiling job (in MiB)")
+set(MAX_LINK_MEM 3300 CACHE INTERNAL "maximum memory used by each linking job (in MiB)")
+
+cmake_host_system_information(RESULT _num_cores QUERY NUMBER_OF_LOGICAL_CORES)
+cmake_host_system_information(RESULT _total_mem QUERY TOTAL_PHYSICAL_MEMORY)
+
+math(EXPR _avg_compile_jobs "${_total_mem} / ${MAX_COMPILE_MEM}")
+if(_avg_compile_jobs EQUAL 0)
+ set(_avg_compile_jobs 1)
+endif()
+if(_num_cores LESS _avg_compile_jobs)
+ set(_avg_compile_jobs ${_num_cores})
+endif()
+set(NINJA_MAX_COMPILE_JOBS "${_avg_compile_jobs}" CACHE STRING
+ "The maximum number of concurrent compilation jobs, for Ninja build system." FORCE)
+mark_as_advanced(NINJA_MAX_COMPILE_JOBS)
+if(NINJA_MAX_COMPILE_JOBS)
+ math(EXPR _heavy_compile_jobs "${_avg_compile_jobs} / 2")
+ if(_heavy_compile_jobs EQUAL 0)
+ set(_heavy_compile_jobs 1)
+ endif()
+ set_property(GLOBAL APPEND PROPERTY JOB_POOLS
+ avg_compile_job_pool=${NINJA_MAX_COMPILE_JOBS}
+ heavy_compile_job_pool=${_heavy_compile_jobs})
+ set(CMAKE_JOB_POOL_COMPILE avg_compile_job_pool)
+endif()
+
+math(EXPR _avg_link_jobs "${_total_mem} / ${MAX_LINK_MEM}")
+if(_avg_link_jobs EQUAL 0)
+ set(_avg_link_jobs 1)
+endif()
+if(_num_cores LESS _avg_link_jobs)
+ set(_avg_link_jobs ${_num_cores})
+endif()
+set(NINJA_MAX_LINK_JOBS "${_avg_link_jobs}" CACHE STRING
+ "The maximum number of concurrent link jobs, for Ninja build system." FORCE)
+mark_as_advanced(NINJA_MAX_LINK_JOBS)
+if(NINJA_MAX_LINK_JOBS)
+ math(EXPR _heavy_link_jobs "${_avg_link_jobs} / 2")
+ if(_heavy_link_jobs EQUAL 0)
+ set(_heavy_link_jobs 1)
+ endif()
+ set_property(GLOBAL APPEND PROPERTY JOB_POOLS
+ avg_link_job_pool=${NINJA_MAX_LINK_JOBS}
+ heavy_link_job_pool=${_heavy_link_jobs})
+ set(CMAKE_JOB_POOL_LINK avg_link_job_pool)
+endif()