cmake: Use job pool feature to limit concurrent jobs

Add two new options, WOWNERO_PARALLEL_COMPILE_JOBS and
WOWNERO_PARALLEL_LINK_JOBS to try and prevent running out of memory when
building everything.

Requires >= cmake 3.0.0, and the use of the Ninja generator.

Useful links:

* https://cmake.org/cmake/help/latest/prop_gbl/JOB_POOLS.html
* https://reviews.llvm.org/D6304
This commit is contained in:
Matt Smith 2020-08-05 18:39:44 +01:00 committed by wowario
parent b9974f7bff
commit 96ae690083
No known key found for this signature in database
GPG Key ID: 24DCBE762DE9C111
1 changed files with 15 additions and 0 deletions

View File

@ -55,6 +55,21 @@ else()
message(STATUS "ccache deselected")
endif()
# Job pool feature requires Ninja.
if (${CMAKE_VERSION} VERSION_GREATER "3.0.0")
set(WOWNERO_PARALLEL_COMPILE_JOBS "" CACHE STRING "The maximum number of concurrent compilation jobs.")
if (WOWNERO_PARALLEL_COMPILE_JOBS)
set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${WOWNERO_PARALLEL_COMPILE_JOBS})
set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
endif ()
set(WOWNERO_PARALLEL_LINK_JOBS "" CACHE STRING "The maximum number of concurrent link jobs.")
if (WOWNERO_PARALLEL_LINK_JOBS)
set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${WOWNERO_PARALLEL_LINK_JOBS})
set(CMAKE_JOB_POOL_LINK link_job_pool)
endif ()
endif()
enable_language(C ASM)
function (die msg)