open-source-parsers / open-source-parsers/jsoncpp
CMake: Specify a DEBUG_LIBNAME_SUFFIX by default?
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.9k
- Forks
- 2.7k
- Avg merge
- 31m
- Merged PRs (30d)
- 1
Description
Describe the bug
When doing a CMake install of both Debug and Release versions into the same directory (which is the typical case, at least on Windows), the library of the configuration installed last overwrites the one installed last.
To Reproduce
Steps to reproduce the behavior:
- Create a new CMake build configuration for any recent Visual Studio. Make sure that
JSONCPP_WITH_CMAKE_PACKAGEisON. - Install both Debug and Release versions. From the command line, it'd be
cmake --build . --target install --config Debug
cmake --build . --target install --config Release
- The install directory will only have a single
jsoncpp.lib, the one for the Release configuration. - Include jsoncpp in your application like any other CMake package:
include("${JSONCPP_CMAKE_BUILD_PATH_FROM_STEP_ONE}/lib/cmake/jsoncpp/jsoncppConfig.cmake")
target_link_libraries(MyProject jsoncpp_lib)
- Linking a Debug version of
MyProjectfails, since the only existingjsoncpp.libreferences the Release version of the C++ runtime.
Expected behavior
Both configurations should work from the same install, without requiring any more CMake code from users of the library.
Desktop (please complete the following information):
- OS: Windows 10
- CMake version: 3.15.4
Additional context
This is probably what #833 was mainly about. Setting a suffix upstream seems to be the best practice for handling this – at least that's what curl ended up doing after quite a bit of discussion on their issue tracker (see https://github.com/curl/curl/pull/1857#pullrequestreview-66306386 and the other issues linked from there).
I would have made this a pull request, but apparently, doing this breaks CMake's own Find* modules, which then need to be manually made aware of the change, effectively requiring a new CMake version for the change to fully propagate. So I guess I just leave this here as a bug report, and a notice for everyone affected to keep working around this issue…
If this is fixed though, it would be even better stylistically to use the standard CMAKE_DEBUG_POSTFIX variable in the same way curl does it (see https://github.com/curl/curl/issues/2121#issuecomment-374253607). Searching for DEBUG_LIBNAME_SUFFIX on both GitHub and Google reveals that it has become jsoncpp's own "not invented here" version of the same feature. (Then again, as a custom variable, it is shown in the GUI, unlike CMAKE_DEBUG_POSTFIX…)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the CMake package configuration enabled by JSONCPP_WITH_CMAKE_PACKAGE and reproduce the Debug and Release install commands from the report. Compare DEBUG_LIBNAME_SUFFIX with CMAKE_DEBUG_POSTFIX and check the generated jsoncppConfig.cmake entry point. Done means both configurations can be installed together and a Debug consumer links successfully without extra CMake code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100