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.
This commit is contained in:
Mats Kindahl 2021-06-28 10:58:02 +02:00 committed by Mats Kindahl
parent 45a7abc4de
commit a3e8fd0497

View File

@ -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()