Skip to content

Commit

Permalink
Merge pull request #5380 from rouault/ci_cmake_ccache
Browse files Browse the repository at this point in the history
CI: enable ccache on other CMake configs
  • Loading branch information
rouault authored Feb 23, 2022
2 parents 8e4bae6 + 866ac42 commit 1a9392f
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 5 deletions.
75 changes: 71 additions & 4 deletions .github/workflows/cmake_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ jobs:
build-linux-ubuntu-focal:
runs-on: ubuntu-20.04
env:
CMAKE_OPTIONS: -DPython_LOOKUP_VERSION=3.8 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache
CMAKE_OPTIONS: -DPython_LOOKUP_VERSION=3.8 -DUSE_CCACHE=ON
cache-name: cmake-ubuntu-focal
steps:
- name: Checkout GDAL
uses: actions/checkout@v2
- name: Setup cache
uses: actions/cache@v2
id: cache
with:
path: ${{ github.workspace }}/.ccache
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.base_ref }}${{ github.ref_name }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ github.base_ref }}
${{ runner.os }}-${{ env.cache-name }}
- name: Install CMake 3.10.2
run: |
cd ${GITHUB_WORKSPACE}
Expand Down Expand Up @@ -55,6 +65,13 @@ jobs:
#
python3 -m pip install -U pip wheel setuptools numpy
python3 -m pip install -r $GITHUB_WORKSPACE/autotest/requirements.txt
- name: Configure ccache
run: |
echo CCACHE_BASEDIR=$PWD >> ${GITHUB_ENV}
echo CCACHE_DIR=$PWD/.ccache >> ${GITHUB_ENV}
echo CCACHE_MAXSIZE=250M >> ${GITHUB_ENV}
ccache -z
working-directory: ${{ github.workspace }}
- name: Configure
run: |
mkdir -p $GITHUB_WORKSPACE/superbuild
Expand Down Expand Up @@ -144,6 +161,8 @@ jobs:
else
echo 'Expected fail'
fi
- name: ccache statistics
run: ccache -s

build-windows-msys2-mingw:
runs-on: windows-2022
Expand Down Expand Up @@ -241,7 +260,9 @@ jobs:
runs-on: windows-2022
env:
architecture: x64
generator: Visual Studio 17 2022
#generator: Visual Studio 17 2022
generator: Ninja
cache-name: cmake-msvc
steps:
# To avoid git clone to mess with the line endings of GDAL autotest data
# files that look like text, but should be handled as binary content
Expand All @@ -250,6 +271,7 @@ jobs:
git config --global core.autocrlf false
- name: Checkout GDAL
uses: actions/checkout@v2
- uses: ilammy/msvc-dev-cmd@v1
- name: populate JAVA_HOME
shell: pwsh
run: |
Expand All @@ -274,6 +296,28 @@ jobs:
curl http://download.osgeo.org/proj/proj-datumgrid-1.8.tar.gz > proj-datumgrid-1.8.tar.gz
tar xvzf proj-datumgrid-1.8.tar.gz
cd $OLDPWD
- name: Setup cache
uses: actions/cache@v2
id: cache
with:
path: ${{ github.workspace }}\.clcache
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.base_ref }}${{ github.ref_name }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ github.base_ref }}
${{ runner.os }}-${{ env.cache-name }}
- name: Configure ccache (Part 1)
shell: cmd
run: |
set CLCACHE_DIR=%CD%\.clcache
echo CLCACHE_DIR=%CLCACHE_DIR%>> %GITHUB_ENV%
- name: Configure ccache (Part 2)
shell: bash -l {0}
run: |
${CONDA_PREFIX}/Scripts/clcache -z
${CONDA_PREFIX}/Scripts/clcache -M 250000000
${CONDA_PREFIX}/Scripts/clcache -s
# Otherwise cmake can find link.exe from Conda instead of MSVC
rm /usr/bin/link
- name: Configure
shell: bash -l {0}
# FIXME: Jasper manually disabled because of linking errors: lacks jp2_box_destroy
Expand All @@ -284,7 +328,7 @@ jobs:
# BUILD_JAVA_BINDINGS=OFF because we get "Error occurred during initialization of VM. Corrupted ZIP library: C:\Miniconda\envs\gdalenv\Library\bin\zip.dll" when running java. Not reproducible on a standard VM
run: |
mkdir -p $GITHUB_WORKSPACE/build
cmake -A ${architecture} -G "${generator}" -Werror=dev "-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal" "-DCMAKE_C_COMPILER_LAUNCHER=clcache" "-DCMAKE_CXX_COMPILER_LAUNCHER=clcache" "-DCMAKE_PREFIX_PATH=${CONDA_PREFIX}" -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DJASPER_LIBRARY_RELEASE:FILEPATH= -DLIBKML_BASE_LIBRARY:FILEPATH= -DGDAL_ENABLE_PLUGINS:BOOL=ON -DGDAL_ENABLE_PLUGINS_NO_DEPS:BOOL=ON -DGDAL_USE_PUBLICDECOMPWT:BOOL=ON -DPUBLICDECOMPWT_URL=https://github.com/rouault/PublicDecompWT -DBUILD_JAVA_BINDINGS=OFF -DBUILD_CSHARP_BINDINGS=ON -DGDAL_USE_MYSQL:BOOL=OFF -DCMAKE_C_FLAGS=" /WX" -DCMAKE_CXX_FLAGS=" /WX" -DWERROR_DEV_FLAG="-Werror=dev"
cmake -G "${generator}" -Werror=dev "-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal" "-DUSE_CCACHE=ON" "-DCMAKE_PREFIX_PATH=${CONDA_PREFIX}" -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DJASPER_LIBRARY_RELEASE:FILEPATH= -DLIBKML_BASE_LIBRARY:FILEPATH= -DGDAL_ENABLE_PLUGINS:BOOL=ON -DGDAL_ENABLE_PLUGINS_NO_DEPS:BOOL=ON -DGDAL_USE_PUBLICDECOMPWT:BOOL=ON -DPUBLICDECOMPWT_URL=https://github.com/rouault/PublicDecompWT -DBUILD_JAVA_BINDINGS=OFF -DBUILD_CSHARP_BINDINGS=ON -DGDAL_USE_MYSQL:BOOL=OFF -DCMAKE_C_FLAGS=" /WX" -DCMAKE_CXX_FLAGS=" /WX" -DWERROR_DEV_FLAG="-Werror=dev" -DCMAKE_BUILD_TYPE=Release
- name: Build
shell: bash -l {0}
run: cmake --build $GITHUB_WORKSPACE/build --config Release -j 2
Expand All @@ -310,6 +354,10 @@ jobs:
gdalinfo --version
python -VV
PYTHONPATH=$GITHUB_WORKSPACE/install-gdal/lib/site-packages python -c "from osgeo import gdal;print(gdal.VersionInfo(None))"
- name: clcache statistics
shell: bash -l {0}
run:
${CONDA_PREFIX}/Scripts/clcache -s

