From 62fdd69d856e8eafa6526dd60107d8240d65e0e3 Mon Sep 17 00:00:00 2001 From: jiayuehua <3423893+jiayuehua@users.noreply.github.com> Date: Mon, 17 Jan 2022 17:13:15 +0800 Subject: [PATCH] Support more compiler launchers: distcc sccache --- CMakeLists.txt | 2 +- cmake/nebula/CcacheConfig.cmake | 16 ---------------- cmake/nebula/CompilerLauncher.cmake | 29 +++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 17 deletions(-) delete mode 100644 cmake/nebula/CcacheConfig.cmake create mode 100644 cmake/nebula/CompilerLauncher.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e6729faa47..8198e11d418 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ include(GeneralCMakeOptions) include(GeneralCMakeConfig) include(GeneralCompilerConfig) include(LinkerConfig) -include(CcacheConfig) +include(CompilerLauncher) include(ThirdPartyConfig) include(SanitizerConfig) include(GitHooksConfig) diff --git a/cmake/nebula/CcacheConfig.cmake b/cmake/nebula/CcacheConfig.cmake deleted file mode 100644 index ad0816bdb77..00000000000 --- a/cmake/nebula/CcacheConfig.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# To detect if ccache is available -find_program(ccache_program_found "ccache") -if (ENABLE_CCACHE AND ccache_program_found) - if (NOT $ENV{CCACHE_DIR} STREQUAL "") - message(STATUS "CCACHE_DIR : $ENV{CCACHE_DIR}") - else() - message(STATUS "CCACHE_DIR : $ENV{HOME}/.ccache") - endif() - set(CMAKE_CXX_COMPILER_LAUNCHER "ccache") -elseif (ENABLE_CCACHE) - message(STATUS "CCACHE : Enabled but not found") - set(CMAKE_CXX_COMPILER_LAUNCHER) -else () - message(STATUS "CCACHE : OFF") - set(CMAKE_CXX_COMPILER_LAUNCHER) -endif() diff --git a/cmake/nebula/CompilerLauncher.cmake b/cmake/nebula/CompilerLauncher.cmake new file mode 100644 index 00000000000..2295e857934 --- /dev/null +++ b/cmake/nebula/CompilerLauncher.cmake @@ -0,0 +1,29 @@ +option(ENABLE_COMPILER_LAUNCHER "Using compiler launcher if available" ON) +if(NOT ENABLE_COMPILER_LAUNCHER) + return() +endif() + +set(COMPILER_LAUNCHER_OPTION + "ccache" + CACHE STRING "Compiler cache to be used") +set(COMPILER_LAUNCHER_OPTION_VALUES "ccache" "sccache" "distcc") +set_property(CACHE COMPILER_LAUNCHER_OPTION PROPERTY STRINGS ${COMPILER_LAUNCHER_OPTION_VALUES}) +list( + FIND + COMPILER_LAUNCHER_OPTION_VALUES + ${COMPILER_LAUNCHER_OPTION} + COMPILER_LAUNCHER_OPTION_INDEX) + +if(${COMPILER_LAUNCHER_OPTION_INDEX} EQUAL -1) + message( + STATUS + "Using custom compiler launcher system: '${COMPILER_LAUNCHER_OPTION}', explicitly supported entries are ${COMPILER_LAUNCHER_OPTION_VALUES}") +endif() + +find_program(COMPILER_LAUNCHER_BINARY ${COMPILER_LAUNCHER_OPTION}) +if(COMPILER_LAUNCHER_BINARY) + message(STATUS "${COMPILER_LAUNCHER_OPTION} found and enabled") + set(CMAKE_CXX_COMPILER_LAUNCHER ${COMPILER_LAUNCHER_BINARY}) +else() + message(WARNING "${COMPILER_LAUNCHER_OPTION} is enabled but was not found. Not using it") +endif()