From bd751d40893e11ed2abc9a1553d48569f434319b Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Fri, 5 Jun 2020 14:35:29 +0200
Subject: [PATCH] [CMake] Added clcache (win) integration.

Install clcache with:

pip install git+https://github.com/frerich/clcache.git@cae73d8255d78db8ba11e23c51fd2c9a89e7475b
---
 CMakeLists.txt                   | 7 ++++++-
 Jenkinsfile                      | 2 --
 scripts/cmake/CCacheSetup.cmake  | 2 +-
 scripts/cmake/CLCacheSetup.cmake | 6 ++++++
 scripts/cmake/Find.cmake         | 6 +++++-
 5 files changed, 18 insertions(+), 5 deletions(-)
 create mode 100644 scripts/cmake/CLCacheSetup.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a35067acd7b..70a16867236 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,7 +26,11 @@ option(OGS_ENABLE_AVX2 "Enable the use of AVX2 instructions" OFF)
 option(OGS_USE_CONAN "Should Conan package manager be used?" ON)
 set(OGS_CONAN_BUILD "missing" CACHE STRING "Possible values: all, missing, \
     never or list of libs to build")
-option(OGS_DISABLE_CCACHE "Disables ccache compiler cache." OFF)
+if(WIN32)
+    option(OGS_DISABLE_CLCACHE "Disables clcache compiler cache." OFF)
+else()
+    option(OGS_DISABLE_CCACHE "Disables ccache compiler cache." OFF)
+endif()
 if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16)
     option(OGS_USE_UNITY_BUILDS "Enables Unity builds for faster compilation." ON)
 endif()
@@ -69,6 +73,7 @@ include(ConanSetup)
 include(CompilerSetup)
 include(Find)
 include(CCacheSetup)
+include(CLCacheSetup)
 include(DocumentationSetup)
 include(test/Test)
 if(OGS_COVERAGE AND NOT IS_SUBPROJECT)
diff --git a/Jenkinsfile b/Jenkinsfile
index e2f27244ec3..a15a03b92b8 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -412,8 +412,6 @@ pipeline {
             MSVC_NUMBER = '16'
             MSVC_VERSION = '2019'
             OMP_NUM_THREADS = '1'
-            CC = 'clcache'
-            CXX = 'clcache'
           }
           steps {
             script {
diff --git a/scripts/cmake/CCacheSetup.cmake b/scripts/cmake/CCacheSetup.cmake
index e00f95edbcc..147ba5a6aec 100644
--- a/scripts/cmake/CCacheSetup.cmake
+++ b/scripts/cmake/CCacheSetup.cmake
@@ -1,4 +1,4 @@
-if(NOT CCACHE_TOOL_PATH OR OGS_DISABLE_CCACHE)
+if(WIN32 OR NOT CCACHE_TOOL_PATH OR OGS_DISABLE_CCACHE)
     return()
 endif()
 
diff --git a/scripts/cmake/CLCacheSetup.cmake b/scripts/cmake/CLCacheSetup.cmake
new file mode 100644
index 00000000000..ccdc39ee5b8
--- /dev/null
+++ b/scripts/cmake/CLCacheSetup.cmake
@@ -0,0 +1,6 @@
+if(NOT WIN32 OR NOT CLCACHE_TOOL_PATH OR OGS_DISABLE_CLCACHE)
+    return()
+endif()
+
+set(CMAKE_C_COMPILER_LAUNCHER ${CLCACHE_TOOL_PATH})
+set(CMAKE_CXX_COMPILER_LAUNCHER ${CLCACHE_TOOL_PATH})
diff --git a/scripts/cmake/Find.cmake b/scripts/cmake/Find.cmake
index 782d27b9ff9..e893c4b17c6 100644
--- a/scripts/cmake/Find.cmake
+++ b/scripts/cmake/Find.cmake
@@ -36,7 +36,11 @@ find_program(CURL_TOOL_PATH curl DOC "The curl-tool")
 
 find_program(S3CMD_TOOL_PATH s3cmd DOC "S3cmd tool for uploading to Amazon S3")
 
-find_program(CCACHE_TOOL_PATH ccache)
+if(WIN32)
+    find_program(CLCACHE_TOOL_PATH clcache)
+else()
+    find_program(CCACHE_TOOL_PATH ccache)
+endif()
 
 # Tools for web
 find_program(VTKJS_CONVERTER vtkDataConverter
-- 
GitLab