From: Joel Rosdahl Date: Sat, 30 Jan 2021 18:17:33 +0000 (+0100) Subject: Improve speed of compiler launcher command in UseCcache.cmake X-Git-Tag: v4.2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=68d8481c;p=thirdparty%2Fccache.git Improve speed of compiler launcher command in UseCcache.cmake 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. --- 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)