1

ccache does not support some compiler options (e.g. --coverage). If there is an unsupported compiler options it compiles but the cache is not used.

There are more than one ways how to enable ccache (modifying PATH, using CC/CXX environment variables).

I would like to detect if the compiler uses ccache and if yes disable the unsupported compiler options.

The best i have come up with is something like this:

CC = $(shell which $(CC))
ifeq (,$(findstring ccache,$(CC)))

Any ideas how to improve this?

arved
  • 4,401
  • 4
  • 30
  • 53

2 Answers2

3

This might be a more elegant solution:

ifeq ($(shell readlink -f `which $(CC)`),$(shell which ccache))
    echo "Using ccache"
else
    echo "Not using ccache"
endif
smani
  • 1,953
  • 17
  • 13
1

Smani's solution may not work, depending on how ccache in configured (e.g. in RedHat Linux's ccache 3.3.4, t the compiler symlinks in /usr/lib64/ccache/ point to /usr/bin/ccache but which ccache returns /bin/ccache).

This solution doesn't care where ccache is located and even works if ccache is used as a prefix:

ifeq ($(shell $(CC) -xc -c - --ccache-skip </dev/null 2>&1),)
    echo "Using ccache"
else
    echo "Not using ccache"
endif

This works by compiling an empty file and checking whether the compiler knows about the ccache --ccache-skip flag.

Note that once you know ccache is enabled, instead of omitting the --coverage flag, you could preface it with --ccache-skip.

Note also that even if ccache is in the path, it may be disabled by the CCACHE_DISABLE environment variable or by the ccache.conf file.

D Adler
  • 41
  • 4