Format.cmake
Format.cmake copied to clipboard
`clang-format` target conflicts with other libraries
Would you consider allowing for OPTIONS/ENV that allows for a custom target for old libraries that happen to use the same build target?
I tried various CMake settings to avoid this but nothing seems to work. See CMP0002 using cmake_policy(SET CMP0002 OLD)
and or set(ALLOW_DUPLICATE_CUSTOM_TARGETS TRUE)
didn't work and there are many warnings not to do that.
I don't really want to fork either project just to fix this so I am hoping that because this project is specifically about adding clang-formating and the basis for many cpp projects with ModernCppStarter.
It's worth noting that that I don't have python installed so it's hitting https://github.com/TheLartians/Format.cmake/blob/15b0454f2a5a0b9e5099dfa1b1e80813da1c4cbd/CMakeLists.txt#L43
The full error:
CMake Error at cmake-build-debug/_deps/format.cmake-src/CMakeLists.txt:42 (add_custom_target):
add_custom_target cannot create target "clang-format" because another
target with the same name already exists. The existing target is a custom
target created in source directory
"C:/mosiac/all/cmake-build-debug/_deps/libzmq-src".
See documentation for policy CMP0002 for more details.
The CPM I am adding is
CPMAddPackage(
NAME libzmq
GIT_TAG v4.3.5
GITHUB_REPOSITORY zeromq/libzmq
OPTIONS
"BUILD_SHARED OFF"
)
Their target can be found in this file: https://github.com/zeromq/libzmq/blob/2a75ef07be0ba76f86592e10b999331cd6124d52/builds/cmake/Modules/ClangFormat.cmake#L18
Sure, I can see how an option like CLANG_FORMAT_TARGET_NAME
could be useful here. I'll be happy to review a PR that adds this option!