Add feature flag and instructions to use Mac SDL2 framework

This commit is contained in:
Matthew D. Steele
2016-05-01 14:51:02 -04:00
parent c55239d285
commit 0cc48511fc
5 changed files with 38 additions and 3 deletions
+1
View File
@@ -35,3 +35,4 @@ version = "0.8.1"
default = []
use-pkgconfig = [ "sdl2-sys/use-pkgconfig" ]
use_mac_framework = ["sdl2-sys/use_mac_framework"]
+29
View File
@@ -70,6 +70,35 @@ Then add the following to your `~/.bash_profile` if not already present.
If you're having issues with either homebrew or macports, [see here][pdev-issue].
#### If you are using the SDL2 framework
You can download and install the SDL2 Mac OS X framework from:
https://www.libsdl.org/download-2.0.php
To make the `sdl2` crate link with the SDL2 framework, you will need to enable
the `use_mac_framework` feature. To build and test the `sdl2` crate with this
feature, use:
> cargo test --features use_mac_framework
To depend on the `sdl2` crate with this feature enabled, put the following in
your project's `Cargo.toml` file:
```toml
[dependencies.sdl2]
features = ["use_mac_framework"]
version = ... # Whichever version you are using
```
Alternatively, you can re-export the feature in your package by putting the
following in your `Cargo.toml` file:
```toml
[features]
default = []
use_sdl2_mac_framework = ["sdl2/use_mac_framework"]
```
### Windows (MinGW)
On Windows, make certain you are using the MinGW version of SDL; the native
version will crash on `sdl2::init`.
+1
View File
@@ -25,3 +25,4 @@ optional = true
default = []
use-pkgconfig = ["pkg-config"]
no_std = []
use_mac_framework = []
+5 -1
View File
@@ -3,7 +3,11 @@ extern crate pkg_config;
fn main() {
if !build_pkgconfig() {
println!("cargo:rustc-flags=-l SDL2");
if cfg!(feature="use_mac_framework") {
println!("cargo:rustc-flags=-l framework=SDL2");
} else {
println!("cargo:rustc-flags=-l SDL2");
}
}
}
+2 -2
View File
@@ -3,11 +3,11 @@ use libc::{c_int, c_uint, c_char, uint32_t};
// Setup linking for all targets.
#[cfg(target_os="macos")]
mod mac {
#[cfg(mac_framework)]
#[cfg(any(mac_framework, feature="use_mac_framework"))]
#[link(kind="framework", name="SDL2")]
extern {}
#[cfg(not(mac_framework))]
#[cfg(not(any(mac_framework, feature="use_mac_framework")))]
#[link(name="SDL2")]
extern {}
}