Skip to content

Generate CMake export set regardless of FMT_INSTALL#4850

Merged
vitaut merged 1 commit into
fmtlib:mainfrom
hexonal:fix-cmake-export-scope
Jul 20, 2026
Merged

Generate CMake export set regardless of FMT_INSTALL#4850
vitaut merged 1 commit into
fmtlib:mainfrom
hexonal:fix-cmake-export-scope

Conversation

@hexonal

@hexonal hexonal commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Closes #4806

export(TARGETS ...) is currently scoped inside if (FMT_INSTALL), so a project that pulls in fmt via add_subdirectory()/FetchContent without also installing it never gets the fmt::* import targets in its build tree. If that project then tries to export() one of its own targets that depends on fmt, CMake fails with:

CMake Error: export("MyLibTargets" ...) includes target "mylib" which requires target "fmt" that is not in any export set.

This moves the export() call, along with the INSTALL_TARGETS/targets_export_name it needs, outside the FMT_INSTALL guard 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 that fmt-config.cmake, fmt-config-version.cmake and fmt.pc are still only produced with FMT_INSTALL=ON.

Extended test/add-subdirectory-test with a small static library that publicly links fmt::fmt and exports itself. This reproduces the exact failure from the issue when FMT_INSTALL is off (the default when fmt is a subproject) and passes with this fix.

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
@hexonal
hexonal requested a review from vitaut as a code owner July 15, 2026 09:16
@vitaut
vitaut merged commit a749e9d into fmtlib:main Jul 20, 2026
46 checks passed
@vitaut

vitaut commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Thank you!

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.

export( should not be scoped by FMT_INSTALL

2 participants