swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.75k stars 1.34k forks source link

[SR-7689] SwiftPM can not handle pkg-config file which contains `-D` options for cflags at all #4817

Open omochi opened 6 years ago

omochi commented 6 years ago
Previous ID SR-7689
Radar rdar://problem/40257646
Original Reporter @omochi
Type Bug
Environment macOS High Sierra version 10.13.4 iMac (retina 4K, 21.5-inch, 2017) Xcode 9.3 Homebrew 1.6.3 imagemagick: stable 7.0.7-31 (bottled)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 5af0917f7ede1519c735bf074c4a2f92

Issue Description:

SwiftPM can not handle pkg-config file which contains `-D` options for cflags at all.

In my investigation, `PackageLoading.whitelist` throws `PkgConfigError.nonWhitelistedFlags` if cflags in `*.pc` file contains `-D` style options and `PackageLoading.pkgConfigArgs(for: fileSystem🙂` which is a caller of `whitelist` returns error value of `PkgConfigResult`.

This is problem in a library actually exists.

For example, `MagickWand` distributed by homebrew in mac contains `-D` options.
This is programming interface of `ImageMagick` which is a very famous image processing tool.

$ cat /usr/local/lib/pkgconfig/MagickWand.pc
prefix=/usr/local/Cellar/imagemagick/7.0.7-27
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/ImageMagick-7
includearchdir=/usr/local/Cellar/imagemagick/7.0.7-27/include/ImageMagick-7
libname=MagickWand-7.Q16HDRI

Name: MagickWand
Description: MagickWand - C API for ImageMagick (ABI Q16HDRI)
URL: https://www.imagemagick.org
Version: 7.0.7
Requires: MagickCore
Cflags: -I${includearchdir} -I${includedir} -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16
Libs: -L${libdir} -l${libname}
Libs.private: -L${libdir} -l${libname}   -L/usr/local/opt/freetype/lib -lfreetype    -lxml2       -L/usr/local/Cellar/xz/5.2.3/lib -llzma -lbz2 -lz -lltdl  -lm      -lm
aciidgh commented 6 years ago

@swift-ci create

swift-ci commented 6 years ago

Comment by Brian Palmer (JIRA)

This is a problem with SDL2 as well, which has `-D_THREAD_SAFE` in its .pc file CLFAGS.

swift-ci commented 5 years ago

Comment by Tom Sullivan (JIRA)

Also an issue with `osxfuse`:

$ pkg-config --cflags osxfuse

-D_FILE_OFFSET_BITS=64 -D_DARWIN_USE_64_BIT_INODE -I/usr/local/include/osxfuse/fuse