diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f772b634..1ddd6772f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,11 @@ jobs: - uses: actions/checkout@v2 with: submodules: 'recursive' + - name: ccache + uses: hendrikmuhs/ccache-action@v1 + if: runner.os == 'Linux' + with: + key: ${{ matrix.os }}-${{ matrix.enable_ui }} - uses: seanmiddleditch/gha-setup-ninja@master - uses: ilammy/msvc-dev-cmd@v1 if: runner.os == 'Windows' diff --git a/CMakeLists.txt b/CMakeLists.txt index 45aa52cb5..a73a98b6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ option(ENABLE_DEVMODE "Compile vesion for developers" off) option(ENABLE_UI "Compile UI (turn off to compile CLI-only version)" on) option(FULLSCREEN_PLATFORM "Enable fullscreen by default" off) option(ENABLE_CLANG_TIDY "Enable static analysis" off) +option(ENABLE_CCACHE "Use CCache to improve recompilation speed (optional)" on) set(CUSTOM_WEBSITE_URL "" CACHE STRING "Enable custom local webserver to check updates") if(ENABLE_NEWS OR ENABLE_UPDATER) @@ -169,6 +170,14 @@ set(ZLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib) # Search in the "cmake" directory for additional CMake modules. list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +if(ENABLE_CCACHE) + find_package(CCache) + if(CCache_FOUND) + # Use e.g. "ccache clang++" instead of "clang++" + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCache_EXECUTABLE}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCache_EXECUTABLE}") + endif() +endif() # Put libraries into "lib". set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) diff --git a/cmake/FindCCache.cmake b/cmake/FindCCache.cmake new file mode 100644 index 000000000..3c71c5464 --- /dev/null +++ b/cmake/FindCCache.cmake @@ -0,0 +1,23 @@ +# To find CCache compiler cache + +include(FindPackageHandleStandardArgs) + +find_program(CCache_EXECUTABLE ccache) + +if (CCache_EXECUTABLE) + execute_process(COMMAND "${CCache_EXECUTABLE}" --version + OUTPUT_VARIABLE CCache_VERSION_OUTPUT + ) + + if (CCache_VERSION_OUTPUT MATCHES "version ([0-9]+\\.[0-9]+\\.[0-9]+)") + set(CCache_VERSION "${CMAKE_MATCH_1}") + endif () +endif (CCache_EXECUTABLE) + +find_package_handle_standard_args(CCache + FOUND_VAR CCache_FOUND + REQUIRED_VARS CCache_EXECUTABLE + VERSION_VAR CCache_VERSION +) + +mark_as_advanced(CCache_EXECUTABLE)