Skip to content

Find jsoncpp through pkg-config when its CMake target is missing - #1501

Open
aeron-gh wants to merge 1 commit into
p4lang:mainfrom
aeron-gh:jsoncpp-pkg-config-fallback
Open

aeron-gh wants to merge 1 commit into
p4lang:mainfrom
aeron-gh:jsoncpp-pkg-config-fallback

Conversation

@aeron-gh

@aeron-gh aeron-gh commented Dec 5, 2026

Copy link
Copy Markdown
Member

Fixes #1489.

The CMake build finds jsoncpp only through jsoncpp's CMake package file and then links JsonCpp::JsonCpp. That breaks in two cases:

  • No package file. Arch's jsoncpp (1.9.8) ships only jsoncpp.pc, so configure stops at CMakeLists.txt:107 (details in CMake configure fails where jsoncpp has no CMake package file (Arch Linux) #1489).
  • A package file without that target. Ubuntu 20.04's libjsoncpp-dev (1.7.4-3.1ubuntu2) only defines jsoncpp_lib and jsoncpp_lib_static; the 1.9.5 package in Ubuntu 24.04 adds JsonCpp::JsonCpp in jsoncpp-namespaced-targets.cmake. Without it, configure fails with Target "bmsim" links to: JsonCpp::JsonCpp and the same for every other target that links jsoncpp.

This keeps find_package(jsoncpp) (now QUIET). If it does not provide JsonCpp::JsonCpp, the target is defined on top of jsoncpp's pkg-config data instead, which is also how configure.ac finds jsoncpp. Where the package file defines the target, as with the 1.9.5 package in CI, nothing changes.

Testing

Arch Linux, CMake 4.4.4, jsoncpp 1.9.8:

  • Before: configure fails as in CMake configure fails where jsoncpp has no CMake package file (Arch Linux) #1489. After: configure, a full build and ctest work without any workaround. 50/51 tests pass; test_switch fails because the Python thrift module is not installed here.
  • The generated build.ninja is the same as main configured with a local Findjsoncpp.cmake doing the same pkg-config lookup, except for the rule that re-runs CMake. Same with -DENABLE_PACKET_TRACE=ON -DENABLE_WERROR=ON.
  • A jsoncppConfig.cmake placed on CMAKE_PREFIX_PATH is still loaded first.
  • With a package file that only defines jsoncpp_lib, like Ubuntu 20.04's, main fails with the error above and this branch configures. I checked the Ubuntu 20.04 and 24.04 packages by unpacking them, not on those systems.
  • The new block configures and builds a small jsoncpp program with CMake 3.10.3, the version in cmake_minimum_required.

Signed-off-by: Abhishek Agarwal <agab0323@gmail.com>
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 this pull request may close these issues.

CMake configure fails where jsoncpp has no CMake package file (Arch Linux)

1 participant