-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
84 lines (68 loc) · 2.48 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace gmake
{
class Program
{
private static string projectName;
private static string projectDirectory;
static void CreateDirectory(string dirPath)
{
Console.WriteLine("~ mkdir " + dirPath);
Directory.CreateDirectory(dirPath);
}
static void WriteCMakeLists()
{
const string cmlplaceholder = @"project(#{PROJECT_NAME})
cmake_minimum_required(VERSION 2.6)
include_directories(${#{PROJECT_NAME}_SOURCE_DIR}/include)
file(GLOB_RECURSE cppFiles src/*.cpp)
add_executable(#{PROJECT_NAME} ${cppFiles})";
StreamWriter sw = File.CreateText(projectDirectory + @"CMakeLists.txt");
sw.Write(cmlplaceholder.Replace("#{PROJECT_NAME}", projectName));
sw.Close();
}
static void CreateHelloWorld()
{
const string code = @"#include <iostream>
int main()
{
std::cout << " + "\"Hello World\"" + @";
return 0;
}";
StreamWriter sw = File.CreateText(projectDirectory + @"src\main.cpp");
sw.Write(code);
sw.Close();
}
static void Main(string[] args)
{
if (args.Length > 1)
{
Console.WriteLine("Too many arguments");
return;
}
if (args.Length == 0)
{
Console.WriteLine("Usage: gmake <project_name>");
return;
}
projectName = args[0];
projectDirectory = Directory.GetCurrentDirectory() + @"\" + projectName + @"\";
CreateDirectory(projectDirectory);
CreateDirectory(projectDirectory + "build");
CreateDirectory(projectDirectory + "include");
CreateDirectory(projectDirectory + "src");
WriteCMakeLists();
CreateHelloWorld();
Console.WriteLine("Running cd " + projectName + "\\build && cmake .. -G \"MinGW Makefiles\"");
System.Threading.Thread.Sleep(2000);
System.Diagnostics.Process.Start("cmd.exe", "/C cd " + projectName + "\\build && cmake .. -G \"MinGW Makefiles\"");
Console.WriteLine("Running cd " + projectName + "\\build && cmake ..");
System.Threading.Thread.Sleep(4000);
System.Diagnostics.Process.Start("cmd.exe", "/C cd " + projectName + "\\build && cmake ..");
}
}
}