Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ impl Config {
// Build up the first cmake command to build the build system.
let executable = self
.getenv_target_os("CMAKE")
.or_else(|| find_cmake_executable(&target))
.unwrap_or(OsString::from("cmake"));
let mut cmd = Command::new(&executable);

Expand Down Expand Up @@ -965,3 +966,28 @@ fn getenv_unwrap(v: &str) -> String {
fn fail(s: &str) -> ! {
panic!("\n{}\n\nbuild script failed, must exit now", s)
}

#[cfg(windows)]
fn find_cmake_executable(target: &str) -> Option<OsString> {
use cc::windows_registry::find_tool;

// Try to find cmake.exe bundled with MSVC, but only if there isn't another one in path
let cmake_in_path = env::split_paths(&env::var_os("PATH").unwrap_or(OsString::new()))
.any(|p| p.join("cmake.exe").exists());
if cmake_in_path {
None
} else {
find_tool(target, "devenv").and_then(|t| {
t.path()
.join("..\\CommonExtensions\\Microsoft\\CMake\\CMake\\bin\\cmake.exe")
.canonicalize()
.ok()
.map(OsString::from)
})
}
}

#[cfg(not(windows))]
fn find_cmake_executable(target: &str) -> Option<OsString> {
None
}