Skip to content

fix detecting & using utf8c++ 4.0.0 or newer#346

Open
mbunkus wants to merge 1 commit into
v1.xfrom
v1.x-fix-cmake-utf8cpp
Open

fix detecting & using utf8c++ 4.0.0 or newer#346
mbunkus wants to merge 1 commit into
v1.xfrom
v1.x-fix-cmake-utf8cpp

Conversation

@mbunkus

@mbunkus mbunkus commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

find_package with version constraint 3.2.0 does not consider 4.x.y to be compatible. Therefore also look for 4.x.y in a secondary find_package call.

The fallback for cloning from git if neither version is found via cmake remains in place.

Furthermore, linking against a distro-provided 4.x.y doesn't seem to work with the existing target_link_libraries(ebml PRIVATE $<BUILD_INTERFACE:utf8cpp>) & requires PRIVATE utf8cpp::utf8cpp. However, that doesn't work with a git-cloned copy; that still requires PRIVATE $<BUILD_INTERFACE:utf8cpp>; so make that argument depend on the package detection, too.

fixes #344 ; see #345

@mbunkus

mbunkus commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Soooooo… it seems my solution doesn't actually work with a distro-packaged 3.x. Interesting. Will have to switch that case back to PRIVATE $<BUILD_INTERFACE:utf8cpp>, too? Maaaaan I just have no clue about cmake… 😂

@mbunkus
mbunkus force-pushed the v1.x-fix-cmake-utf8cpp branch from 6cbbd23 to 67a2dbb Compare July 21, 2026 17:45
@mbunkus

mbunkus commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Alright, 67a2dbb works fine on:

  • Ubuntu 24.04 with distro-packaged 3.2.x
  • Ubuntu 26.04 with distro-packaged 4.0.x
  • Ubuntu 26.04 without distro-packaged, cloning from git

…and the checks agree.

@marillat & @ReillyBrogan I'd appreciate some testing on your end, too. Thanks a lot!

@mbunkus

mbunkus commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

While we're at it we could also bump the version we get from git in case of "no distro-packaged found" to 4.0.x & use PRIVATE utf8cpp::utf8cpp there, too. Thoughts?

@marillat

Copy link
Copy Markdown

Build fine for me, but with a cmake warning:

CMake Warning at CMakeLists.txt:52 (find_package):
  Could not find a configuration file for package "utf8cpp" that is
  compatible with requested version "3.2.0".

  The following configuration files were considered but not accepted:

    /usr/share/cmake/utf8cpp/utf8cppConfig.cmake, version: 4.1.0
      The version found is not compatible with the version requested.

@robUx4

robUx4 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Build fine for me, but with a cmake warning:

There is a QUIET parameter that could be used, in both calls. In the end we show in the summary what we are using (system or internal).

@robUx4 robUx4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for me. We need the same in the master branch.

@robUx4

robUx4 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

After rebasing on v1.x we should see in the CI that the 4.x.x version is properly picked.

@ReillyBrogan

Copy link
Copy Markdown

Build fine for me, but with a cmake warning:

There is a QUIET parameter that could be used, in both calls. In the end we show in the summary what we are using (system or internal).

Speaking as a packager I usually check the cmake output to see what new dependencies I may need to add to the build recipe. So at least one of them should continue to be not-QUIET so it's noticeable in the output.

But honestly looking at repology utf8cpp >= 4.0 is already very widespread in the various distribution repos. It's in the latest stable Debian, the latest LTS Ubuntu, all supported Fedora releases, etc. Given that libebml appears to compile and work with it just fine why not just require 4.0 unconditionally? If a user is on a distribution that doesn't have it they can just enable networking so that fetch_content can pull down a 4.0 release.

Another approach that could be used here is to use alias targets instead.

Something like this:

