option(WITH_SCCACHE "Build with sccache.")
if(WITH_SCCACHE)
- if(CMAKE_C_COMPILER_LAUNCHER OR CMAKE_CXX_COMPILER_LAUNCHER)
- message(WARNING "Compiler launcher already set. stop configuring sccache")
- else()
- find_program(SCCACHE_EXECUTABLE sccache)
- if(NOT SCCACHE_EXECUTABLE)
- message(FATAL_ERROR "Can't find sccache. Is it installed?")
+ find_program(SCCACHE_EXECUTABLE sccache)
+ if(NOT SCCACHE_EXECUTABLE)
+ message(FATAL_ERROR "Can't find sccache. Is it installed?")
+ endif()
+ if(NOT NINJA_MAX_COMPILE_JOBS)
+ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
+ execute_process(
+ COMMAND "sccache" "--dist-status"
+ OUTPUT_VARIABLE sccache_dist_status
+ )
+ string(
+ JSON sccache_cores
+ ERROR_VARIABLE sccache_dist_status_error
+ GET "${sccache_dist_status}" SchedulerStatus 1 num_cpus
+ )
+ string(FIND "${sccache_dist_status}" "disabled" find_result)
+ if(find_result EQUAL -1)
+ message(STATUS "Using sccache with distributed compilation. Effective cores: ${sccache_cores}")
+ set(NINJA_MAX_COMPILE_JOBS ${sccache_cores})
+ set(NINJA_MAX_LINK_JOBS ${sccache_cores})
+ else()
+ message(WARNING "Using sccache, but it is not configured for distributed complilation")
+ endif()
+ else()
+ message(WARNING "Using sccache, but cannot determine maximum job value since cmake version is <3.19")
endif()
- message(STATUS "Building with sccache: ${SCCACHE_EXECUTABLE}, SCCACHE_CONF=$ENV{SCCACHE_CONF}")
- set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_EXECUTABLE})
- set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_EXECUTABLE})
endif()
+ message(STATUS "Building with sccache: ${SCCACHE_EXECUTABLE}, SCCACHE_CONF=$ENV{SCCACHE_CONF}")
+ set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_EXECUTABLE})
+ set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_EXECUTABLE})
endif(WITH_SCCACHE)
option(WITH_MANPAGE "Build man pages." ON)
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})
+if(NINJA_MAX_COMPILE_JOBS)
+ set(_avg_compile_jobs "${NINJA_MAX_COMPILE_JOBS}")
+else()
+ 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)
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(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})
+if(NINJA_MAX_LINK_JOBS)
+ set(_avg_link_jobs "${NINJA_MAX_LINK_JOBS}")
+else()
+ 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)
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)