Fix ccache support
authorDan Church <amphetamachine@gmail.com>
Wed, 21 Mar 2018 16:57:36 +0000 (11:57 -0500)
committerDan Church <amphetamachine@gmail.com>
Wed, 21 Mar 2018 21:30:34 +0000 (16:30 -0500)
Setting the compiler launcher to "ccache" is the recommended way of
enabling ccache for the build.

If cmake is run with it defined, it causes an error when ccache tries to
run:

    ccache: error: Recursive invocation (the name of the ccache binary must be "ccache")

This was because the compiler was getting invoked as
"ccache ccache [COMPILER]"

CMakeLists.txt

index c076160..2d9d338 100644 (file)
@@ -125,8 +125,17 @@ endif(CMAKE_CROSSCOMPILING)
 
 find_program(CCACHE ccache)
 if(CCACHE AND WITH_CCACHE)
-       set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
-       set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
+       if(CMAKE_VERSION VERSION_GREATER 3.3.2)
+               if(NOT DEFINED CMAKE_C_COMPILER_LAUNCHER)
+                       SET(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
+               endif(NOT DEFINED CMAKE_C_COMPILER_LAUNCHER)
+               if(NOT DEFINED CMAKE_CXX_COMPILER_LAUNCHER)
+                       SET(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
+               endif(NOT DEFINED CMAKE_CXX_COMPILER_LAUNCHER)
+       else()
+               set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
+               set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
+       endif()
 endif(CCACHE AND WITH_CCACHE)
 
 if(EXISTS "${CMAKE_SOURCE_DIR}/.source_version" )