<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le lun. 18 févr. 2019 à 00:01, Craig Scott <<a href="mailto:craig.scott@crascit.com">craig.scott@crascit.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 18, 2019 at 9:35 AM Domen Vrankar <<a href="mailto:domen.vrankar@gmail.com" target="_blank">domen.vrankar@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>I'm building llvm project with CMake.</div><div>While build process is compiling the code I prefer running "make -j3" on my 4 core pc (bumping processor to 100% on 3 of 4 cores and using up ~5 GB of ram - part of it is system and not build related).</div><div>While build process is linking I must run "make" with a single job because otherwise I run out of memory (cores do little work but ram usage goes past 23 GB).</div><div><br></div><div>Currently I'm handling this so that I first run "make -j3" and once I get to about 90% (first larger linking) I hit ctrl+c and run "make".</div><div><br></div><div>Is there a feature in CMake that would support handling this transition of parallel builds, sequential linking out of the box?</div><div>(while I'm mostly interested in Linux/make support, having the same feature for Windows/nmake/ninja through the same command line cmake command would be even better) </div></div></blockquote></div><div><br></div><div>This is available for Ninja with the <a href="https://cmake.org/cmake/help/latest/prop_tgt/JOB_POOL_LINK.html" target="_blank">JOB_POOL_LINK</a> target property, the default for which can be set project-wide with the <a href="https://cmake.org/cmake/help/latest/variable/CMAKE_JOB_POOL_LINK.html" target="_blank">CMAKE_JOB_POOL_LINK</a> variable. You can control the number of parallel jobs for a given pool with the <a href="https://cmake.org/cmake/help/latest/prop_gbl/JOB_POOLS.html" target="_blank">JOB_POOLS</a> global property.</div></div></div></div></blockquote><div><br></div><div>I use that a lot and I shall add that, on my side, link jobs memory consumption heavily depends on the type of build (debug, release, profiling, etc...), moreover </div><div>the available memory amount vary a lot as well whether if the build occurs on a "local" developer desktop or on some CI runner.</div><div>So we end up doing some very basic CMake computation in order to automatically adapt to the local resource.</div><div>Nothing fancy but it has been proven very useful for us:</div><div><br></div><div>if (CMAKE_BUILD_TYPE STREQUAL "Debug")<br></div><div>   cmake_host_system_information(RESULT MYMEM QUERY TOTAL_PHYSICAL_MEMORY)</div><div>   # Compute the number of authorized number of link jobs by:<br></div><div>   #   - "saving" 4 GiB of memory</div><div>   #   - assume each debug link job may consume 2GiB</div><div>   math(EXPR NLJ "(${MYMEM}-4096)/2048")</div><div><div>   set_property(GLOBAL PROPERTY JOB_POOLS link_jobs=${NLJ})</div><div>   set(CMAKE_JOB_POOL_LINK link_jobs)</div></div><div>elseif (CMAKE_BUILD_TYPE STREQUAL "Release")</div><div>...</div><div>endif()</div><div><br></div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Eric<br></div></div></div></div></div></div></div></div></div></div>