Add CCache support to cmake list
This commit is contained in:
parent
225ff6bba1
commit
5802e87121
|
@ -23,3 +23,4 @@ bin/serenec_CXX_cotire.cmake
|
|||
/config.h
|
||||
|
||||
docs/Doxyfile.docs
|
||||
.ccache/
|
|
@ -38,8 +38,8 @@ option(CPP_20_SUPPORT "C++20 Support" OFF)
|
|||
option(SERENE_BUILD_TESTING "Enable tests" OFF)
|
||||
option(SERENE_ENABLE_BUILDID "Enable build id." OFF)
|
||||
option(SERENE_ENABLE_THINLTO "Enable ThisLTO." ON)
|
||||
option(SERENE_ENABLE_ASAN "Enable address sanitizer" ON)
|
||||
option(SERENE_ENABLE_DOCS "Enable document generation" OFF)
|
||||
option(SERENE_DISABLE_CCACHE "Disable automatic ccache integration" OFF)
|
||||
|
||||
# Only do these if this is the main project, and not if it is included through add_subdirectory
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
|
@ -88,7 +88,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|||
# For the sake of debugging
|
||||
$<$<CONFIG:DEBUG>:-fno-inline>
|
||||
# To make the local ccache happy
|
||||
$<$<CONFIG:DEBUG>:-fdebug-prefix-map=$PWD=.>
|
||||
$<$<CONFIG:DEBUG>:-fdebug-prefix-map=${PROJECT_SOURCE_DIR}=.>
|
||||
|
||||
$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>
|
||||
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
|
||||
|
@ -99,22 +99,54 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|||
add_link_options(
|
||||
# We enforce the lld linker
|
||||
-fuse-ld=lld
|
||||
-fsanitize=address
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
|
||||
# Do not link against shared libraries
|
||||
#--static
|
||||
)
|
||||
|
||||
|
||||
find_program(LLD_PROGRAM REQUIRED NAMES lld)
|
||||
find_program(MLIRTBLGEN_PROGRAM REQUIRED NAMES mlir-tblgen)
|
||||
|
||||
if(SERENE_ENABLE_BUILDID)
|
||||
add_link_options(-Wl,--build-id)
|
||||
endif()
|
||||
|
||||
if(SERENE_ENABLE_ASAN)
|
||||
add_compile_options(-fsanitize=address)
|
||||
endif()
|
||||
|
||||
if(SERENE_ENABLE_THINLTO)
|
||||
endif()
|
||||
|
||||
|
||||
# CCache support ==============================
|
||||
if(SERENE_DISABLE_CCACHE)
|
||||
message(STATUS "CCache support is disabled")
|
||||
else()
|
||||
|
||||
find_program(CCACHE_PROGRAM ccache)
|
||||
|
||||
if(CCACHE_PROGRAM)
|
||||
message(STATUS "Found CCache")
|
||||
set(SERENE_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
|
||||
set(SERENE_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
|
||||
set(SERENE_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
|
||||
CACHE STRING "Parameters to pass through to ccache")
|
||||
|
||||
set(CCACHE_PROGRAM "${SERENE_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
|
||||
|
||||
if (SERENE_CCACHE_MAXSIZE)
|
||||
set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${SERENE_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
|
||||
endif()
|
||||
if (SERENE_CCACHE_DIR)
|
||||
set(CCACHE_PROGRAM "CCACHE_DIR=${SERENE_CCACHE_DIR} ${CCACHE_PROGRAM}")
|
||||
endif()
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
|
||||
else()
|
||||
message(FATAL_ERROR "Unable to find the program ccache. Set SERENE_DISABLE_CCACHE to ON")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# LLVM setup =========================================
|
||||
find_package(LLVM REQUIRED CONFIG)
|
||||
find_package(MLIR REQUIRED CONFIG)
|
||||
|
|
23
builder
23
builder
|
@ -2,22 +2,10 @@
|
|||
|
||||
command=$1
|
||||
|
||||
# Utilize `ccache` if available
|
||||
if type "ccache" > /dev/null
|
||||
then
|
||||
echo "CCache detected."
|
||||
CMAKE_CCACHE="-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
|
||||
|
||||
else
|
||||
echo "CCache not detected."
|
||||
CMAKE_CCACHE=""
|
||||
fi
|
||||
export CMAKE_CCACHE
|
||||
|
||||
export CC=$(which clang)
|
||||
export CXX=$(which clang++)
|
||||
|
||||
export CCACHE_SLOPPINESS="pch_defines,time_macros"
|
||||
#export CCACHE_SLOPPINESS="pch_defines,time_macros"
|
||||
# Meke sure to use `lld` linker it faster and has a better UX
|
||||
export ASAN_OPTIONS=check_initialization_order=1
|
||||
LSAN_OPTIONS=suppressions=$(pwd)/.ignore_sanitize
|
||||
|
@ -26,10 +14,9 @@ export LSAN_OPTIONS
|
|||
# The `builder` script is supposed to be run from the
|
||||
# root of the source tree
|
||||
ROOT_DIR=$(pwd)
|
||||
CMAKEARGS="-DLLVM_PARALLEL_COMPILE_JOBS=7 -DLLVM_PARALLEL_LINK_JOBS=7 "
|
||||
BUILD_DIR=$ROOT_DIR/build
|
||||
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
|
||||
|
||||
CMAKEARGS="-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DSERENE_CCACHE_DIR=~/.ccache"
|
||||
scanbuild=scan-build
|
||||
|
||||
|
||||
|
@ -60,14 +47,14 @@ function build() {
|
|||
pushed_build
|
||||
echo "Running: "
|
||||
echo "cmake -G Ninja $CMAKE_CCACHE $CMAKEARGS -DCMAKE_BUILD_TYPE=Debug \"$@\" \"$ROOT_DIR\""
|
||||
cmake -G Ninja $CMAKE_CCACHE $CMAKEARGS -DCMAKE_BUILD_TYPE=Debug "$@" "$ROOT_DIR"
|
||||
cmake -G Ninja $CMAKEARGS -DCMAKE_BUILD_TYPE=Debug "$@" "$ROOT_DIR"
|
||||
cmake --build .
|
||||
popd_build
|
||||
}
|
||||
|
||||
function build-20() {
|
||||
pushed_build
|
||||
cmake -G Ninja $CMAKE_CCACHE -DCMAKE_BUILD_TYPE=Debug -DCPP_20_SUPPORT=ON "$@" "$ROOT_DIR"
|
||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCPP_20_SUPPORT=ON "$@" "$ROOT_DIR"
|
||||
cmake --build .
|
||||
popd_build
|
||||
}
|
||||
|
@ -81,7 +68,7 @@ function build-release() {
|
|||
|
||||
function build-docs() {
|
||||
pushed_build
|
||||
cmake -G Ninja $CMAKE_CCACHE -DCMAKE_BUILD_TYPE=Docs "$ROOT_DIR"
|
||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=Docs "$ROOT_DIR"
|
||||
cmake --build .
|
||||
popd_build
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue