CMake target with namespace
Is your feature request related to a problem? Please describe.
We found a case in our CMake script where jsoncpp, rather than jsoncpp_lib, is mistakenly used in target_link_libraries().
As a result, a system installed jsoncpp is linked by -ljsoncpp, not what we found with find_package().
Describe the solution you'd like
I think the more popular solution is to create namespaced targets like jsoncpp::shared and jsoncpp::static, and maybe also jsoncpp::jsoncpp pointing to the default.
Describe alternatives you've considered
Add a target jsoncpp equivalent to jsoncpp::jsoncpp mentioned above, to shadow the file version of jsoncpp.
I don't know much about cmake namespace target, but I'll investigate it late. And for now, can you see if this PR https://github.com/open-source-parsers/jsoncpp/pull/1214 can solve your problem?
Not really. What I mean is more like this: https://github.com/google/glog/blob/c8f8135a5720aee7de8328b42e4c43f8aa2e60aa/CMakeLists.txt#L542 https://github.com/google/glog/blob/c8f8135a5720aee7de8328b42e4c43f8aa2e60aa/CMakeLists.txt#L850
I mention namespacing because, when people see jsoncpp or jsoncpp_lib in target_link_libraries(), it's hard to tell whether it's a file or target.
Although the intention is to use target, when editing around people can easily make mistakes and write it as jsoncpp, which can still "work" when linker found a file matching the name.
We want to avoid this.
See #1374