Skip to content

Commit

Permalink
Add support for ccache
Browse files Browse the repository at this point in the history
For CMake builds, it now checks if ccache is available on the system,
and enables it if found.
This isn't a big project, but it still provides a nice speed boost for
rebuilds, especially when switching between release and debug.

The way I have it structured is not optimal, I don't use a build
directory for the different build types, and instead just rebuild the
whole thing from scratch.
Should probably fix it somehow, I'm just so used to how it is now :D
  • Loading branch information
vkoskiv committed Nov 4, 2023
1 parent 044176f commit 8c40781
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${c-ray_SOURCE_DIR}/cmake")
file(GLOB_RECURSE SOURCES src/*.c)

include(set_up_ccache)

include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
configure_file("${c-ray_SOURCE_DIR}/src/utils/gitsha1.c.in" "${c-ray_BINARY_DIR}/generated/gitsha1.c" @ONLY)
Expand Down
9 changes: 9 additions & 0 deletions cmake/set_up_ccache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
find_program(CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM)
get_filename_component(compiler_path "${CMAKE_C_COMPILER}" REALPATH)
get_filename_component(compiler_name "${compiler_path}" NAME)
if (NOT ${compiler_name} MATCHES "ccache")
message(STATUS "Enabling ccache")
set("CMAKE_C_COMPILER_LAUNCHER" "${CCACHE_PROGRAM}" CACHE FILEPATH "Path to a compiler launcher, usually ccache")
endif()
endif()

0 comments on commit 8c40781

Please sign in to comment.