Skip to content

Commit

Permalink
Merge pull request #202 from tudat-team/feature/add-ccache
Browse files Browse the repository at this point in the history
Feature/add ccache
  • Loading branch information
niketagrawal authored Mar 19, 2024
2 parents 33a446c + c7628e8 commit 5c4df5d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,34 +117,36 @@ jobs:
run: cmd /c "curl -fsSL https://raw.githubusercontent.com/tudat-team/tudat-resources-feedstock/master/recipe/post-link.bat | cmd"


- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash -l {0}
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Setup ccache
# This third party action will setup ccache on the runner and restore any previously saved cache. Caches are saved automatically by the action after a build.
uses: hendrikmuhs/[email protected]
with:
key: ${{ matrix.os }}-${{ matrix.type }}


- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
shell: bash -l {0}
run: >
cmake -B "${{ steps.strings.outputs.build-output-dir }}"
cmake -B "${{ github.workspace }}/build"
-S "${{ github.workspace }}"
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S "${{ github.workspace }}"
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DTUDAT_BUILD_GITHUB_ACTIONS=ON
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). Use multiple cpu cores available in the runner.
shell: bash -l {0}
run: cmake --build "${{ steps.strings.outputs.build-output-dir }}" --config "${{ matrix.build_type }}" -j4
run: cmake --build "${{ github.workspace }}/build" --config "${{ matrix.build_type }}" -j4


- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
working-directory: "${{ github.workspace }}/build"
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
# Prevent the action from failing if any of the tests fail by using `|| true`. This is placed temporarily because currently, some tests fail on MacOS, and if the action fails, the cache is not updated, which prevents testing of the cache feature on MacOS.
Expand Down
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ else()
option(TUDAT_BUILD_WITH_EXTENDED_PRECISION_PROPAGATION_TOOLS "Build tudat with extended precision propagation tools." OFF)
endif()

# Build as part of a GitHub Actions workflow
# Option enables the use of ccache by MSVC
# see https://github.com/ccache/ccache/wiki/MS-Visual-Studio
option(TUDAT_BUILD_GITHUB_ACTIONS "Build as part of GitHub Actions workflow." OFF)
if (TUDAT_BUILD_GITHUB_ACTIONS AND MSVC)
find_program(ccache_exe ccache)
if(ccache_exe)
message(STATUS "CONFIGURING MSVC FOR CCACHE")
file(COPY_FILE ${ccache_exe} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT)

# By default Visual Studio generators will use /Zi which is not compatible
# with ccache, so tell Visual Studio to use /Z7 instead.
message(STATUS "Setting MSVC debug information format to 'Embedded'")
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")

set(CMAKE_VS_GLOBALS
"CLToolExe=cl.exe"
"CLToolPath=${CMAKE_BINARY_DIR}"
"TrackFileAccess=false"
"UseMultiToolTask=true"
"DebugInformationFormat=OldStyle"
)
endif()
endif()

message(STATUS "******************** BUILD CONFIGURATION ********************")
message(STATUS "TUDAT_BUILD_TESTS ${TUDAT_BUILD_TESTS}")
message(STATUS "TUDAT_BUILD_WITH_PROPAGATION_TESTS ${TUDAT_BUILD_WITH_PROPAGATION_TESTS}")
Expand Down

0 comments on commit 5c4df5d

Please sign in to comment.