Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build starts to fail with 1.9.5 due to JsonCpp::JsonCpp target not protected against multi-include #1356

Closed
flichtenheld opened this issue Nov 17, 2021 · 5 comments · Fixed by #1435

Comments

@flichtenheld
Copy link

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.

dsommers pushed a commit to OpenVPN/openvpn3 that referenced this issue Nov 18, 2021
@Andres6936
Copy link

See #1374

@johnwason
Copy link

This is happening because the jsoncpp-namespaced-targets.cmake file is not checking if the target exists. A simple change adding a check to see if JsonCPP::JsonCPP is defined should fix this problem:

if (TARGET jsoncpp_static AND NOT TARGET JsonCpp::JsonCpp)
    add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
    set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_static")
elseif (TARGET jsoncpp_lib AND NOT TARGET JsonCpp::JsonCpp)
    add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
    set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib")
endif ()

@baylesj
Copy link
Contributor

baylesj commented Jan 22, 2023

What's left to resolve this issue? Seems like the original issue has been resolved and there may be some package resolution follow up work?

@flichtenheld
Copy link
Author

What's left to resolve this issue? Seems like the original issue has been resolved and there may be some package resolution follow up work?

I see no indication that the original issue has been resolved. All the references to merged PRs and commits here are from other projects working around the problem. Merging #1435 would fix it.

@JonasVautherin
Copy link

For the record, #1435 solves the problem for me 👍.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants