Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pkg-config to get dependencies #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

snowkat
Copy link

@snowkat snowkat commented Nov 20, 2021

With this change, a pre-build script will get the library and header flags needed for dependencies from pkg-config instead of having them hardcoded. This has allowed for building on my system (ARCH=arm64) with xcodebuild and in Xcode.app.

Xcode seems to have a version of pkg-config in its $PATH that doesn't check Homebrew pkgconfig directories. To get around that, the build takes an argument HOMEBREW_ROOT which defaults to /opt/homebrew (the current default path) and can be overrode in xcodebuild or by modifying the scheme's arguments.

For some reason the pre-build script doesn't run by default on xcodebuild, and I had to explicitly define the scheme to get it to kick off consistently:

xcodebuild \
    -project PidginMacOSIntegration.xcodeproj \
    -scheme PidginMacOSIntegration \
    build

This uses an aggregate target with a Run Script and pkg-config to
generate OTHER_CFLAGS, OTHER_LDFLAGS, HEADER_SEARCH_PATHS, and
LIBRARY_SEARCH_PATHS instead of having them hardcoded in the plugin
configuration.
pkg-config points directly to the pidgin/ include subfolder, so we need
to change the imports to follow.

This also removes the (no longer needed) GtkTree and GtkWindow defines.
Generating the xcconfig as a target meant having to run the project
twice (once to generate the config and have the build fail, and another
time to actually pull the config values and build properly). Running as
a pre-action allows the config values to be pulled on the same build.
xcodebuild will fail if the file doesn't exist. It doesn't need to start
with content, it just needs to exist.
@Agalin
Copy link
Owner

Agalin commented Nov 22, 2021

Hi
Thanks, will check it next week, can't do it right now.

Copy link
Owner

@Agalin Agalin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually works well but automated generation seems to be missing. A few small suggestions too.

HEADER_SEARCH_PATHS="$(pkg-config $PACKAGES --cflags-only-I | sed 's/^-I//g;s/ -I/ /g')"
LIBRARY_SEARCH_PATHS="$(pkg-config $PACKAGES --libs-only-L | sed 's/^-L//g;s/ -L/ /g')"

cat <<EOF > "${PROJECT_DIR}/Dependencies.xcconfig"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should write to a file that is a part of the repository. That generated file should be in gitignore otherwise it makes fictional changes.

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that Apple has basically stopped supporting bash on macOS either pure sh or at least zsh would be a better idea.

@@ -0,0 +1,26 @@
#!/usr/bin/env bash

HOMEBREW_BIN="${HOMEBREW_ROOT:-/opt/homebrew}/bin"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does modern homebrew installation set this variable? Mine (a few years old) definitely didn't.

Anyway why not use brew config | grep "HOMEBREW_PREFIX:" | awk -F ' ' '{print $2}' or something similar to find it when env var is not set?

@@ -35,6 +35,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
9DFC539927488134005F0927 /* Dependencies.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Dependencies.xcconfig; sourceTree = "<group>"; };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some kind of a Run Script phase or similar config is missing - currently it doesn't run the script at all and that would be the expected behavior (and commits mention it).

After manually running the script with correct env vars (I can only hope that xcode sets correct project dir as of now) it builds correctly through both XCode and terminal command.

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.

2 participants