# https://crascit.com/2016/04/09/using-ccache-with-cmake/
# https://github.com/msys2/MINGW-packages/issues/5628
#
# cmake -GNinja .. -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache
cmake_minimum_required(VERSION 3.4)
# NOTE: A common path for custom Cmake modules is '<CMAKE_SOURCE_DIR>/cmake'.
# Anyhow, this repository contains several CMake examples, each one in its own subdirectory, sharing the same custom modules.
# This is why the added module path path in this case has been changed from '<CMAKE_SOURCE_DIR>/cmake' to '<CMAKE_SOURCE_DIR>/../cmake'.
get_filename_component(CMAKE_MODULE_PATH_CCACHE "${CMAKE_SOURCE_DIR}/../cmake/" ABSOLUTE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_MODULE_PATH_CCACHE}")
include(FindCcache)
project(SmallTestCcacheProject)
# This CMakeLists.txt expects a source file and an executable name from the command line
if(DEFINED SRC AND DEFINED EXE)
message("Building '${EXE}' using CMake and Ninja (${ccache_msg})...")
else()
message("ERROR: Missing flags, rerun 'cmake' with the added flags:")
message(FATAL_ERROR "-DSRC=small-test.c -DEXE=small-test-built-with-ninja -DUSE_CCACHE=0|1")
endif()
# Build the minimal app
add_executable(${EXE} ${SRC})