build-windows-minimum:
runs-on: windows-2022
Expand Down Expand Up @@ -350,13 +398,23 @@ jobs:
runs-on: macOS-latest
env:
CMAKE_OPTIONS: -DGDAL_USE_GIFLIB_INTERNAL=YES -DCFITSIO_ROOT=/usr/local/opt/cfitsio -DPoppler_ROOT=/usr/local/opt/poppler -DPROJ_ROOT=/usr/local/opt/proj -DLibXml2_ROOT=/usr/local/opt/libxml2 -DSPATIALITE_ROOT=/usr/local/opt/libspatialite -DPostgreSQL_ROOT=/usr/local/opt/libpq -DEXPAT_ROOT=/usr/local/opt/expat -DXercesC_ROOT=/usr/local/opt/xerces-c -DSQLite3_ROOT=/usr/local/opt/sqlite -DOpenSSL_ROOT=/usr/local/opt/openssl -DPNG_ROOT=/usr/local/opt/libpng -DJPEG_ROOT=/usr/local/opt/jpeg -DOpenJPEG_ROOT=/usr/local/opt/openjpeg -DCURL_ROOT=/usr/local/opt/curl -DGDAL_USE_DAP=OFF -DGDAL_USE_JASPER=OFF
cache-name: cmake-macos
steps:
- name: Setup xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 12.4
- name: Checkout GDAL
uses: actions/checkout@v2
- name: Setup cache
uses: actions/cache@v2
id: cache
with:
path: ${{ github.workspace }}/.ccache
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.base_ref }}${{ github.ref_name }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ github.base_ref }}
${{ runner.os }}-${{ env.cache-name }}
- run: |
cmake --version
- name: Install dependency
Expand All @@ -373,10 +431,17 @@ jobs:
tar xvzf proj-datumgrid-1.8.tar.gz
cd $OLDPWD
python3 -m pip install -r $GITHUB_WORKSPACE/autotest/requirements.txt
- name: Configure ccache
run: |
echo CCACHE_BASEDIR=$PWD >> ${GITHUB_ENV}
echo CCACHE_DIR=$PWD/.ccache >> ${GITHUB_ENV}
echo CCACHE_MAXSIZE=250M >> ${GITHUB_ENV}
ccache -z
working-directory: ${{ github.workspace }}
- name: Configure
run: |
mkdir -p $GITHUB_WORKSPACE/build
cmake -Werror=dev -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal ${CMAKE_OPTIONS} -DCMAKE_C_FLAGS=-Werror -DCMAKE_CXX_FLAGS=-Werror "-DCMAKE_C_COMPILER_LAUNCHER=ccache" "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache" -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DWERROR_DEV_FLAG="-Werror=dev"
cmake -Werror=dev -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal ${CMAKE_OPTIONS} -DCMAKE_C_FLAGS=-Werror -DCMAKE_CXX_FLAGS=-Werror -DUSE_CCACHE=ON -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DWERROR_DEV_FLAG="-Werror=dev"
- name: Build
run: |
cmake --build $GITHUB_WORKSPACE/build -j 3
Expand All @@ -399,6 +464,8 @@ jobs:
- name: Test post-install usage (with CMake)
run: |
./autotest/postinstall/test_cmake.sh $GITHUB_WORKSPACE/install-gdal
- name: ccache statistics
run: ccache -s

