From 036d5cce406ee0112ec109181ce58221a4cb06e8 Mon Sep 17 00:00:00 2001
From: Eidolon <furyhunter600@gmail.com>
Date: Sat, 5 Nov 2022 19:26:01 -0500
Subject: [PATCH] cmake: Use TheLartians' Ccache script on non-Win32

Improves ccache support for Xcode
---
 CMakeLists.txt      | 28 +++++++++++++++++++---------
 cmake/launch-c.in   |  3 ---
 cmake/launch-cxx.in |  3 ---
 3 files changed, 19 insertions(+), 15 deletions(-)
 delete mode 100644 cmake/launch-c.in
 delete mode 100644 cmake/launch-cxx.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f5364bc885..c70c9f767e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,16 +64,26 @@ cmake_dependent_option(
 option(SRB2_CONFIG_HWRENDER "Enable hardware render (OpenGL) support" ON)
 option(SRB2_CONFIG_STATIC_OPENGL "Enable static linking GL (do not do this)" OFF)
 
-# Enable CCache early
-set(SRB2_USE_CCACHE OFF CACHE BOOL "Use CCache")
-if (${SRB2_USE_CCACHE})
-	find_program(CCACHE_PROGRAM ccache)
-	if(CCACHE_PROGRAM)
-		message(STATUS "Found CCache: ${CCACHE_PROGRAM}")
-		set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
-	else()
-		message(WARNING "You have specified to use CCACHE but it was not found. Object files will not be cached.")
+# Enable CCache
+# (Set USE_CCACHE=ON to use, CCACHE_OPTIONS for options)
+if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL Windows)
+	option(USE_CCACHE "Enable ccache support" OFF)
+
+	if(USE_CCACHE)
+		find_program(CCACHE_TOOL_PATH ccache)
+		if(CCACHE_TOOL_PATH)
+			set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE)
+			set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE)
+		else()
+			message(WARNING "USE_CCACHE was set but ccache is not found (set CCACHE_TOOL_PATH)")
+		endif()
 	endif()
+else()
+	CPMAddPackage(
+		NAME Ccache.cmake
+		GITHUB_REPOSITORY TheLartians/Ccache.cmake
+		VERSION 1.2
+	)
 endif()
 
 # Dependencies
diff --git a/cmake/launch-c.in b/cmake/launch-c.in
deleted file mode 100644
index c605582326..0000000000
--- a/cmake/launch-c.in
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-export CCACHE_CPP2=true
-exec "${RULE_LAUNCH_COMPILE}" "${CMAKE_C_COMPILER}" "$@"
diff --git a/cmake/launch-cxx.in b/cmake/launch-cxx.in
deleted file mode 100644
index c605582326..0000000000
--- a/cmake/launch-cxx.in
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-export CCACHE_CPP2=true
-exec "${RULE_LAUNCH_COMPILE}" "${CMAKE_C_COMPILER}" "$@"
-- 
GitLab