Skip to content

Commit 2f192bf

Browse files
committed
Revert the default x265 support with the optional integrate way on SPM/Carthage
1 parent 3bcf8ae commit 2f192bf

File tree

4 files changed

+91
-55
lines changed

4 files changed

+91
-55
lines changed

Package.resolved

-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99
"revision": "3410ee6f5f496681c545229e716f305862b4b5ac",
1010
"version": "1.0.15"
1111
}
12-
},
13-
{
14-
"package": "libx265",
15-
"repositoryURL": "https://github.com/SDWebImage/libx265-Xcode.git",
16-
"state": {
17-
"branch": null,
18-
"revision": "c8df330791e353c7ed5034bc4784eb0ee8c3d6ee",
19-
"version": "3.4.0"
20-
}
2112
}
2213
]
2314
},

Package.swift

+63-37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,65 @@
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
5+
import Foundation
6+
7+
let HAVE_X265: Bool = ProcessInfo.processInfo.environment["HAVE_X265"] == "1"
8+
9+
var packageDependencies: [PackageDescription.Package.Dependency] = [
10+
.package(url: "https://github.com/SDWebImage/libde265-Xcode.git", from: "1.0.9")
11+
]
12+
var targetDependencies: [PackageDescription.Target.Dependency] = ["libde265"]
13+
var exclude: [String] = ["libheif/libheif/plugins_unix.h",
14+
"libheif/libheif/plugins_unix.cc",
15+
"libheif/libheif/plugins_windows.h",
16+
"libheif/libheif/plugins_windows.cc",
17+
"libheif/libheif/plugins/encoder_aom.h",
18+
"libheif/libheif/plugins/encoder_aom.cc",
19+
"libheif/libheif/plugins/decoder_aom.h",
20+
"libheif/libheif/plugins/decoder_aom.cc",
21+
"libheif/libheif/plugins/decoder_dav1d.h",
22+
"libheif/libheif/plugins/decoder_dav1d.cc",
23+
"libheif/libheif/plugins/encoder_rav1e.h",
24+
"libheif/libheif/plugins/encoder_rav1e.cc",
25+
"libheif/libheif/plugins/encoder_svt.h",
26+
"libheif/libheif/plugins/encoder_svt.cc",
27+
"libheif/libheif/plugins/encoder_openjpeg.h",
28+
"libheif/libheif/plugins/encoder_openjpeg.cc",
29+
"libheif/libheif/plugins/decoder_openjpeg.h",
30+
"libheif/libheif/plugins/decoder_openjpeg.cc",
31+
"libheif/libheif/plugins/encoder_jpeg.h",
32+
"libheif/libheif/plugins/encoder_jpeg.cc",
33+
"libheif/libheif/plugins/decoder_jpeg.h",
34+
"libheif/libheif/plugins/decoder_jpeg.cc",
35+
"libheif/libheif/plugins/encoder_ffmpeg.h",
36+
"libheif/libheif/plugins/encoder_ffmpeg.cc",
37+
"libheif/libheif/plugins/decoder_ffmpeg.h",
38+
"libheif/libheif/plugins/decoder_ffmpeg.cc",
39+
"libheif/libheif/plugins/encoder_kvazaar.h",
40+
"libheif/libheif/plugins/encoder_kvazaar.cc",
41+
"libheif/libheif/plugins/encoder_svt.h",
42+
"libheif/libheif/plugins/encoder_svt.cc"
43+
]
44+
var defines : [CSetting] = [
45+
.define("HAVE_UNISTD_H"),
46+
.define("HAVE_LIBDE265")
47+
]
48+
if HAVE_X265 {
49+
packageDependencies += [
50+
.package(url: "https://github.com/SDWebImage/libx265-Xcode.git", from: "3.4.0")
51+
]
52+
targetDependencies += [
53+
"libx265"
54+
]
55+
defines += [
56+
.define("HAVE_X265")
57+
]
58+
} else {
59+
exclude += [
60+
"libheif/libheif/plugins/encoder_x265.h",
61+
"libheif/libheif/plugins/encoder_x265.cc"
62+
]
63+
}
564

