aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorMike Taves <mwtoews@gmail.com>2021-11-25 11:21:09 +1300
committerMike Taves <mwtoews@gmail.com>2021-11-25 11:21:09 +1300
commit4889dcfa71505939966e119baa9449be189abaaf (patch)
treeb9bf676349011d4fd10612f9ce67f5eca82aa76d /cmake
parentdd74dd05a055cb882388862f8a3fe6e3ba4b194b (diff)
downloadPROJ-4889dcfa71505939966e119baa9449be189abaaf.tar.gz
PROJ-4889dcfa71505939966e119baa9449be189abaaf.zip
Also look for clcache for MSVC; only use wrappers for Xcode
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Ccache.cmake70
1 files changed, 26 insertions, 44 deletions
diff --git a/cmake/Ccache.cmake b/cmake/Ccache.cmake
index 09e81756..7bc59429 100644
--- a/cmake/Ccache.cmake
+++ b/cmake/Ccache.cmake
@@ -1,66 +1,48 @@
#
-# CMake module to support ccache
-#
-# see https://crascit.com/2016/04/09/using-ccache-with-cmake/
+# CMake module to support ccache (or clcache for MSVC)
#
+# Copyright (c) 2021, Mike Taves <mwtoews at gmail dot com>
+
+cmake_minimum_required(VERSION 3.4)
-find_program(CCACHE_PROGRAM ccache)
-# Note: REQUIRED keyword introduced in CMake 3.18
+find_program(CCACHE_PROGRAM NAMES ccache clcache)
if(CCACHE_PROGRAM)
message(STATUS "Configuring ccache with ${CCACHE_PROGRAM}")
- set(C_LAUNCHER "${CCACHE_PROGRAM}")
- set(CXX_LAUNCHER "${CCACHE_PROGRAM}")
-
- # Set up wrapper scripts
- set(CCACHE_LAUNCH_C ${CMAKE_BINARY_DIR}/ccache-launch-c)
- file(WRITE ${CCACHE_LAUNCH_C} "\
+ if(CMAKE_GENERATOR STREQUAL "Xcode")
+ # see https://crascit.com/2016/04/09/using-ccache-with-cmake/
+ set(C_LAUNCHER "${CCACHE_PROGRAM}")
+ set(CXX_LAUNCHER "${CCACHE_PROGRAM}")
+ set(CCACHE_LAUNCH_C ${CMAKE_BINARY_DIR}/ccache-c)
+ set(CCACHE_LAUNCH_CXX ${CMAKE_BINARY_DIR}/ccache-cxx)
+ file(WRITE "${CCACHE_LAUNCH_C}" "\
#!/bin/sh
-
-# Xcode generator doesn't include the compiler as the
-# first argument, Ninja and Makefiles do. Handle both cases.
-if [ \"$1\" = \"${CMAKE_C_COMPILER}\" ] ; then
- shift
-fi
-
-export CCACHE_CPP2=true
+shift
exec \"${C_LAUNCHER}\" \"${CMAKE_C_COMPILER}\" \"$@\"
")
-
- set(CCACHE_LAUNCH_CXX ${CMAKE_BINARY_DIR}/ccache-launch-cxx)
- file(WRITE ${CCACHE_LAUNCH_CXX} "\
+ file(WRITE "${CCACHE_LAUNCH_CXX}" "\
#!/bin/sh
-
-# Xcode generator doesn't include the compiler as the
-# first argument, Ninja and Makefiles do. Handle both cases.
-if [ \"$1\" = \"${CMAKE_CXX_COMPILER}\" ] ; then
- shift
-fi
-
-export CCACHE_CPP2=true
+shift
exec \"${CXX_LAUNCHER}\" \"${CMAKE_CXX_COMPILER}\" \"$@\"
")
-
- # Note: file(CHMOD) introduced in CMake 3.19
- execute_process(
- COMMAND chmod a+rx
- "${CCACHE_LAUNCH_C}"
- "${CCACHE_LAUNCH_CXX}"
- )
-
- if(CMAKE_GENERATOR STREQUAL "Xcode")
+ # Note: file(CHMOD) introduced in CMake 3.19
+ execute_process(
+ COMMAND chmod a+rx
+ "${CCACHE_LAUNCH_C}"
+ "${CCACHE_LAUNCH_CXX}"
+ )
# Set Xcode project attributes to route compilation and linking
- # through our scripts
+ # through the wrapper scripts
set(CMAKE_XCODE_ATTRIBUTE_CC "${CCACHE_LAUNCH_C}")
set(CMAKE_XCODE_ATTRIBUTE_CXX "${CCACHE_LAUNCH_CXX}")
set(CMAKE_XCODE_ATTRIBUTE_LD "${CCACHE_LAUNCH_C}")
set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CCACHE_LAUNCH_CXX}")
else()
- # Support Unix Makefiles and Ninja
- set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_LAUNCH_C}")
- set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_LAUNCH_CXX}")
+ # Most other generators (Unix Makefiles, Ninja, etc.)
+ set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
+ set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
else()
- message(SEND_ERROR "Ccache requested, but ccache was not found")
+ message(WARNING "Ccache was requested, but no program was not found")
endif()