From f91413db8f27043ce89a62d5fd5fdad87ba57be5 Mon Sep 17 00:00:00 2001 From: Neui Date: Sat, 8 Jun 2024 16:05:14 +0200 Subject: [PATCH 1/2] CMake: Fix CCache support when already using _LAUNCHER The official ccache documentation[1] recommends to set `CMAKE_C(XX)_COMPILER_LAUNCHER` to ccache to enable ccache. These also work as envionment variables (supported by CMake itself). However, using these instructions generates the following error during building: ccache: error: Recursive invocation (the name of the ccache binary must be "ccache") This is because Dolphin adds an additional command ccache layer (ccache ccache compiler ...). This fixes that issue by checking for `CMAKE_C(XX)_COMPILER_LAUNCHER` before inserting our own. Also, use `CMAKE_C(XX)_COMPILER_LAUNCHER` to add ccache because the CMake docs discourages the use of `RULE_LAUNCH_COMPILE` in favour of `CMAKE_C(XX)_COMPILER_LAUNCHER`. [1]: https://github.com/ccache/ccache/wiki/CMake --- CMake/CCache.cmake | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/CMake/CCache.cmake b/CMake/CCache.cmake index 775256cd3b..5cd4c9c478 100644 --- a/CMake/CCache.cmake +++ b/CMake/CCache.cmake @@ -1,10 +1,19 @@ find_program(CCACHE_BIN NAMES ccache sccache) if(CCACHE_BIN) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_BIN}) + # Official ccache recommendation is to set CMAKE_C(XX)_COMPILER_LAUNCHER + if (NOT CMAKE_C_COMPILER_LAUNCHER MATCHES "ccache") + list(INSERT CMAKE_C_COMPILER_LAUNCHER 0 "${CCACHE_BIN}") + # ccache uses -I when compiling without preprocessor, which makes clang complain. + if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics") + endif() + endif() - # ccache uses -I when compiling without preprocessor, which makes clang complain. - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics") + if (NOT CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache") + list(INSERT CMAKE_CXX_COMPILER_LAUNCHER 0 "${CCACHE_BIN}") + # ccache uses -I when compiling without preprocessor, which makes clang complain. + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics") + endif() endif() endif() From a1c54063d0d8271a316915b73f839e82cafef5ed Mon Sep 17 00:00:00 2001 From: Neui Date: Mon, 10 Jun 2024 23:41:49 +0200 Subject: [PATCH 2/2] CMake: CCache: Always make clang happy When we are using ccache anyway, always add the flags to make clang happy. Also, fix copy-paste error regarding what variable to modify for it. --- CMake/CCache.cmake | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/CMake/CCache.cmake b/CMake/CCache.cmake index 5cd4c9c478..a8ee5da473 100644 --- a/CMake/CCache.cmake +++ b/CMake/CCache.cmake @@ -3,17 +3,15 @@ if(CCACHE_BIN) # Official ccache recommendation is to set CMAKE_C(XX)_COMPILER_LAUNCHER if (NOT CMAKE_C_COMPILER_LAUNCHER MATCHES "ccache") list(INSERT CMAKE_C_COMPILER_LAUNCHER 0 "${CCACHE_BIN}") - # ccache uses -I when compiling without preprocessor, which makes clang complain. - if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics") - endif() endif() if (NOT CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache") list(INSERT CMAKE_CXX_COMPILER_LAUNCHER 0 "${CCACHE_BIN}") - # ccache uses -I when compiling without preprocessor, which makes clang complain. - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics") - endif() + endif() + + # ccache uses -I when compiling without preprocessor, which makes clang complain. + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") endif() endif()