pub struct Config { /* private fields */ }
Expand description
Builder style configuration for a pending CMake build.
Implementations§
Source§impl Config
impl Config
Sourcepub fn get_profile(&self) -> &str
pub fn get_profile(&self) -> &str
Return explicitly set profile or infer CMAKE_BUILD_TYPE
from Rust’s compilation profile.
- if
opt-level=0
thenCMAKE_BUILD_TYPE=Debug
, - if
opt-level={1,2,3}
and:debug=false
thenCMAKE_BUILD_TYPE=Release
- otherwise
CMAKE_BUILD_TYPE=RelWithDebInfo
- if
opt-level={s,z}
thenCMAKE_BUILD_TYPE=MinSizeRel
Sourcepub fn new<P: AsRef<Path>>(path: P) -> Config
pub fn new<P: AsRef<Path>>(path: P) -> Config
Creates a new blank set of configuration to build the project specified
at the path path
.
Sourcepub fn pic(&mut self, explicit_flag: bool) -> &mut Config
pub fn pic(&mut self, explicit_flag: bool) -> &mut Config
Sets flag for PIC. Otherwise use cc::Build platform default
Sourcepub fn generator<T: AsRef<OsStr>>(&mut self, generator: T) -> &mut Config
pub fn generator<T: AsRef<OsStr>>(&mut self, generator: T) -> &mut Config
Sets the build-tool generator (-G
) for this compilation.
If unset, this crate will use the CMAKE_GENERATOR
environment variable
if set. Otherwise, it will guess the best generator to use based on the
build target.
Sourcepub fn generator_toolset<T: AsRef<OsStr>>(
&mut self,
toolset_name: T,
) -> &mut Config
pub fn generator_toolset<T: AsRef<OsStr>>( &mut self, toolset_name: T, ) -> &mut Config
Sets the toolset name (-T) if supported by generator. Can be used to compile with Clang/LLVM instead of msvc when Visual Studio generator is selected.
If unset, will use the default toolset of the selected generator.
Sourcepub fn cflag<P: AsRef<OsStr>>(&mut self, flag: P) -> &mut Config
pub fn cflag<P: AsRef<OsStr>>(&mut self, flag: P) -> &mut Config
Adds a custom flag to pass down to the C compiler, supplementing those that this library already passes.
Sourcepub fn cxxflag<P: AsRef<OsStr>>(&mut self, flag: P) -> &mut Config
pub fn cxxflag<P: AsRef<OsStr>>(&mut self, flag: P) -> &mut Config
Adds a custom flag to pass down to the C++ compiler, supplementing those that this library already passes.
Sourcepub fn asmflag<P: AsRef<OsStr>>(&mut self, flag: P) -> &mut Config
pub fn asmflag<P: AsRef<OsStr>>(&mut self, flag: P) -> &mut Config
Adds a custom flag to pass down to the ASM compiler, supplementing those that this library already passes.
Sourcepub fn define<K, V>(&mut self, k: K, v: V) -> &mut Config
pub fn define<K, V>(&mut self, k: K, v: V) -> &mut Config
Adds a new -D
flag to pass to cmake during the generation step.
Sourcepub fn register_dep(&mut self, dep: &str) -> &mut Config
pub fn register_dep(&mut self, dep: &str) -> &mut Config
Registers a dependency for this compilation on the native library built by Cargo previously.
This registration will update the CMAKE_PREFIX_PATH
environment
variable for the build
system generation step. The
path will be updated to include the content of the environment
variable DEP_XXX_ROOT
, where XXX
is replaced with the uppercased
value of dep
(if that variable exists).
Sourcepub fn target(&mut self, target: &str) -> &mut Config
pub fn target(&mut self, target: &str) -> &mut Config
Sets the target triple for this compilation.
This is automatically scraped from $TARGET
which is set for Cargo
build scripts so it’s not necessary to call this from a build script.
Sourcepub fn no_build_target(&mut self, no_build_target: bool) -> &mut Config
pub fn no_build_target(&mut self, no_build_target: bool) -> &mut Config
Disables the cmake target option for this compilation.
Note that this isn’t related to the target triple passed to the compiler!
Sourcepub fn no_default_flags(&mut self, no_default_flags: bool) -> &mut Config
pub fn no_default_flags(&mut self, no_default_flags: bool) -> &mut Config
Disables the generation of default compiler flags. The default compiler flags may cause conflicts in some cross compiling scenarios.
Sourcepub fn host(&mut self, host: &str) -> &mut Config
pub fn host(&mut self, host: &str) -> &mut Config
Sets the host triple for this compilation.
This is automatically scraped from $HOST
which is set for Cargo
build scripts so it’s not necessary to call this from a build script.
Sourcepub fn out_dir<P: AsRef<Path>>(&mut self, out: P) -> &mut Config
pub fn out_dir<P: AsRef<Path>>(&mut self, out: P) -> &mut Config
Sets the output directory for this compilation.
This is automatically scraped from $OUT_DIR
which is set for Cargo
build scripts so it’s not necessary to call this from a build script.
Sourcepub fn profile(&mut self, profile: &str) -> &mut Config
pub fn profile(&mut self, profile: &str) -> &mut Config
Sets the CMAKE_BUILD_TYPE=build_type
variable.
By default, this value is automatically inferred from Rust’s compilation profile as follows:
- if
opt-level=0
thenCMAKE_BUILD_TYPE=Debug
, - if
opt-level={1,2,3}
and:debug=false
thenCMAKE_BUILD_TYPE=Release
- otherwise
CMAKE_BUILD_TYPE=RelWithDebInfo
- if
opt-level={s,z}
thenCMAKE_BUILD_TYPE=MinSizeRel
Sourcepub fn static_crt(&mut self, static_crt: bool) -> &mut Config
pub fn static_crt(&mut self, static_crt: bool) -> &mut Config
Configures whether the /MT flag or the /MD flag will be passed to msvc build tools.
This option defaults to false
, and affect only msvc targets.
Sourcepub fn configure_arg<A: AsRef<OsStr>>(&mut self, arg: A) -> &mut Config
pub fn configure_arg<A: AsRef<OsStr>>(&mut self, arg: A) -> &mut Config
Add an argument to the cmake
configure step
Sourcepub fn build_arg<A: AsRef<OsStr>>(&mut self, arg: A) -> &mut Config
pub fn build_arg<A: AsRef<OsStr>>(&mut self, arg: A) -> &mut Config
Add an argument to the final cmake
build step
Sourcepub fn env<K, V>(&mut self, key: K, value: V) -> &mut Config
pub fn env<K, V>(&mut self, key: K, value: V) -> &mut Config
Configure an environment variable for the cmake
processes spawned by
this crate in the build
step.
Sourcepub fn build_target(&mut self, target: &str) -> &mut Config
pub fn build_target(&mut self, target: &str) -> &mut Config
Sets the build target for the final cmake
build step, this will
default to “install” if not specified.
Sourcepub fn uses_cxx11(&mut self) -> &mut Config
👎Deprecated: no longer does anything, C++ is determined based on cc::Build
, and the macOS issue has been fixed upstream
pub fn uses_cxx11(&mut self) -> &mut Config
cc::Build
, and the macOS issue has been fixed upstreamAlters the default target triple on OSX to ensure that c++11 is available. Does not change the target triple if it is explicitly specified.
This does not otherwise affect any CXX flags, i.e. it does not set -std=c++11 or -stdlib=libc++.
Sourcepub fn always_configure(&mut self, always_configure: bool) -> &mut Config
pub fn always_configure(&mut self, always_configure: bool) -> &mut Config
Forces CMake to always run before building the custom target.
In some cases, when you have a big project, you can disable
subsequents runs of cmake to make cargo build
faster.
Sourcepub fn very_verbose(&mut self, value: bool) -> &mut Config
pub fn very_verbose(&mut self, value: bool) -> &mut Config
Sets very verbose output.
Sourcepub fn init_c_cfg(&mut self, c_cfg: Build) -> &mut Config
pub fn init_c_cfg(&mut self, c_cfg: Build) -> &mut Config
Initializes the C build configuration.
Sourcepub fn init_cxx_cfg(&mut self, cxx_cfg: Build) -> &mut Config
pub fn init_cxx_cfg(&mut self, cxx_cfg: Build) -> &mut Config
Initializes the C++ build configuration.