Improve CI cache usage (#6868)
* Update third-party actions to latest version * Use vcpkg in manifest mode * Only trim ccache after build * Use ccache with MSVC * Use Brewfile and cache Homebrew downloads * Use --print-config for ccache 3 * Attempt to make ccache actually work with MSVC * Zero ccache stats before building * Use SDL2 on macOS
This commit is contained in:
@@ -1,25 +1,40 @@
|
||||
option(USE_COMPILE_CACHE "Use ccache or clcache for compilation" OFF)
|
||||
option(USE_COMPILE_CACHE "Use a compiler cache for compilation" OFF)
|
||||
|
||||
# Compatibility for old option name
|
||||
if(USE_CCACHE)
|
||||
set(USE_COMPILE_CACHE ON)
|
||||
endif()
|
||||
|
||||
if(USE_COMPILE_CACHE)
|
||||
if(MSVC)
|
||||
set(CACHE_TOOL_NAME clcache)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|AppleClang|Clang)")
|
||||
set(CACHE_TOOL_NAME ccache)
|
||||
else()
|
||||
message(WARNING "Compile cache only available with MSVC or GNU")
|
||||
if(NOT USE_COMPILE_CACHE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "(GNU|AppleClang|Clang|MSVC)")
|
||||
message(WARNING "Compiler cache only available with MSVC or GNU")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(CACHE_TOOL_NAME ccache)
|
||||
find_program(CACHE_TOOL "${CACHE_TOOL_NAME}")
|
||||
if(NOT CACHE_TOOL)
|
||||
message(WARNING "USE_COMPILE_CACHE enabled, but no ${CACHE_TOOL_NAME} found")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
# ccache doesn't support debug information in the PDB format. Setting the
|
||||
# debug information format requires CMP0141, introduced with CMake 3.25, to
|
||||
# be set to NEW prior to the initial `project` command.
|
||||
if(CMAKE_VERSION VERSION_LESS "3.25")
|
||||
message(WARNING "Use of compiler cache with MSVC requires at least CMake 3.25")
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_program(CACHE_TOOL ${CACHE_TOOL_NAME})
|
||||
if (CACHE_TOOL)
|
||||
message(STATUS "Using ${CACHE_TOOL} found for caching")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CACHE_TOOL})
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CACHE_TOOL})
|
||||
else()
|
||||
message(WARNING "USE_COMPILE_CACHE enabled, but no ${CACHE_TOOL_NAME} found")
|
||||
endif()
|
||||
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")
|
||||
endif()
|
||||
|
||||
message(STATUS "Using ${CACHE_TOOL} for compiler caching")
|
||||
|
||||
# TODO CMake 3.21: Use CMAKE_<LANG>_<COMPILER|LINKER>_LAUNCHER variables instead
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CACHE_TOOL}")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CACHE_TOOL}")
|
||||
|
||||
Reference in New Issue
Block a user