#1069·jsoncpp

CMake: Specify a DEBUG_LIBNAME_SUFFIX by default?

Author: nmlgcCreated Oct 24, 2019Updated May 15, 2026
Labelsbugbuild or testingbuild

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:

  1. Create a new CMake build configuration for any recent Visual Studio. Make sure that JSONCPP_WITH_CMAKE_PACKAGE is ON.
  2. 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
  1. The install directory will only have a single jsoncpp.lib, the one for the Release configuration.
  2. Include jsoncpp in your application like any other CMake package:
cmake
include("${JSONCPP_CMAKE_BUILD_PATH_FROM_STEP_ONE}/lib/cmake/jsoncpp/jsoncppConfig.cmake")
target_link_libraries(MyProject jsoncpp_lib)
  1. Linking a Debug version of MyProject fails, since the only existing jsoncpp.lib references 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…)

Source: open-source-parsers/jsoncpp