build: refactor ccache detection and usage

Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
This commit is contained in:
Artur Harasimiuk 2024-03-29 09:19:40 +00:00 committed by Compute-Runtime-Automation
parent a9e9ac2d73
commit fffa880d5a
1 changed files with 27 additions and 20 deletions

View File

@ -571,29 +571,36 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
option(APPVERIFIER_ALLOWED "allow use of AppVerifier" OFF)
option(CCACHE_ALLOWED "allow use of ccache" TRUE)
find_program(CCACHE_EXE_FOUND ccache)
if(CCACHE_EXE_FOUND AND CCACHE_ALLOWED)
message(STATUS "Found ccache: ${CCACHE_EXE_FOUND}")
if((CMAKE_HOST_UNIX OR("${CMAKE_GENERATOR}" STREQUAL "Ninja")) AND CCACHE_ALLOWED)
find_program(CCACHE_EXE_FOUND ccache)
if(CCACHE_EXE_FOUND)
message(STATUS "Found ccache: ${CCACHE_EXE_FOUND}")
if(NOT NEO_DONT_SET_CCACHE_BASEDIR AND NOT DEFINED ENV{CCACHE_BASEDIR})
get_filename_component(__tmp_dir "../infra" ABSOLUTE)
if(IS_DIRECTORY ${__tmp_dir})
get_filename_component(NEO_CCACHE_BASEDIR ".." ABSOLUTE)
list(APPEND NEO_RULE_LAUNCH_LIST "CCACHE_BASEDIR=${NEO_CCACHE_BASEDIR}")
message(STATUS "using ccache base dir: ${NEO_CCACHE_BASEDIR}")
if(NOT NEO_DONT_SET_CCACHE_BASEDIR AND NOT DEFINED ENV{CCACHE_BASEDIR})
get_filename_component(__tmp_dir "../infra" ABSOLUTE)
if(IS_DIRECTORY ${__tmp_dir})
get_filename_component(NEO_CCACHE_BASEDIR ".." ABSOLUTE)
if(CMAKE_HOST_WIN32)
list(APPEND NEO_RULE_LAUNCH_LIST "\"${CMAKE_COMMAND}\" -E env CCACHE_BASEDIR=${NEO_CCACHE_BASEDIR}")
else()
list(APPEND NEO_RULE_LAUNCH_LIST "CCACHE_BASEDIR=${NEO_CCACHE_BASEDIR}")
endif()
message(STATUS "setting ccache base dir: ${NEO_CCACHE_BASEDIR}")
endif()
elseif(DEFINED ENV{CCACHE_BASEDIR})
message(STATUS "Using ccache base dir: $ENV{CCACHE_BASEDIR}")
endif()
elseif(DEFINED ENV{CCACHE_BASEDIR})
message(STATUS "Using ccache base dir: $ENV{CCACHE_BASEDIR}")
endif()
list(APPEND NEO_RULE_LAUNCH_LIST "ccache")
string(REPLACE ";" " " NEO_RULE_LAUNCH_STR "${NEO_RULE_LAUNCH_LIST}")
message(STATUS "Using rule: ${NEO_RULE_LAUNCH_STR}")
list(APPEND NEO_RULE_LAUNCH_LIST "${CCACHE_EXE_FOUND}")
string(REPLACE ";" " " NEO_RULE_LAUNCH_STR "${NEO_RULE_LAUNCH_LIST}")
message(STATUS "Using rule: ${NEO_RULE_LAUNCH_STR}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${NEO_RULE_LAUNCH_STR})
if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${NEO_RULE_LAUNCH_STR})
else()
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${NEO_RULE_LAUNCH_STR})
if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${NEO_RULE_LAUNCH_STR})
else()
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_EXE_FOUND}")
endif()
endif()
endif()