Skip to content

Upstream Packaging Issue: Missing Installation of Public Header in pystring CMake Build #57

@hkunz

Description

@hkunz

We have pystring.mk that will cross compile pystring using MXE

# This file is part of MXE. See LICENSE.md for licensing information.

include src/common/pkgutils.mk

PKG             := pystring
$(PKG)_WEBSITE  := https://github.com/imageworks/pystring.git
$(PKG)_DESCR    := C++ functions matching the interface and behavior of python string methods with std::string
$(PKG)_VERSION  := 1.1.4
$(PKG)_IGNORE   :=
$(PKG)_CHECKSUM := 49da0fe2a049340d3c45cce530df63a2278af936003642330287b68cefd788fb
$(PKG)_GH_CONF  := imageworks/pystring/tags,v
$(PKG)_DEPS     := cc

define $(PKG)_BUILD

	# configure package with cmake
	cd "$(BUILD_DIR)" && "$(TARGET)-cmake" "$(SOURCE_DIR)" \
		-DCMAKE_INSTALL_PREFIX="$(PREFIX)/$(TARGET)" \
		-DCMAKE_PREFIX_PATH="$(PREFIX)/$(TARGET)" \
		-DBUILD_SHARED_LIBS=$(CMAKE_SHARED_BOOL) \
		-DCMAKE_BUILD_TYPE=Release

	# build package and install
	$(MAKE) -C "$(BUILD_DIR)" -j $(JOBS)
	$(MAKE) -C "$(BUILD_DIR)" -j 1 install

	# Only needed if the project does not ship a .pc file like pystring
	$(call GENERATE_PC, \
		$(PREFIX)/$(TARGET), \
		$(PKG), \
		$($(PKG)_DESCR), \
		$($(PKG)_VERSION), \
		, \
		, \
		-lpystring, \
	)

	# compile a test program to verify the library is usable
	"$(TARGET)-g++" -Wall -Wextra "$(TEST_FILE)" \
		-o "$(PREFIX)/$(TARGET)/bin/test-$(PKG).exe" \
		`"$(TARGET)-pkg-config" "$(PKG)" --cflags --libs`
endef

But this will generate only

$ find usr/x86_64-w64-mingw32.static/ | grep -i "pystring"
usr/x86_64-w64-mingw32.static/installed/pystring
usr/x86_64-w64-mingw32.static/lib/libpystring.dll.a
usr/x86_64-w64-mingw32.static/lib/pkgconfig/pystring.pc
usr/x86_64-w64-mingw32.static/bin/libpystring.dll

Notice that pystring.h is missing. So we have to script an additional line that does copy cp '$(SOURCE_DIR)/pystring.h' into '$(PREFIX)/$(TARGET)/include/pystring/ because cmake doesn't automatically install it. This doesn't look like an MXE configuration problem so I assume it's a pystring cmake install bug?

Here is the final makefile that works with the manual copy:

# This file is part of MXE. See LICENSE.md for licensing information.

include src/common/pkgutils.mk

PKG             := pystring
$(PKG)_WEBSITE  := https://github.com/imageworks/pystring.git
$(PKG)_DESCR    := C++ functions matching the interface and behavior of python string methods with std::string
$(PKG)_VERSION  := 1.1.4
$(PKG)_IGNORE   :=
$(PKG)_CHECKSUM := 49da0fe2a049340d3c45cce530df63a2278af936003642330287b68cefd788fb
$(PKG)_GH_CONF  := imageworks/pystring/tags,v
$(PKG)_DEPS     := cc

define $(PKG)_BUILD

	# configure package with cmake
	cd "$(BUILD_DIR)" && "$(TARGET)-cmake" "$(SOURCE_DIR)" \
		-DCMAKE_INSTALL_PREFIX="$(PREFIX)/$(TARGET)" \
		-DCMAKE_PREFIX_PATH="$(PREFIX)/$(TARGET)" \
		-DBUILD_SHARED_LIBS=$(CMAKE_SHARED_BOOL) \
		-DCMAKE_BUILD_TYPE=Release

	# build package and install
	$(MAKE) -C "$(BUILD_DIR)" -j $(JOBS)
	$(MAKE) -C "$(BUILD_DIR)" -j 1 install

	mkdir -p '$(PREFIX)/$(TARGET)/include/pystring'
	cp '$(SOURCE_DIR)/pystring.h' '$(PREFIX)/$(TARGET)/include/pystring/'  # this workaround fixes the problem.

	# Only needed if the project does not ship a .pc file
	$(call GENERATE_PC, \
		$(PREFIX)/$(TARGET), \
		$(PKG), \
		$($(PKG)_DESCR), \
		$($(PKG)_VERSION), \
		, \
		, \
		-lpystring, \
	)

	# compile a test program to verify the library is usable
	"$(TARGET)-g++" -Wall -Wextra "$(TEST_FILE)" \
		-o "$(PREFIX)/$(TARGET)/bin/test-$(PKG).exe" \
		`"$(TARGET)-pkg-config" "$(PKG)" --cflags --libs`
endef

Now the result is correct with a test-pystring.exe possible since we now have pystring.h

 $ find usr/x86_64-w64-mingw32.static/ | grep -i "pystring"
usr/x86_64-w64-mingw32.static/include/pystring
usr/x86_64-w64-mingw32.static/include/pystring/pystring.h
usr/x86_64-w64-mingw32.static/installed/pystring
usr/x86_64-w64-mingw32.static/lib/libpystring.dll.a
usr/x86_64-w64-mingw32.static/lib/pkgconfig/pystring.pc
usr/x86_64-w64-mingw32.static/bin/test-pystring.exe
usr/x86_64-w64-mingw32.static/bin/libpystring.dll
$

Here's the test compilation cpp file:

/*
    Minimal test program for pystring, verifying basic functionality
    and compatibility with MXE static builds on Windows.

    To compile with MXE (example):

    ./usr/bin/x86_64-w64-mingw32.static-g++ \
        src/pystring-test.cpp \
        -I usr/x86_64-w64-mingw32.static/include \
        -L usr/x86_64-w64-mingw32.static/lib \
        -lpystring \
        -o usr/x86_64-w64-mingw32.static/bin/test-pystring.exe
*/

#include <iostream>
#include <vector>
#include <string>
#include <pystring/pystring.h>

int main() {
    std::string s = "one,two,three";
    std::vector<std::string> parts;

    pystring::split(s, parts, ",");

    for (auto &p : parts)
        std::cout << p << "\n";

    std::cout << "PyString library link test succeeded.\n";
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions