From fd9d05300e74b75cc3cd54b536bb3e3442820c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 26 Sep 2022 18:21:43 +0200 Subject: [PATCH] handle precompiled headers with `ccache` / fixed caching in some docker builds (#4505) * CI-unixish.yml: handle precompiled headers with `ccache` * actually support `ccache` in CMake < 3.17 * CI-unixish-docker.yml: split CMake build and test execution into separate steps * findDependencies.cmake: only print message about macthcompiler being disabled when it is actually used * CI-unixish-docker.yml: added missing `ccache` CMake options --- .github/workflows/CI-unixish-docker.yml | 15 ++++++++++----- .github/workflows/CI-unixish.yml | 8 ++++++++ CMakeLists.txt | 1 + cmake/ccache.cmake | 7 +++++++ cmake/findDependencies.cmake | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 cmake/ccache.cmake diff --git a/.github/workflows/CI-unixish-docker.yml b/.github/workflows/CI-unixish-docker.yml index f6e157fa3..5fbec465d 100644 --- a/.github/workflows/CI-unixish-docker.yml +++ b/.github/workflows/CI-unixish-docker.yml @@ -52,7 +52,7 @@ jobs: key: ${{ github.workflow }}-${{ matrix.image }} # tests require CMake 3.9 - no ccache available - - name: Test CMake build (no tests) + - name: CMake build (no tests) if: matrix.image == 'ubuntu:14.04' run: | mkdir cmake.output @@ -61,7 +61,7 @@ jobs: cmake --build . -- -j$(nproc) # tests require CMake 3.9 - ccache available - - name: Test CMake build (no tests) + - name: CMake build (no tests) if: matrix.image == 'centos:7' || matrix.image == 'ubuntu:16.04' run: | mkdir cmake.output @@ -69,13 +69,18 @@ jobs: cmake -G "Unix Makefiles" -DHAVE_RULES=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache .. cmake --build . -- -j$(nproc) - - name: Test CMake build + - name: CMake build if: matrix.image != 'centos:7' && matrix.image != 'ubuntu:14.04' && matrix.image != 'ubuntu:16.04' run: | mkdir cmake.output cd cmake.output - cmake -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On .. - cmake --build . --target check -- -j$(nproc) + cmake -G "Unix Makefiles" -DHAVE_RULES=On -DBUILD_TESTS=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache .. + cmake --build . -- -j$(nproc) + + - name: Run CMake test + if: matrix.image != 'centos:7' && matrix.image != 'ubuntu:14.04' && matrix.image != 'ubuntu:16.04' + run: | + cmake --build cmake.output --target check -- -j$(nproc) build_make: diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 4bef03b73..96a747f9b 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -17,6 +17,10 @@ jobs: runs-on: ${{ matrix.os }} + env: + # TODO: files are cached but are still cache misses on platforms other than ubuntu-22.04 + CCACHE_SLOPPINESS: pch_defines,time_macros + steps: - uses: actions/checkout@v2 @@ -62,6 +66,10 @@ jobs: runs-on: ${{ matrix.os }} + env: + # TODO: files are cached but are still cache misses + CCACHE_SLOPPINESS: pch_defines,time_macros + steps: - uses: actions/checkout@v2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2628867a1..9a360178b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include(GNUInstallDirs) +include(cmake/ccache.cmake) include(cmake/compilerCheck.cmake) include(cmake/versions.cmake) include(cmake/options.cmake) diff --git a/cmake/ccache.cmake b/cmake/ccache.cmake new file mode 100644 index 000000000..403b61eac --- /dev/null +++ b/cmake/ccache.cmake @@ -0,0 +1,7 @@ +if (CMAKE_VERSION VERSION_LESS "3.17") + if (CMAKE_CXX_COMPILER_LAUNCHER) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_CXX_COMPILER_LAUNCHER}") + elseif (CMAKE_C_COMPILER_LAUNCHER) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_C_COMPILER_LAUNCHER}") + endif() +endif() \ No newline at end of file diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index 460fe4284..18b339df1 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -48,7 +48,7 @@ find_package(PythonInterp 3 QUIET) if (NOT PYTHONINTERP_FOUND) set(PYTHONINTERP_FOUND "") find_package(PythonInterp 2.7 QUIET) - if (NOT PYTHONINTERP_FOUND) + if (NOT PYTHONINTERP_FOUND AND NOT USE_MATCHCOMPILER_OPT STREQUAL "Off") message(WARNING "No python interpreter found. Therefore, the match compiler is switched off.") set(USE_MATCHCOMPILER_OPT "Off") endif()