Skip to content

Commit

Permalink
image: add cmake feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
maia-s committed Jan 24, 2025
1 parent 5704593 commit b4b5408
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 0 deletions.
15 changes: 15 additions & 0 deletions build-common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ type Config = cmake::Config;
#[cfg(not(feature = "build-from-source"))]
type Config = ();

#[allow(unused)]
macro_rules! cmake_vars {
($config:ident => $($cvar:ident),* $(,)?) => {
$(
let cvar = stringify!($cvar);
if env::var_os(format!("CARGO_FEATURE_NO_{cvar}")).is_some() {
$config.define(cvar, "OFF");
}
if env::var_os(format!("CARGO_FEATURE_{cvar}")).is_some() {
$config.define(cvar, "ON");
}
)*
}
}

#[cfg(all(windows, feature = "build-from-source", not(feature = "link-static")))]
// based on find_cargo_target_dir from sdl2-sys
fn top_level_cargo_target_dir() -> std::path::PathBuf {
Expand Down
109 changes: 109 additions & 0 deletions sdl3-image-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ build-from-source = ["dep:cmake", "dep:rpkg-config", "dep:sdl3-image-src"]
# Build and link a static SDL3_image library from source
build-from-source-static = ["build-from-source", "link-static"]

# Build and link a static SDL3_image library from source using vendored libraries
build-static-vendored = ["build-from-source-static", "sdlimage-vendored"]

# Link SDL3_image as a static library. The default is to link a shared/dynamic library.
link-static = []

Expand All @@ -35,6 +38,112 @@ use-vcpkg = ["dep:vcpkg"]
# Implement the Debug trait for applicable types
debug-impls = []

no-default-anything = [
"no-default-backends",
"no-default-formats",
]

no-default-backends = [
"no-sdlimage-backend-imageio",
"no-sdlimage-backend-stb",
"no-sdlimage-backend-wic",
]

no-default-formats = [
"no-sdlimage-avif",
"no-sdlimage-bmp",
"no-sdlimage-gif",
"no-sdlimage-jpg",
"no-sdlimage-jxl",
"no-sdlimage-lbm",
"no-sdlimage-pcx",
"no-sdlimage-png",
"no-sdlimage-pnm",
"no-sdlimage-qoi",
"no-sdlimage-svg",
"no-sdlimage-tga",
"no-sdlimage-tif",
"no-sdlimage-webp",
"no-sdlimage-xcf",
"no-sdlimage-xpm",
"no-sdlimage-xv",
"no-sdlimage-avif-save",
"no-sdlimage-jpg-save",
"no-sdlimage-png-save",
]

sdlimage-deps-shared = []
no-sdlimage-deps-shared = []

sdlimage-vendored = []
no-sdlimage-vendored = []

sdlimage-backend-imageio = []
sdlimage-backend-stb = []
sdlimage-backend-wic = []

no-sdlimage-backend-imageio = []
no-sdlimage-backend-stb = []
no-sdlimage-backend-wic = []

sdlimage-avif = []
sdlimage-bmp = []
sdlimage-gif = []
sdlimage-jpg = []
sdlimage-jxl = []
sdlimage-lbm = []
sdlimage-pcx = []
sdlimage-png = []
sdlimage-pnm = []
sdlimage-qoi = []
sdlimage-svg = []
sdlimage-tga = []
sdlimage-tif = []
sdlimage-webp = []
sdlimage-xcf = []
sdlimage-xpm = []
sdlimage-xv = []

no-sdlimage-avif = []
no-sdlimage-bmp = []
no-sdlimage-gif = []
no-sdlimage-jpg = []
no-sdlimage-jxl = []
no-sdlimage-lbm = []
no-sdlimage-pcx = []
no-sdlimage-png = []
no-sdlimage-pnm = []
no-sdlimage-qoi = []
no-sdlimage-svg = []
no-sdlimage-tga = []
no-sdlimage-tif = []
no-sdlimage-webp = []
no-sdlimage-xcf = []
no-sdlimage-xpm = []
no-sdlimage-xv = []

sdlimage-avif-save = ["sdlimage-avif"]
sdlimage-jpg-save = ["sdlimage-jpg"]
sdlimage-png-save = ["sdlimage-png"]

no-sdlimage-avif-save = []
no-sdlimage-jpg-save = []
no-sdlimage-png-save = []

sdlimage-avif-shared = ["sdlimage-avif"]
sdlimage-jpg-shared = ["sdlimage-jpg"]
sdlimage-jxl-shared = ["sdlimage-jxl"]
sdlimage-png-shared = ["sdlimage-png"]
sdlimage-tif-shared = ["sdlimage-tif"]
sdlimage-webp-shared = ["sdlimage-webp"]

no-sdlimage-avif-shared = []
no-sdlimage-jpg-shared = []
no-sdlimage-jxl-shared = []
no-sdlimage-png-shared = []
no-sdlimage-tif-shared = []
no-sdlimage-webp-shared = []

[dependencies]
sdl3-sys = { version = "0.4", path = "../sdl3-sys" }

Expand Down
15 changes: 15 additions & 0 deletions sdl3-image-sys/build-common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ type Config = cmake::Config;
#[cfg(not(feature = "build-from-source"))]
type Config = ();

#[allow(unused)]
macro_rules! cmake_vars {
($config:ident => $($cvar:ident),* $(,)?) => {
$(
let cvar = stringify!($cvar);
if env::var_os(format!("CARGO_FEATURE_NO_{cvar}")).is_some() {
$config.define(cvar, "OFF");
}
if env::var_os(format!("CARGO_FEATURE_{cvar}")).is_some() {
$config.define(cvar, "ON");
}
)*
}
}

#[cfg(all(windows, feature = "build-from-source", not(feature = "link-static")))]
// based on find_cargo_target_dir from sdl2-sys
fn top_level_cargo_target_dir() -> std::path::PathBuf {
Expand Down
34 changes: 34 additions & 0 deletions sdl3-image-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,40 @@ fn main() -> Result<(), Box<dyn Error>> {
if cfg!(feature = "link-static") {
config.define("BUILD_SHARED_LIBS", "OFF");
}

cmake_vars! { config =>
SDLIMAGE_DEPS_SHARED,
SDLIMAGE_VENDORED,
SDLIMAGE_BACKEND_STB,
SDLIMAGE_BACKEND_WIC,
SDLIMAGE_BACKEND_IMAGEIO,
SDLIMAGE_AVIF,
SDLIMAGE_BMP,
SDLIMAGE_GIF,
SDLIMAGE_JPG,
SDLIMAGE_JXL,
SDLIMAGE_LBM,
SDLIMAGE_PCX,
SDLIMAGE_PNG,
SDLIMAGE_PNM,
SDLIMAGE_QOI,
SDLIMAGE_SVG,
SDLIMAGE_TGA,
SDLIMAGE_TIF,
SDLIMAGE_WEBP,
SDLIMAGE_XCF,
SDLIMAGE_XPM,
SDLIMAGE_XV,
SDLIMAGE_AVIF_SAVE,
SDLIMAGE_JPG_SAVE,
SDLIMAGE_PNG_SAVE,
SDLIMAGE_AVIF_SHARED,
SDLIMAGE_JPG_SHARED,
SDLIMAGE_JXL_SHARED,
SDLIMAGE_PNG_SHARED,
SDLIMAGE_TIF_SHARED,
SDLIMAGE_WEBP_SHARED,
}
}
Ok(())
})?;
Expand Down
15 changes: 15 additions & 0 deletions sdl3-sys/build-common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ type Config = cmake::Config;
#[cfg(not(feature = "build-from-source"))]
type Config = ();

#[allow(unused)]
macro_rules! cmake_vars {
($config:ident => $($cvar:ident),* $(,)?) => {
$(
let cvar = stringify!($cvar);
if env::var_os(format!("CARGO_FEATURE_NO_{cvar}")).is_some() {
$config.define(cvar, "OFF");
}
if env::var_os(format!("CARGO_FEATURE_{cvar}")).is_some() {
$config.define(cvar, "ON");
}
)*
}
}

#[cfg(all(windows, feature = "build-from-source", not(feature = "link-static")))]
// based on find_cargo_target_dir from sdl2-sys
fn top_level_cargo_target_dir() -> std::path::PathBuf {
Expand Down

0 comments on commit b4b5408

Please sign in to comment.