Skip to content

Commit 0e6e98e

Browse files
authored
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.
1 parent 4aad2b1 commit 0e6e98e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ include(CMakePackageConfigHelpers)
1313
include(CMakeDependentOption)
1414
include(CheckCXXCompilerFlag)
1515
include(GNUInstallDirs)
16-
include(CTest)
17-
18-
find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format)
1916

2017
option(YAML_CPP_BUILD_CONTRIB "Enable yaml-cpp contrib in library" ON)
2118
option(YAML_CPP_BUILD_TOOLS "Enable parse tools" ON)
2219
option(YAML_BUILD_SHARED_LIBS "Build yaml-cpp shared library" ${BUILD_SHARED_LIBS})
20+
option(YAML_CPP_FORMAT_SOURCE "Format source" ON)
21+
22+
if (YAML_CPP_BUILD_TESTS)
23+
include(CTest)
24+
endif()
25+
26+
if (YAML_CPP_FORMAT_SOURCE)
27+
find_program(YAML_CPP_CLANG_FORMAT_EXE NAMES clang-format)
28+
endif()
2329

2430
cmake_dependent_option(YAML_CPP_BUILD_TESTS
2531
"Enable yaml-cpp tests" ON
@@ -178,7 +184,7 @@ if(YAML_CPP_BUILD_TOOLS)
178184
add_subdirectory(util)
179185
endif()
180186

181-
if (YAML_CPP_CLANG_FORMAT_EXE)
187+
if (YAML_CPP_FORMAT_SOURCE AND YAML_CPP_CLANG_FORMAT_EXE)
182188
add_custom_target(format
183189
COMMAND clang-format --style=file -i $<TARGET_PROPERTY:yaml-cpp,SOURCES>
184190
COMMAND_EXPAND_LISTS

0 commit comments

Comments
 (0)