Generate CMake export set regardless of FMT_INSTALL#4850
Merged
Conversation
export() was scoped inside if (FMT_INSTALL), so projects that pull in fmt via add_subdirectory()/FetchContent without installing it had no way to get the exported fmt::* targets. If such a project tries to export its own targets that depend on fmt, CMake fails with "target ... requires target fmt that is not in any export set". Hoist the target list/export name and the export() call itself out of the FMT_INSTALL guard so the build-tree export file is always generated; the install()-only pieces (config/version files, pkgconfig, install(EXPORT ...)) stay behind the guard and installed behavior is unchanged. Fixes fmtlib#4806
vitaut
approved these changes
Jul 20, 2026
Contributor
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4806
export(TARGETS ...)is currently scoped insideif (FMT_INSTALL), so a project that pulls in fmt viaadd_subdirectory()/FetchContentwithout also installing it never gets thefmt::*import targets in its build tree. If that project then tries toexport()one of its own targets that depends on fmt, CMake fails with:This moves the
export()call, along with theINSTALL_TARGETS/targets_export_nameit needs, outside theFMT_INSTALLguard so it always runs. Everything that's actually install-specific (config/version files, pkg-config,install(EXPORT ...)) stays behind the guard, so installed behavior is unchanged — confirmed thatfmt-config.cmake,fmt-config-version.cmakeandfmt.pcare still only produced withFMT_INSTALL=ON.Extended
test/add-subdirectory-testwith a small static library that publicly linksfmt::fmtand exports itself. This reproduces the exact failure from the issue whenFMT_INSTALLis off (the default when fmt is a subproject) and passes with this fix.