Skip to content

Commit

Permalink
CMake: Add support for clcache
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-w committed Jun 17, 2018
1 parent 7f31421 commit 8fba32e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ environment:
- compiler: msvc
install:
- vcpkg install --triplet %PLATFORM%-windows fftw3 libsamplerate libsndfile sdl2
- nuget install clcache -Version 4.1.0
build_script:
- cd %APPVEYOR_BUILD_FOLDER%
- mkdir build
- cd build
- ps: $env:CMAKE_PLATFORM="$(if ($env:PLATFORM -eq 'x64') { 'x64' } else { '' })"
- ps: $env:QT_SUFFIX="$(if ($env:PLATFORM -eq 'x64') { '_64' } else { '' })"
- cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=c:/Qt/5.9.5/msvc2015%QT_SUFFIX%;c:/tools/vcpkg/installed/%PLATFORM%-windows -DCMAKE_GENERATOR_PLATFORM="%CMAKE_PLATFORM%" ..
- cmake -DUSE_COMPILE_CACHE=ON -DCACHE_TOOL=%APPVEYOR_BUILD_FOLDER%/clcache.4.1.0/clcache-4.1.0/clcache.exe -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=c:/Qt/5.9.5/msvc2015%QT_SUFFIX%;c:/tools/vcpkg/installed/%PLATFORM%-windows -DCMAKE_GENERATOR_PLATFORM="%CMAKE_PLATFORM%" ..
- cmake --build . -- /maxcpucount:4
- cmake --build . --target tests
cache:
Expand Down
12 changes: 1 addition & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -546,17 +546,7 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
ENDIF()

# use ccache
OPTION(USE_CCACHE "Use ccache for compilation" OFF)
IF(USE_CCACHE)
FIND_PROGRAM(CCACHE ccache)
IF (CCACHE)
MESSAGE(STATUS "Using ccache found in PATH")
SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
ELSE()
MESSAGE(WARNING "USE_CCACHE enabled, but no ccache found")
ENDIF()
ENDIF()
include(CompileCache)

# make sub-directories
ADD_SUBDIRECTORY(cmake)
Expand Down
25 changes: 25 additions & 0 deletions cmake/modules/CompileCache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
option(USE_COMPILE_CACHE "Use ccache or clcache 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")
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()
endif()

0 comments on commit 8fba32e

Please sign in to comment.