From 0e6e98e8fb1b4e42eff5958fce981c80e7ac2dfd Mon Sep 17 00:00:00 2001 From: "xiaozhuai, Weihang Ding" <798047000@qq.com> Date: Fri, 1 Apr 2022 11:36:43 +0800 Subject: [PATCH] Extend options that disable testing and formatting to looking for dependencies also. (#1039) The option `YAML_CPP_BUILD_TESTS` currently enables or disables building of tests; but unconditionally the CMake file includes CTest; this PR makes that conditional on the option. Also, there is no option for enabling formatting, but it does check whether it can find the `clang-format` executable; this PR adds an option (default to true) that skips even looking for the executable if disabled. --- CMakeLists.txt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ccc1964..012d3c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,13 +13,19 @@ include(CMakePackageConfigHelpers) include(CMakeDependentOption) include(CheckCXXCompilerFlag) include(GNUInstallDirs) -include(CTest) - -find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format) option(YAML_CPP_BUILD_CONTRIB "Enable yaml-cpp contrib in library" ON) option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON) option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp shared library" ${BUILD_SHARED_LIBS}) +option(YAML_CPP_FORMAT_SOURCE "Format source" ON) + +if (YAML_CPP_BUILD_TESTS) + include(CTest) +endif() + +if (YAML_CPP_FORMAT_SOURCE) + find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format) +endif() cmake_dependent_option(YAML_CPP_BUILD_TESTS "Enable yaml-cpp tests" ON @@ -178,7 +184,7 @@ if(YAML_CPP_BUILD_TOOLS) add_subdirectory(util) endif() -if (YAML_CPP_CLANG_FORMAT_EXE) +if (YAML_CPP_FORMAT_SOURCE AND YAML_CPP_CLANG_FORMAT_EXE) add_custom_target(format COMMAND clang-format --style=file -i $ COMMAND_EXPAND_LISTS