build: fix pkg-config requires

Issue #471
This commit is contained in:
John McNamara 2025-02-15 00:52:56 +00:00
parent ea6da0dace
commit 3a975c6b89
3 changed files with 29 additions and 4 deletions

View File

@ -211,16 +211,28 @@ if(NOT MSVC)
find_package(PkgConfig)
endif()
file(READ "include/xlsxwriter.h" ver)
# Set some variables for the xlsxwriter.pc file and the .so version.
# ------------------------------------------------------------------
set(PREFIX ${CMAKE_INSTALL_PREFIX})
file(READ "include/xlsxwriter.h" ver)
string(REGEX MATCH "LXW_VERSION \"([^\"]+)\"" _ ${ver})
set(VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "LXW_SOVERSION \"([^\"]+)\"" _ ${ver})
set(SOVERSION ${CMAKE_MATCH_1})
set(PREFIX ${CMAKE_INSTALL_PREFIX})
set(ENABLED_OPTIONS "zlib")
if(USE_SYSTEM_MINIZIP)
string(APPEND ENABLED_OPTIONS " minizip")
endif()
if(USE_OPENSSL_MD5)
string(APPEND ENABLED_OPTIONS " libcrypto")
endif()
# Expand out the xlsxwriter.pc file.
configure_file(dev/release/pkg-config.txt xlsxwriter.pc @ONLY)
# INCLUDES
# --------
enable_language(CXX)

View File

@ -21,6 +21,14 @@ PYTESTFILES ?= test
VERSION = $(shell sed -n -e 's/.*LXW_VERSION \"\(.*\)\"/\1/p' include/xlsxwriter.h)
SOVERSION = $(shell sed -n -e 's/.*LXW_SOVERSION \"\(.*\)\"/\1/p' include/xlsxwriter.h)
ENABLED_OPTIONS = zlib
ifdef USE_SYSTEM_MINIZIP
ENABLED_OPTIONS += minizip
endif
ifdef USE_OPENSSL_MD5
ENABLED_OPTIONS += libcrypto
endif
.PHONY: docs tags examples third_party
# Build libxlsxwriter.
@ -164,7 +172,11 @@ install: all
$(Q)mkdir -p $(DESTDIR)$(PREFIX)/lib
$(Q)cp -R lib/* $(DESTDIR)$(PREFIX)/lib
$(Q)mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig
$(Q)sed -e 's|@PREFIX@|$(PREFIX)|g' -e 's|@VERSION@|$(VERSION)|g' dev/release/pkg-config.txt > $(DESTDIR)$(PREFIX)/lib/pkgconfig/xlsxwriter.pc
$(Q)sed -e 's|@PREFIX@|$(PREFIX)|g' \
-e 's|@VERSION@|$(VERSION)|g' \
-e 's|@ENABLED_OPTIONS@|$(ENABLED_OPTIONS)|g' \
dev/release/pkg-config.txt \
> $(DESTDIR)$(PREFIX)/lib/pkgconfig/xlsxwriter.pc
# Simpler uninstall.
uninstall:

View File

@ -7,4 +7,5 @@ Name: libxlsxwriter
Description: A C library for creating Excel XLSX files
Version: @VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -lxlsxwriter -lz
Libs: -L${libdir} -lxlsxwriter
Requires.private: @ENABLED_OPTIONS@