From 434213681dc74d8d6fae62e34917dfe4c9efb086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Sun, 12 Jan 2020 15:18:04 -0700 Subject: Run CMake as part of "build", implement "run" --- src/main.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 85ba64a..ddcb335 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,51 @@ fn build() { println!("File: {}", file.to_str().unwrap()); } println!("Files: {:?}", files); + let s = "\ +cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) + +enable_language(Fortran) + +project(p1) + +set(SRC + a.f90 + b.f90 +) + +add_executable(p1 main.f90 ${SRC}) +"; + std::fs::write("CMakeLists.txt", s).unwrap(); + let output = std::process::Command::new("cmake") + .args(&["-B", "build", "."]) + .output().unwrap(); + println!("status: {}", output.status); + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + if !output.status.success() { + panic!("Command failed.") + } + + let output = std::process::Command::new("cmake") + .args(&["--build", "build"]) + .output().unwrap(); + println!("status: {}", output.status); + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + if !output.status.success() { + panic!("Command failed.") + } +} + +fn run() { + let output = std::process::Command::new("build/p1") + .output().unwrap(); + println!("status: {}", output.status); + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + if !output.status.success() { + panic!("Command failed.") + } } fn main() { @@ -38,6 +83,10 @@ fn main() { if args.command == "build" { println!("Command: build"); build(); + } else if args.command == "run" { + println!("Command: run"); + build(); + run(); } else { panic!("Unknown command"); } -- cgit v1.2.3