From 68d8481c173eb711624232c8f9c8e4507d747dc9 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 30 Jan 2021 19:17:33 +0100 Subject: [PATCH] Improve speed of compiler launcher command in UseCcache.cmake MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit I noticed that the overhead of “cmake -E env” is around 9 ms on my system. This means that ccache direct mode hits on average have become twice as slow when building ccache itself on my system. Improve this by using the standard “env” program if available. Its overhead is around 1 ms. --- cmake/UseCcache.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmake/UseCcache.cmake b/cmake/UseCcache.cmake index 248635f71..ac2c640d0 100644 --- a/cmake/UseCcache.cmake +++ b/cmake/UseCcache.cmake @@ -39,9 +39,15 @@ function(use_ccache) ) if(CMAKE_GENERATOR MATCHES "Ninja|Makefiles") + find_program(ENV_PROGRAM env) + if(ENV_PROGRAM) + set(env_program env) # faster than "cmake -E env" + else() + set(env_program ${CMAKE_COMMAND} -E env) + endif() foreach(lang IN ITEMS C CXX OBJC OBJCXX CUDA) set(CMAKE_${lang}_COMPILER_LAUNCHER - ${CMAKE_COMMAND} -E env ${ccache_env} ${CCACHE_PROGRAM} + ${env_program} ${ccache_env} ${CCACHE_PROGRAM} PARENT_SCOPE) endforeach() elseif(CMAKE_GENERATOR STREQUAL Xcode) -- 2.47.3