Skip to content

Add a pkg-config file for header-only usage - #3634

Merged
gabime merged 2 commits into
gabime:v1.xfrom
c-tonneslan:feat/header-only-pkgconfig
Jul 11, 2026
Merged

Add a pkg-config file for header-only usage#3634
gabime merged 2 commits into
gabime:v1.xfrom
c-tonneslan:feat/header-only-pkgconfig

Conversation

@c-tonneslan

Copy link
Copy Markdown
Contributor

Closes #3106.

spdlog.pc describes the compiled library: its CFlags include -DSPDLOG_COMPILED_LIB and its Libs link -lspdlog. A header-only consumer that pulls flags from pkg-config --cflags --libs spdlog therefore gets -DSPDLOG_COMPILED_LIB (which makes the headers expect a library to link) and -lspdlog (which may not be built), breaking the build.

This installs a companion spdlog_header_only.pc, generated from the spdlog_header_only INTERFACE target, so its defines and libs match header-only use: no -DSPDLOG_COMPILED_LIB, no -lspdlog (just the include dir and -pthread, plus SPDLOG_FMT_EXTERNAL / Requires: fmt when external fmt is selected, mirroring the existing .pc).

Verified the generated files with cmake -DSPDLOG_INSTALL=ON:

  • spdlog.pc — unchanged.
  • spdlog_header_only.pcCFlags: -I${includedir}, Libs: -L${libdir} -pthread.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>

Copilot AI 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.

Pull request overview

Adds a dedicated pkg-config file for spdlog_header_only to avoid leaking compiled-library flags (-DSPDLOG_COMPILED_LIB) and link requirements (-lspdlog) into header-only consumers using pkg-config.

Changes:

  • Generate and install a new spdlog_header_only.pc alongside the existing spdlog.pc.
  • Derive header-only CFlags compile definitions from the spdlog_header_only INTERFACE target when generating the new .pc.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
CMakeLists.txt Generates and installs a new header-only pkg-config file during SPDLOG_INSTALL.
cmake/spdlog_header_only.pc.in New pkg-config template for header-only consumption (include dir + flags, no -lspdlog).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CMakeLists.txt Outdated
URL: https://github.com/gabime/@PROJECT_NAME@
Version: @SPDLOG_VERSION@
CFlags: -I${includedir} @PKG_CONFIG_HO_DEFINES@
Libs: -L${libdir} -pthread
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@gabime
gabime merged commit 4122216 into gabime:v1.x Jul 11, 2026
14 checks passed
@gabime

gabime commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Thanks @c-tonneslan

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.

pkg-config file does not support spdlog_header_only

3 participants