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.
)
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)