1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #3400 from Kuxe/enable_ccache_option_for_linux

Enable ccache option for linux
This commit is contained in:
Ivan Savenko
2023-12-31 12:16:21 +02:00
committed by GitHub
5 changed files with 62 additions and 34 deletions

View File

@@ -244,7 +244,7 @@ jobs:
- name: CMake Preset with ccache - name: CMake Preset with ccache
run: | run: |
cmake -DCMAKE_CXX_COMPILER_LAUNCHER=ccache --preset ${{ matrix.preset }} cmake -DENABLE_CCACHE:BOOL=ON --preset ${{ matrix.preset }}
- name: Build Preset - name: Build Preset
run: | run: |

View File

@@ -79,28 +79,31 @@ if(NOT APPLE_IOS AND NOT ANDROID)
option(ENABLE_MONOLITHIC_INSTALL "Install everything in single directory on Linux and Mac" OFF) option(ENABLE_MONOLITHIC_INSTALL "Install everything in single directory on Linux and Mac" OFF)
endif() endif()
# On Linux, use -DCMAKE_CXX_COMPILER_LAUNCHER=ccache instead. option(ENABLE_CCACHE "Speed up recompilation by caching previous compilations" OFF)
# The XCode and MSVC builds each require some more configuration, which is enabled by the following option: if(ENABLE_CCACHE)
if(MSVC OR (CMAKE_GENERATOR STREQUAL "Xcode")) find_program(CCACHE ccache REQUIRED)
option(ENABLE_CCACHE "Speed up recompilation by caching previous compilations" OFF) endif()
# On Linux, use ccache via CMAKE_CXX_COMPILER_LAUNCHER.
# The XCode and MSVC builds each require some more configuration further down.
if(ENABLE_CCACHE AND LINUX)
set(CMAKE_C_COMPILER_LAUNCHER "ccache")
set(CMAKE_CXX_COMPILER_LAUNCHER "ccache")
endif() endif()
if(ENABLE_CCACHE AND (CMAKE_GENERATOR STREQUAL "Xcode")) if(ENABLE_CCACHE AND (CMAKE_GENERATOR STREQUAL "Xcode"))
find_program(CCACHE ccache REQUIRED) # https://stackoverflow.com/a/36515503/2278742
if(CCACHE) # Set up wrapper scripts
# https://stackoverflow.com/a/36515503/2278742 configure_file(xcode/launch-c.in xcode/launch-c)
# Set up wrapper scripts configure_file(xcode/launch-cxx.in xcode/launch-cxx)
configure_file(xcode/launch-c.in xcode/launch-c) execute_process(COMMAND chmod a+rx
configure_file(xcode/launch-cxx.in xcode/launch-cxx) "${CMAKE_BINARY_DIR}/xcode/launch-c"
execute_process(COMMAND chmod a+rx "${CMAKE_BINARY_DIR}/xcode/launch-cxx")
"${CMAKE_BINARY_DIR}/xcode/launch-c" # Set Xcode project attributes to route compilation through our scripts
"${CMAKE_BINARY_DIR}/xcode/launch-cxx") set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/xcode/launch-c")
# Set Xcode project attributes to route compilation through our scripts set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/xcode/launch-cxx")
set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/xcode/launch-c") set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/xcode/launch-c")
set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/xcode/launch-cxx") set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/xcode/launch-cxx")
set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/xcode/launch-c")
set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/xcode/launch-cxx")
endif()
endif() endif()
# Allow to pass package name from Travis CI # Allow to pass package name from Travis CI
@@ -266,19 +269,16 @@ if(MINGW OR MSVC)
if(MSVC) if(MSVC)
if(ENABLE_CCACHE) if(ENABLE_CCACHE)
# https://github.com/ccache/ccache/discussions/1154#discussioncomment-3611387 # https://github.com/ccache/ccache/discussions/1154#discussioncomment-3611387
find_program(CCACHE ccache REQUIRED) file(COPY_FILE
if (CCACHE) ${CCACHE} ${CMAKE_BINARY_DIR}/cl.exe
file(COPY_FILE ONLY_IF_DIFFERENT)
${CCACHE} ${CMAKE_BINARY_DIR}/cl.exe
ONLY_IF_DIFFERENT)
set(CMAKE_VS_GLOBALS set(CMAKE_VS_GLOBALS
"CLToolExe=cl.exe" "CLToolExe=cl.exe"
"CLToolPath=${CMAKE_BINARY_DIR}" "CLToolPath=${CMAKE_BINARY_DIR}"
"TrackFileAccess=false" "TrackFileAccess=false"
"UseMultiToolTask=true" "UseMultiToolTask=true"
) )
endif()
endif() endif()
add_definitions(-DBOOST_ALL_NO_LIB) add_definitions(-DBOOST_ALL_NO_LIB)

