Closed
Description
Describe the bug
Our build suddenly started failing after upgrade to jsoncpp 1.9.5 with the following error:
CMake Error at C:/Jenkins/vcpkg/scripts/buildsystems/vcpkg.cmake:578 (_add_library):
_add_library cannot create imported target "JsonCpp::JsonCpp" because
another target with the same name already exists.
Call Stack (most recent call first):
C:/Jenkins/vcpkg/installed/x86-windows/share/jsoncpp/jsoncpp-namespaced-targets.cmake:5 (add_library)
C:/Jenkins/vcpkg/installed/x86-windows/share/jsoncpp/jsoncppConfig.cmake:31 (include)
C:/Jenkins/vcpkg/scripts/buildsystems/vcpkg.cmake:788 (_find_package)
To Reproduce
Have nested CMakeLists which at different places call find_package(jsoncpp)
Expected behavior
With 1.9.4 the build succeeds. All previous targets in jsoncpp-targets.cmake are protected against multiple definitions with something equivalent to "if (TARGET ) return() endif()". But the new target in jsoncpp-namespaced-targets.cmake is not similarly protected.
Potential solutions
Just adding
if (TARGET JsonCpp::JsonCpp)
return()
endif()
to jsoncpp-namespaced-targets.cmake seems to prevent the issue. If you want I can open a PR to that effect. #1306 might also fix it, I haven't tested that, yet.
Metadata
Metadata
Assignees
Labels
No labels