if(NOT utf8cpp_FOUND)
  include(FetchContent REQUIRED)
  FetchContent_Declare(
        utf8cpp
        GIT_REPOSITORY https://github.com/nemtrif/utfcpp.git
        GIT_TAG v3.2.5
        GIT_PROGRESS TRUE
        DOWNLOAD_EXTRACT_TIMESTAMP ON
        OVERRIDE_FIND_PACKAGE
    )
    FetchContent_MakeAvailable(utf8cpp)
    add_library(utf8cpp::utf8cpp ALIAS utf8cpp)
endif()

...

target_link_libraries(ebml PRIVATE utf8cpp::utf8cpp)

(note that I'm not sure what target the fetch_content for utf8cpp actually exports so that might need to be adjusted).

Then if utf8cpp is ever referenced anywhere else in cmake you can just use utf8cpp::utf8cpp and it will use the system or vendored version correctly.

`find_package` with version constraint `3.2.0` does not consider 4.x.y
to be compatible. Therefore also look for 4.x.y in a secondary
`find_package` call.

The fallback for cloning from git if neither version is found via
`cmake` remains in place.

Furthermore, linking against a distro-packaged 4.x.y doesn't seem to
work with the existing `target_link_libraries(ebml PRIVATE
$<BUILD_INTERFACE:utf8cpp>)` & requires `PRIVATE
utf8cpp::utf8cpp`. However, that doesn't work with a git-cloned copy
nor with distro-packaged 3.2.x as those still requires `PRIVATE
$<BUILD_INTERFACE:utf8cpp>`.

Therefore make the argument depend on availability of the
`utf8cpp::utf8cpp` target: it is available only for distro-packaged
4.x.y. For the other two cases (distro-packaged < 4.x.y & cloned from
git) we stay with `$<BUILD_INTERFACE:utf8cpp>`.

fixes #344 ; see #345
@mbunkus
mbunkus force-pushed the v1.x-fix-cmake-utf8cpp branch from 67a2dbb to 7cf88e1 Compare July 22, 2026 18:00
@mbunkus

mbunkus commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Thank y'all very much for your feedback. I've taken it into account & produced a new version that

a) gets rid of the version requirement altogether and
b) makes then link thingy to use depend on the availability of the utf8cpp::utf8cpp target instead of the version number/git clone status.

As for the version requirement: I had investigated using QUIET, but I wasn't a fan. Yes, it gets rid of the warnings, but I concur with @ReillyBrogan that having some kind of warning if neither is found is definitely required. Furthermore, QUIET also gets rid of the message that cmake is using the package if it is found, which I also disliked.

Therefore I opt not to restrict the version number at all. At the moment all known-deployed versions work just fine, and I say that we just deal with the bug reports of something breaking with utf8cpp 5.whatever when those come in.

Furthermore, there are two cases wrt. the target to use:

  • version ≥ 4 which requires utf8cpp::utf8cpp and
  • version < 4 (either distro-packaged or from git as we check out a specific version < 4) which requires the existing one

Given that version ≥ 4 is the future, we can simply check if the target utf8cpp::utf8cpp is known to cmake with if(TARGET utf8cpp::utf8cpp) & use that if so, otherwise the old one.

…and while I write this I realize I could've simply moved that check to the location of target_link_libraries(), duplicated that call in the two branches & not used a variable. Might have been nicer.

As before I've verified this to be working on:

  • Ubuntu 26.04 with distro-packaged 4.0.x
  • Ubuntu 24.04 with distro-packaged 3.2.y
  • Ubuntu 26.04 without distro-packaged, meaning git-cloned

In the meantime @robUx4 has also added some more checks which now test for some of the same combinations, too.

Again I'd appreciate some feedback before I merge this (and do the same for the master branch — I will do that once we've settled on a specific implementation).

@mbunkus

mbunkus commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Oh, BTW, I wasn't able to make the add_library(utf8cpp::utf8cpp ALIAS utf8cpp) call suggested by @ReillyBrogan work with v3.2.something, unfortunately. Most likely due to my lack of cmake knowledge.

@robUx4 robUx4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of dropping the version check but I guess if that ever happens some distro will find out and reach out to us (but they usually silently patch).

@marillat

Copy link
Copy Markdown

Build fine for me with commit 7cf88e1

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.

4 participants