665
let package = Package(
766
name: "libheif",
@@ -14,51 +73,18 @@ let package = Package(
1473
name: "libheif",
1574
targets: ["libheif"]),
1675
],
17-
dependencies: [
18-
// Dependencies declare other packages that this package depends on.
19-
.package(url: "https://github.com/SDWebImage/libde265-Xcode.git", from: "1.0.9"),
20-
.package(url: "https://github.com/SDWebImage/libx265-Xcode.git", from: "3.4.0")
21-
],
76+
dependencies: packageDependencies,
2277
targets: [
2378
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2479
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2580
.target(
2681
name: "libheif",
27-
dependencies: ["libde265", "libx265"],
82+
dependencies: targetDependencies,
2883
path: ".",
29-
exclude: ["libheif/libheif/plugins_unix.h",
30-
"libheif/libheif/plugins_unix.cc",
31-
"libheif/libheif/plugins_windows.h",
32-
"libheif/libheif/plugins_windows.cc",
33-
"libheif/libheif/plugins/encoder_aom.h",
34-
"libheif/libheif/plugins/encoder_aom.cc",
35-
"libheif/libheif/plugins/decoder_aom.h",
36-
"libheif/libheif/plugins/decoder_aom.cc",
37-
"libheif/libheif/plugins/decoder_dav1d.h",
38-
"libheif/libheif/plugins/decoder_dav1d.cc",
39-
"libheif/libheif/plugins/encoder_rav1e.h",
40-
"libheif/libheif/plugins/encoder_rav1e.cc",
41-
"libheif/libheif/plugins/encoder_svt.h",
42-
"libheif/libheif/plugins/encoder_svt.cc",
43-
"libheif/libheif/plugins/encoder_openjpeg.h",
44-
"libheif/libheif/plugins/encoder_openjpeg.cc",
45-
"libheif/libheif/plugins/decoder_openjpeg.h",
46-
"libheif/libheif/plugins/decoder_openjpeg.cc",
47-
"libheif/libheif/plugins/encoder_jpeg.h",
48-
"libheif/libheif/plugins/encoder_jpeg.cc",
49-
"libheif/libheif/plugins/decoder_jpeg.h",
50-
"libheif/libheif/plugins/decoder_jpeg.cc",
51-
"libheif/libheif/plugins/encoder_ffmpeg.h",
52-
"libheif/libheif/plugins/encoder_ffmpeg.cc",
53-
"libheif/libheif/plugins/decoder_ffmpeg.h",
54-
"libheif/libheif/plugins/decoder_ffmpeg.cc",
55-
"libheif/libheif/plugins/encoder_kvazaar.h",
56-
"libheif/libheif/plugins/encoder_kvazaar.cc",
57-
"libheif/libheif/plugins/encoder_svt.h",
58-
"libheif/libheif/plugins/encoder_svt.cc"],
84+
exclude: exclude,
5985
sources: ["libheif/libheif"],
6086
publicHeadersPath: "include",
61-
cSettings: [.headerSearchPath("libheif"), .define("HAVE_UNISTD_H"), .define("HAVE_LIBDE265"), .define("HAVE_X265")]
87+
cSettings: [.headerSearchPath("libheif")] + defines
6288
)
6389
],
6490
cLanguageStandard: .gnu11,

