4

I'm trying to marry swiftpm and .xcconfig files.

I've created Config.xcconfig file right next to my Package.swift file with two lines:

LIBRARY_SEARCH_PATHS = $(inherited) $(SRCROOT)/../3rdparty/mylib/.build/
OTHER_LDFLAGS = $(inherited) -lmylibRelease

But I still have 120 linkage errors, my guess is that swift build does not see my config file.

What should I do?

s1ddok
  • 4,615
  • 1
  • 18
  • 31

3 Answers3

9

SwiftPM support custom Xcode configs. You have to specify the path to your custom config file when invoking generate-xcodeproj command.
To see more details about generate-xcodeproj run swift package generate-xcodeproj -h

Example

swift package generate-xcodeproj --xcconfig-overrides Config.xcconfig
Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
Kostiantyn Koval
  • 8,407
  • 1
  • 45
  • 58
  • 2
    Ohh, so I cant use configs with `swift build`? Only XCode? – s1ddok Oct 27 '16 at 09:25
  • Yes thats right, and it makes sense. xcconfig is a Xcode config file and It can be used only by Xcode. If you need custom configs then you have to generate Xcode project and build it from there. – Kostiantyn Koval Oct 27 '16 at 09:28
  • 3
    My problem was that I couldn't find a way to pass additional library search paths etc. I end up using a bunch of `-Xlinker` stuff, but that ruins the whole thing because now it can't be used as a SwiftPM package. – s1ddok Oct 27 '16 at 09:31
  • 2
    @s1ddok have you found a better solution? I also need to add some LDFLAGS to swift build ... – Jan Sep 24 '17 at 20:23
  • 1
    warning: Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon. July ’21. – Max MacLeod Jul 14 '21 at 13:27
0

The appropriate way to specify a header search path, and linker flags, is to use the Package.swift struct values. They are provided for that very purpose.

For header search paths, use CSetting.

For linker flags, use LinkerSetting.

Full specification of Package.swift can be found at the PackageDescription API.

Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
-4

Xcode 11.3 supports now SPM with custom Xcode configurations.

Ugo Arangino
  • 2,802
  • 1
  • 18
  • 19