View File

@@ -65,6 +65,15 @@
"CMAKE_CXX_COMPILER": "/usr/bin/clang++" "CMAKE_CXX_COMPILER": "/usr/bin/clang++"
} }
}, },
{
"name": "linux-clang-release-ccache",
"displayName": "Clang x86_64-pc-linux-gnu with ccache",
"description": "VCMI Linux Clang with ccache",
"inherits": "linux-release",
"cacheVariables": {
"ENABLE_CCACHE": "ON"
}
},
{ {
"name": "linux-gcc-release", "name": "linux-gcc-release",
"displayName": "GCC x86_64-pc-linux-gnu", "displayName": "GCC x86_64-pc-linux-gnu",
@@ -76,6 +85,15 @@
"CMAKE_CXX_COMPILER": "/usr/bin/g++" "CMAKE_CXX_COMPILER": "/usr/bin/g++"
} }
}, },
{
"name": "linux-gcc-release-ccache",
"displayName": "GCC x86_64-pc-linux-gnu with ccache",
"description": "VCMI Linux GCC with ccache",
"inherits": "linux-release",
"cacheVariables": {
"ENABLE_CCACHE": "ON"
}
},
{ {
"name": "linux-gcc-debug", "name": "linux-gcc-debug",
"displayName": "GCC x86_64-pc-linux-gnu (debug)", "displayName": "GCC x86_64-pc-linux-gnu (debug)",
@@ -284,6 +302,11 @@
"configurePreset": "linux-clang-release", "configurePreset": "linux-clang-release",
"inherits": "default-release" "inherits": "default-release"
}, },
{
"name": "linux-clang-release-ccache",
"configurePreset": "linux-clang-release-ccache",
"inherits": "linux-clang-release"
},
{ {
"name": "linux-clang-test", "name": "linux-clang-test",
"configurePreset": "linux-clang-test", "configurePreset": "linux-clang-test",
@@ -299,6 +322,11 @@
"configurePreset": "linux-gcc-release", "configurePreset": "linux-gcc-release",
"inherits": "default-release" "inherits": "default-release"
}, },
{
"name": "linux-gcc-release-ccache",
"configurePreset": "linux-gcc-release-ccache",
"inherits": "linux-gcc-release"
},
{ {
"name": "linux-gcc-debug", "name": "linux-gcc-debug",
"configurePreset": "linux-gcc-debug", "configurePreset": "linux-gcc-debug",

View File

@@ -62,7 +62,7 @@ Building for Android is a 2-step process. First, native C++ code is compiled to
This is a traditional CMake project, you can build it from command line or some IDE. You're not required to pass any custom options (except Conan toolchain file), defaults are already good. If you wish to use your own CMake presets, inherit them from our `build-with-conan` preset. Example: This is a traditional CMake project, you can build it from command line or some IDE. You're not required to pass any custom options (except Conan toolchain file), defaults are already good. If you wish to use your own CMake presets, inherit them from our `build-with-conan` preset. Example:
``` ```
cmake -S . -B ../build -G Ninja -D CMAKE_BUILD_TYPE=Debug -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER_LAUNCHER=ccache --toolchain ... cmake -S . -B ../build -G Ninja -D CMAKE_BUILD_TYPE=Debug -D ENABLE_CCACHE:BOOL=ON --toolchain ...
cmake --build ../build cmake --build ../build
``` ```

View File

@@ -76,7 +76,7 @@ cmake ../vcmi
**Notice**: The ../vcmi/ is not a typo, it will place makefile scripts into the build dir as the build dir is your working dir when calling CMake. **Notice**: The ../vcmi/ is not a typo, it will place makefile scripts into the build dir as the build dir is your working dir when calling CMake.
## To use ccache: ## To use ccache:
`cmake ../vcmi -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER_LAUNCHER=ccache` `cmake ../vcmi -D ENABLE_CCACHE:BOOL=ON`
## Trigger build ## Trigger build