From 58914a77c03b1097bf0284a4dda06613b66c4e00 Mon Sep 17 00:00:00 2001 From: "yuehua.jia" <3423893+jiayuehua@users.noreply.github.com> Date: Mon, 13 Dec 2021 20:23:46 +0800 Subject: [PATCH] add cmake git hooks options (#3390) * add cmake git hooks options * githooks option * include what you use * make name follow convention --- CMakeLists.txt | 3 +++ cmake/nebula/GitHooksConfig.cmake | 2 +- cmake/nebula/IncludeWhatYouUse.cmake | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 cmake/nebula/IncludeWhatYouUse.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index da676c5716f..8d9dee102f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ project("Nebula Graph" C CXX) option(ENABLE_PACK_ONE "Whether to package into one" ON) option(ENABLE_VERBOSE_BISON "Enable Bison to report state" OFF) option(ENABLE_PACKAGE_TAR "Enable package artifacts to tar." OFF) +option(ENABLE_CREATE_GIT_HOOKS "Enable create git hooks." ON) +option(ENABLE_INCLUDE_WHAT_YOU_USE "Enable include-what-you-use find nouse include files" OFF) add_definitions(-DNEBULA_HOME=${CMAKE_SOURCE_DIR}) @@ -44,6 +46,7 @@ include(SanitizerConfig) include(GitHooksConfig) include(GitInfoConfig) include(NebulaCustomTargets) +include(IncludeWhatYouUse) add_custom_target( clang-format diff --git a/cmake/nebula/GitHooksConfig.cmake b/cmake/nebula/GitHooksConfig.cmake index 526bb984987..6573efac730 100644 --- a/cmake/nebula/GitHooksConfig.cmake +++ b/cmake/nebula/GitHooksConfig.cmake @@ -1,4 +1,4 @@ -if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/") +if(ENABLE_CREATE_GIT_HOOKS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git/") # Create the pre-commit hook every time we run cmake message(STATUS "Create the pre-commit hook") set(PRE_COMMIT_HOOK ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit) diff --git a/cmake/nebula/IncludeWhatYouUse.cmake b/cmake/nebula/IncludeWhatYouUse.cmake new file mode 100644 index 00000000000..07e86c0ea30 --- /dev/null +++ b/cmake/nebula/IncludeWhatYouUse.cmake @@ -0,0 +1,10 @@ +if(ENABLE_INCLUDE_WHAT_YOU_USE) + find_program(INCLUDE_WHAT_YOU_USE include-what-you-use) + if(INCLUDE_WHAT_YOU_USE) + message("use include-what-you-use") + set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "include-what-you-use;-Xiwyu;--transitive_includes_only") + else() + message(STATUS "iwyu requested but executable not found") + endif() +endif() +