From a3e8fd0497d7f54e476d02c0969f6de256784d44 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Mon, 28 Jun 2021 10:58:02 +0200 Subject: [PATCH] Always define 'format' target If `clang-format` is not found `CLANG_FORMAT` will be set to a false value, which will prevent the `format` target from being defined if `cmake-format` is not installed. This commit fixes that by always creating a `format` target since `clang-format` is always created even if `CLANG_FORMAT` is false. We do not redefine `CLANG_FORMAT` to a non-false value since it is expected to contain a path to an executable and if set to a true value that is not a path it could be used in a way that leads to strange errors. --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90412d228..ed036e2ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -440,10 +440,12 @@ if(CMAKE_FORMAT) ${PROJECT_SOURCE_DIR}/scripts/cmake_format_all.sh) endif() -if(CMAKE_FORMAT OR CLANG_FORMAT) +if(TARGET clang-format OR TARGET cmake-format) add_custom_target(format) - add_dependencies(format clang-format) - if(CMAKE_FORMAT) + if(TARGET clang-format) + add_dependencies(format clang-format) + endif() + if(TARGET cmake-format) add_dependencies(format cmake-format) endif() endif()