# Disabled for now since bindings in master use GDALDatasetGetFieldDomainNames
# but libgdal from Conda has not it yet.
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ endif ()
#
include(CheckCompilerMachineOption)
include(CheckCompilerSIMDFeature)
include(Ccache)

#
if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(x86|AMD64)")
check_compiler_machine_option(flag SSE)
Expand Down
1 change: 0 additions & 1 deletion autotest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ int main(int argc, char **argv) {
}")
add_executable(pytest_runner ${CMAKE_CURRENT_BINARY_DIR}/pytest_runner.cpp)
set_property(TARGET pytest_runner PROPERTY CXX_STANDARD 11)
target_link_libraries(pytest_runner PUBLIC ${GDAL_LIB_TARGET_NAME})
target_include_directories(pytest_runner PRIVATE ${Python_INCLUDE_DIRS})
target_link_libraries(pytest_runner PRIVATE ${Python_LIBRARIES})
add_custom_target(
Expand Down
67 changes: 67 additions & 0 deletions cmake/modules/Ccache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#
# CMake module to support ccache (or clcache for MSVC)
#
# Copyright (c) 2021, Mike Taves <mwtoews at gmail dot com>
#
# Usage:
# Add "include(Ccache)" to CMakeLists.txt and enable
# using the option -D USE_CCACHE=ON

cmake_minimum_required(VERSION 3.4)


option(USE_CCACHE
"Use ccache (or clcache for MSVC) to compile C/C++ objects" OFF)
if(NOT USE_CCACHE)
# stop here and return to including file
return()
endif()

# Search priority:
# 1. ccache for many compilers except MSVC
# 2. clcache for MSVC

find_program(CCACHE_PROGRAM NAMES ccache clcache)

if(CCACHE_PROGRAM)
message(STATUS "Configuring ccache with ${CCACHE_PROGRAM}")

if(CMAKE_GENERATOR STREQUAL "Xcode")
# see https://crascit.com/2016/04/09/using-ccache-with-cmake/
set(C_LAUNCHER "${CCACHE_PROGRAM}")
set(CXX_LAUNCHER "${CCACHE_PROGRAM}")
set(CCACHE_LAUNCH_C ${CMAKE_BINARY_DIR}/ccache-c)
set(CCACHE_LAUNCH_CXX ${CMAKE_BINARY_DIR}/ccache-cxx)
file(WRITE "${CCACHE_LAUNCH_C}" "\
#!/bin/sh
shift
exec \"${C_LAUNCHER}\" \"${CMAKE_C_COMPILER}\" \"$@\"
")
file(WRITE "${CCACHE_LAUNCH_CXX}" "\
#!/bin/sh
shift
exec \"${CXX_LAUNCHER}\" \"${CMAKE_CXX_COMPILER}\" \"$@\"
")
# Note: file(CHMOD) introduced in CMake 3.19
execute_process(
COMMAND chmod a+rx
"${CCACHE_LAUNCH_C}"
"${CCACHE_LAUNCH_CXX}"
)
# Set Xcode project attributes to route compilation and linking
# through the wrapper scripts
set(CMAKE_XCODE_ATTRIBUTE_CC "${CCACHE_LAUNCH_C}")
set(CMAKE_XCODE_ATTRIBUTE_CXX "${CCACHE_LAUNCH_CXX}")
set(CMAKE_XCODE_ATTRIBUTE_LD "${CCACHE_LAUNCH_C}")
set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CCACHE_LAUNCH_CXX}")
elseif(CCACHE_PROGRAM MATCHES "clcache")
set(CMAKE_C_COMPILER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER "${CCACHE_PROGRAM}")
else()
# Most other generators (Unix Makefiles, Ninja, etc.)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
else()
message(WARNING "Ccache was requested, but no program was not found")
endif()

0 comments on commit 1a9392f

Please sign in to comment.