Skip to content

Commit ffd7b5a

Browse files
committed
Linux version is now working again, including the SimpleVideoFilter sample application. This time, full Swift Package Manager support is available.
1 parent bf19a4e commit ffd7b5a

File tree

18 files changed

+141
-158
lines changed

18 files changed

+141
-158
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Exclude the build directory
22
build/*
33
examples/FilterShowcase/build*
4+
examples/Linux-OpenGL/SimpleVideoFilter/.build
5+
.build
6+
.swiftpm
47

58
# Exclude temp nibs and swap files
69
*~.nib

Package.swift

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
1-
// swift-tools-version:4.0
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
1+
// swift-tools-version:4.2
32

43
import PackageDescription
54

65
#if os(macOS)
76
let platformDepedencies: [Package.Dependency] = []
87
let platformExcludes = ["iOS", "Linux", "Operations/Shaders"]
8+
let platformTargets: [Target] = [
9+
.target(
10+
name: "GPUImage",
11+
path: "framework/Source",
12+
exclude: platformExcludes)]
913
#elseif os(iOS)
1014
let platformDepedencies: [Package.Dependency] = []
1115
let platformExcludes = ["Linux", "Mac", "Operations/Shaders"]
16+
let platformTargets: [Target] = [
17+
.target(
18+
name: "GPUImage",
19+
path: "framework/Source",
20+
exclude: platformExcludes)]
1221
#elseif os(Linux)
1322
// TODO: Add back in RPi support
14-
let platformDepedencies: [Package.Dependency] = [.package(url: "https://github.com/BradLarson/COpenGL.git", from: "1.0.2"), .package(url: "https://github.com/BradLarson/CFreeGLUT.git", from: "1.0.1"), .package(url: "https://github.com/BradLarson/CVideo4Linux.git", from: "1.0.2")]
23+
// TODO: Move the remote system library packages into this project
24+
let platformDepedencies: [Package.Dependency] = [
25+
.package(url: "https://github.com/BradLarson/COpenGL.git", from: "1.0.2"),
26+
.package(url: "https://github.com/BradLarson/CFreeGLUT.git", from: "1.0.1"),
27+
.package(url: "https://github.com/BradLarson/CVideo4Linux.git", from: "1.0.2")]
1528
let platformExcludes = ["iOS", "Mac", "Operations/Shaders", "Linux/RPiRenderWindow.swift", "Linux/OpenGLContext-RPi.swift", "Linux/V4LSupplement"]
29+
let platformTargets: [Target] = [
30+
.target(
31+
name: "V4LSupplement",
32+
path: "framework/Source/Linux/V4LSupplement"),
33+
.target(
34+
name: "GPUImage",
35+
dependencies: ["V4LSupplement"],
36+
path: "framework/Source",
37+
exclude: platformExcludes)]
1638
#endif
1739

1840

@@ -24,10 +46,6 @@ let package = Package(
2446
targets: ["GPUImage"]),
2547
],
2648
dependencies: platformDepedencies,
27-
targets: [
28-
.target(
29-
name: "GPUImage",
30-
path: "framework/Source",
31-
exclude: platformExcludes),
32-
]
49+
targets: platformTargets,
50+
swiftLanguageVersions: [.v4]
3351
)

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,21 @@ Note that you may need to build your project once to parse and build the GPUImag
5454

5555
## Using GPUImage in a Linux application ##
5656

57-
Eventually, this project will support the Swift Package Manager, which will make it trivial to use with a Linux project. Unfortunately, that's not yet the case, so it can take a little work to get this to build for a Linux project.
57+
This project supports the Swift Package Manager, so you should be able to add it as a dependency in your Package.swift file like the following:
5858

59-
Right now, there are two build scripts in the framework directory, one named compile-LinuxGL.sh and one named compile-RPi.sh. The former builds the framework for a Linux target using OpenGL and the latter builds for the Raspberry Pi. I can add other targets as I test them, but I've only gotten this operational in desktop Ubuntu, on Ubuntu running on a Jetson TK1 development board, and on Raspbian running on a Raspberry Pi 2 and Pi 3.
59+
```
60+
.package(url: "https://github.com/BradLarson/GPUImage2.git", from: "0.0.1"),
61+
```
6062

61-
Before compiling the framework, you'll need to get Swift up and running on your system. For desktop Ubuntu installs, you can follow Apple's guidelines on <a href="https://swift.org/download/">their Downloads page</a>. Those instructions also worked for me on the Jetson TK1 dev board.
63+
along with an
64+
65+
```
66+
import GPUImage
67+
```
6268

63-
For ARM Linux devices like the Raspberry Pi, follow <a href="http://dev.iachieved.it/iachievedit/open-source-swift-on-raspberry-pi-2/">these steps exactly</a> to get a working Swift compiler installed. Pay close attention to the steps for getting Clang-2.6 installed and the use of update-alternatives. These are the steps I used to go from stock Raspbian to a Swift install on
69+
in your application code.
6470

65-
I have noticed that Swift 2.2 compiler snapshots newer than January 11 or so are missing Foundation, which I need for the framework, so maybe go with a snaphot earlier than that.
71+
Before compiling the framework, you'll need to get Swift up and running on your system. For desktop Ubuntu installs, you can follow Apple's guidelines on <a href="https://swift.org/download/">their Downloads page</a>.
6672

6773
After Swift, you'll need to install Video4Linux to get access to standard USB webcams as inputs:
6874

@@ -76,13 +82,15 @@ On the Raspberry Pi, you'll need to make sure that the Broadcom Videocore header
7682
sudo apt-get install libraspberrypi-dev
7783
```
7884

79-
For desktop Linux and other OpenGL devices (Jetson TK1), you'll need to make sure GLUT and the OpenGL headers are installed. The framework currently uses GLUT for its output. GLUT can be used on the Raspberry Pi via the new experimental OpenGL support there, but I've found that it's significantly slower than using the OpenGL ES APIs and the Videocore interface that ships with the Pi. Also, if you enable the OpenGL support you currently lock yourself out of using the Videocore interface.
85+
For desktop Linux and other OpenGL devices (Jetson family), you'll need to make sure GLUT and the OpenGL headers are installed. The framework currently uses GLUT for its output. GLUT can be used on the Raspberry Pi via the new experimental OpenGL support there, but I've found that it's significantly slower than using the OpenGL ES APIs and the Videocore interface that ships with the Pi. Also, if you enable the OpenGL support you currently lock yourself out of using the Videocore interface.
8086

81-
Once all of that is set up, to build the framework go to the /framework directory and run the appropriate build script. This will compile and generate a Swift module and a shared library for the framework. Copy the shared library into a system-accessible library path, like /usr/lib.
87+
Once all of that is set up, you can use
8288

83-
To build any of the sample applications, go to the examples/ subdirectory for that example (examples are platform-specific) and run the compile.sh build script to compile the example. The framework must be built before any example application.
89+
```
90+
swift build
91+
```
8492

85-
As Swift becomes incorporated into more platforms, and as I add support for the Swift Package Manager, these Linux build steps will become much easier. My setup is kind of a hack at present.
93+
in the main GPUImage directory to build the framework, or do the same in the examples/Linux-OpenGL/SimpleVideoFilter directory. This will build a sample application that filters live video from a USB camera and displays the results in real time to the screen. The application itself will be contained within the .build directory and its platform-specific subdirectories. Look for the SimpleVideoFilter binary and run that.
8694

8795
## Performing common tasks ##
8896

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj

examples/Linux-OpenGL/SimpleVideoFilter/Package.resolved

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// swift-tools-version:4.2
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "SimpleVideoFilter",
7+
dependencies: [
8+
.package(path: "../../../../GPUImage2")
9+
],
10+
targets: [
11+
.target(
12+
name: "SimpleVideoFilter",
13+
dependencies: ["GPUImage"],
14+
path: "Sources")
15+
]
16+
)

examples/Linux-OpenGL/SimpleVideoFilter/compile.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/iOS/FilterShowcase/FilterShowcase.xcodeproj/project.pbxproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
developmentRegion = English;
221221
hasScannedForEncodings = 0;
222222
knownRegions = (
223+
English,
223224
en,
224225
Base,
225226
);
@@ -384,6 +385,7 @@
384385
ONLY_ACTIVE_ARCH = YES;
385386
SDKROOT = iphoneos;
386387
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
388+
SWIFT_VERSION = 4.2;
387389
TARGETED_DEVICE_FAMILY = "1,2";
388390
};
389391
name = Debug;
@@ -431,6 +433,7 @@
431433
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
432434
METAL_ENABLE_DEBUG_INFO = NO;
433435
SDKROOT = iphoneos;
436+
SWIFT_VERSION = 4.2;
434437
TARGETED_DEVICE_FAMILY = "1,2";
435438
VALIDATE_PRODUCT = YES;
436439
};
@@ -450,7 +453,6 @@
450453
PRODUCT_NAME = FilterShowcase;
451454
PROVISIONING_PROFILE_SPECIFIER = "";
452455
SWIFT_SWIFT3_OBJC_INFERENCE = On;
453-
SWIFT_VERSION = 4.0;
454456
};
455457
name = Debug;
456458
};
@@ -469,7 +471,6 @@
469471
PROVISIONING_PROFILE_SPECIFIER = "";
470472
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
471473
SWIFT_SWIFT3_OBJC_INFERENCE = On;
472-
SWIFT_VERSION = 4.0;
473474
};
474475
name = Release;
475476
};

examples/iOS/FilterShowcase/FilterShowcaseSwift/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
55

66
var window: UIWindow?
77

8-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey:Any]?) -> Bool {
8+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey:Any]?) -> Bool {
99
return true
1010
}
1111
}

0 commit comments

Comments
 (0)