Skip to content

Commit

Permalink
Add Halide_CCACHE_BUILD option for CMake (#5804)
Browse files Browse the repository at this point in the history
* Add Halide_CCACHE_BUILD option for CMake

This replicates the approach LLVM already has of baking a use-cache option directly into the CMake options, without having to futz with changing CC/CXX/etc.

* Update CMakeLists.txt

* Add CCACHE_SLOPPINESS=pch_defines,time_macros

* Update CMakeLists.txt
  • Loading branch information
steven-johnson committed Mar 16, 2021
1 parent b061a32 commit 5aa1a65
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Build Halide with ccache if the package is present
option(Halide_CCACHE_BUILD "Set to ON for a ccache enabled build" OFF)
if (Halide_CCACHE_BUILD)
find_program(CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM)
# TODO: ccache recommends setting CCACHE_SLOPPINESS=pch_defines,time_macros to
# enable precompiled header caching. Our timing found it slightly faster with
# just CCACHE_SLOPPINESS=pch_defines, so that's what we're using. Maybe revisit
# if issues occur (but we don't use any of the time macros so should be irrelevant).
set(Halide_CCACHE_PARAMS CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines
CACHE STRING "Parameters to pass through to ccache")
set(CMAKE_C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env ${Halide_CCACHE_PARAMS} ${CCACHE_PROGRAM})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env ${Halide_CCACHE_PARAMS} ${CCACHE_PROGRAM})
message(STATUS "Enabling ccache usage for building.")
else ()
message(FATAL_ERROR "Unable to find the program ccache. Set Halide_CCACHE_BUILD to OFF")
endif ()
endif ()

##
# Import dependencies
##
Expand Down
1 change: 1 addition & 0 deletions README_cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ compiled.
| `Halide_ENABLE_EXCEPTIONS` | `ON` | Enable exceptions when building Halide |
| `Halide_USE_CODEMODEL_LARGE` | `OFF` | Use the Large LLVM codemodel |
| `Halide_TARGET` | _empty_ | The default target triple to use for `add_halide_library` (and the generator tests, by extension) |
| `Halide_CCACHE_BUILD` | `OFF` | Use ccache to accelerate rebuilds. |

The following options are only available when building Halide directly, ie. not
through the [`add_subdirectory`][add_subdirectory] or
Expand Down

0 comments on commit 5aa1a65

Please sign in to comment.