README.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,40 @@ let package = Package(
5353

5454
libheif itself is not a full function decoder but an abstract layer. It needs [libde265](http://www.libde265.org/) for HEIF decoder support, and [x265](http://x265.org/) for HEIF encoder support.
5555

56+
Note: Since most of people's usage of this library is for HEIF decoding, and `x265` is under GPLv2 license, we only integrate libheif with [libde265-Xcode](https://github.com/SDWebImage/libde265-Xcode) on Carthage/SwiftPM package manager. If you want x265 with HEIF encoding support, read below carefully.
57+
58+
### x265 on CocoaPods
59+
5660
For CocoaPods user, you can use `libx265` subspec to integrate the x265 codec supports for HEIF encoding.
5761

5862
```ruby
5963
pod 'libheif', :subspecs => ['libde265', 'libx265']
6064
```
6165

62-
Since most of people's usage of this library is for HEIF decoding, and `x265` is under GPLv2 license, we only integrate libheif with the Carthage dependency [libde265-Xcode](https://github.com/SDWebImage/libde265-Xcode). To use x265 for HEIF encoding, try to build it by your own.
66+
### x265 on Carthage
67+
68+
For Carthage user, export the environment (using bash profile or xcconfig if you want) `HAVE_X265=1`, and modify carthage's xcconfig about `GCC_PREPROCESSOR_DEFINITIONS` to build.
69+
70+
You can use the shell script to spawn carthage, like run via `carthage_build_with_x265.sh build`
71+
72+
```bash
73+
#!/bin/bash -e
74+
xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
75+
echo "GCC_PREPROCESSOR_DEFINITIONS = $(inherited) HAVE_X265=1" >> $xcconfig
76+
77+
export XCODE_XCCONFIG_FILE="$xcconfig"
78+
79+
carthage "$@"
80+
```
81+
82+
### x265 on SwiftPM
83+
84+
For SPM user, export the environment (using bash profile or xcconfig if you want) `HAVE_X265=1`, and use `xcodebuild` or `swift build` to build.
85+
86+
```bash
87+
mv libheif.xcodeproj libheif.xcodeproj.bak
88+
HAVE_X265=1 xcodebuild build -scheme libheif -sdk macosx -destination "generic/platform=macOS"
89+
```
6390

6491
## AVIF Decoding
6592

libheif.xcodeproj/project.pbxproj

-8
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,6 @@
14161416
GCC_PREPROCESSOR_DEFINITIONS = (
14171417
"DEBUG=1",
14181418
"HAVE_LIBDE265=1",
1419-
"HAVE_X265=1",
14201419
"HAVE_UNISTD_H=1",
14211420
"$(inherited)",
14221421
);
@@ -1452,7 +1451,6 @@
14521451
FRAMEWORK_VERSION = A;
14531452
GCC_PREPROCESSOR_DEFINITIONS = (
14541453
"HAVE_LIBDE265=1",
1455-
"HAVE_X265=1",
14561454
"HAVE_UNISTD_H=1",
14571455
"$(inherited)",
14581456
);
@@ -1513,7 +1511,6 @@
15131511
GCC_PREPROCESSOR_DEFINITIONS = (
15141512
"DEBUG=1",
15151513
"HAVE_LIBDE265=1",
1516-
"HAVE_X265=1",
15171514
"HAVE_UNISTD_H=1",
15181515
"$(inherited)",
15191516
);
@@ -1549,7 +1546,6 @@
15491546
);
15501547
GCC_PREPROCESSOR_DEFINITIONS = (
15511548
"HAVE_LIBDE265=1",
1552-
"HAVE_X265=1",
15531549
"HAVE_UNISTD_H=1",
15541550
"$(inherited)",
15551551
);
@@ -1587,7 +1583,6 @@
15871583
GCC_PREPROCESSOR_DEFINITIONS = (
15881584
"DEBUG=1",
15891585
"HAVE_LIBDE265=1",
1590-
"HAVE_X265=1",
15911586
"HAVE_UNISTD_H=1",
15921587
"$(inherited)",
15931588
);
@@ -1623,7 +1618,6 @@
16231618
);
16241619
GCC_PREPROCESSOR_DEFINITIONS = (
16251620
"HAVE_LIBDE265=1",
1626-
"HAVE_X265=1",
16271621
"HAVE_UNISTD_H=1",
16281622
"$(inherited)",
16291623
);
@@ -1662,7 +1656,6 @@
16621656
GCC_PREPROCESSOR_DEFINITIONS = (
16631657
"DEBUG=1",
16641658
"HAVE_LIBDE265=1",
1665-
"HAVE_X265=1",
16661659
"HAVE_UNISTD_H=1",
16671660
"$(inherited)",
16681661
);
@@ -1699,7 +1692,6 @@
16991692
);
17001693
GCC_PREPROCESSOR_DEFINITIONS = (
17011694
"HAVE_LIBDE265=1",
1702-
"HAVE_X265=1",
17031695
"HAVE_UNISTD_H=1",
17041696
"$(inherited)",
17051697
);

0 commit comments

Comments
 (0)