]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Improve speed of compiler launcher command in UseCcache.cmake
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 30 Jan 2021 18:17:33 +0000 (19:17 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 1 Feb 2021 19:16:22 +0000 (20:16 +0100)
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

index 248635f7134f075999c808ca606d52a507a5e1b9..ac2c640d024b06d3a95f23ec1e5a7448648563f1 100644 (file)
@@ -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)