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 find headers and libraries on macOS? #5

Open
Feuermurmel opened this issue Feb 17, 2018 · 1 comment
Open

Use pkg-config to find headers and libraries on macOS? #5

Feuermurmel opened this issue Feb 17, 2018 · 1 comment

Comments

@Feuermurmel
Copy link

Feuermurmel commented Feb 17, 2018

I tried to run the hello-window-1 example from the examples repository by naively typing swift run but got the following error:

[...]/01-hello-window-1$ swift run
[...]
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "shim.h"
        ^
[...]/01-hello-window-1/.build/checkouts/CGLFW3.git-2014552659416122263/shim.h:5:10: error: 'GLFW/glfw3.h' file not found
#include "GLFW/glfw3.h"
         ^
[...]/01-hello-window-1/main.swift:4:8: error: could not build Objective-C module 'CGLFW3'
import CGLFW3
       ^
error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f [...]/01-hello-window-1/.build/debug.yaml example.exe

I installed glfw using MacPorts. Adding the include and library directories on the command line solves the problem and let's the example run without modification: swift run -Xswiftc -I/opt/local/include -Xlinker -L/opt/local/lib. But this kinda sucks because I have to remember adding those options whenever I want to build or run my projects and Xcode does not automatically know about those directories either and I have to configure it there too.

I'm a complete novice when it comes to Swift package management but I noticed that adding pkgConfig: "glfw3" to CGLFW3's Package.swift allows me to run the example with just swift run and from within the generated Xcode project without any adjustments.

diff --git a/Package.swift b/Package.swift
index e1f46ee..cc1bbd3 100644
--- a/Package.swift
+++ b/Package.swift
@@ -1,5 +1,6 @@
 import PackageDescription
 
 let package = Package(
-    name: "CGLFW3"
+    name: "CGLFW3",
+    pkgConfig: "glfw3"
 )

Is there any downside to this? Otherwise it would IMHO greatly improve the experience of using this library on macOS.

@jkolb
Copy link
Member

jkolb commented Feb 17, 2018

I don't have experience with pkgConfig and to use it would require knowing it well enough to support Linux (major distros) and macOS (brew & macports) since SwiftGL supports both platforms. Also I'm not sure how it handles stuff like "-dev" packages on Linux. Lastly the current release version of GLFW has bugs in keyboard input that I ran into easily so I've been using a manually compiled 3.3 version which fixes those and I would recommend against not using the 3.2.1 version.

So the downside ends up being the time needed to learn pkgconfig, test and support all platforms, and still manage to use the 3.3 GLFW code which isn't installed by most package managers by default and usually has to be compiled and installed manually.

I have been working on this project to upgrade it to new versions of Swift as they are released and don't have much time for the integration side of things, so any help in that regard would be welcome. The newness of Swift Package Manager and the difficulties of cross platform develop make things hard unfortunately.

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

No branches or pull requests

2 participants