You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 5.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using Spectre.Console;
  2. using System;
  3. using System.Diagnostics;
  4. using System.Text;
  5. using static System.Runtime.InteropServices.JavaScript.JSType;
  6. namespace GenerateSolution
  7. {
  8. internal class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. System.Console.InputEncoding = Encoding.Unicode;
  13. System.Console.OutputEncoding = Encoding.Unicode;
  14. // Check if we can accept key strokes
  15. if (!AnsiConsole.Profile.Capabilities.Interactive)
  16. {
  17. AnsiConsole.MarkupLine("[red]Environment does not support interaction.[/]");
  18. return;
  19. }
  20. var options = AskOptions();
  21. var cmakePath = AskCMakePath();
  22. if(string.IsNullOrEmpty(cmakePath) == true)
  23. {
  24. cmakePath = "C:\\Program Files\\CMake\\bin\\cmake.exe";
  25. }
  26. AnsiConsole.MarkupLine("You have selected: [yellow]{0}[/]", cmakePath);
  27. string cmakeListsPath = @"..\..\..\..\CMakeLists.txt";
  28. //cmake [<options>] -B <path-to-build> [-S <path-to-source>]
  29. //TODO: get the chosen arguments from above (hardcoded values below)
  30. //TODO: edit the CMakeList.txt.in template and create the CMakeLists.txt with the chosen options
  31. cmakeListsPath += " -G \"Visual Studio 17 2022\" -A x64 -B ..\\..\\..\\..\\ -S ..\\..\\..\\..\\";
  32. ProcessStartInfo startInfo = new ProcessStartInfo
  33. {
  34. FileName = cmakePath,
  35. Arguments = cmakeListsPath,
  36. RedirectStandardOutput = true,
  37. RedirectStandardError = true,
  38. UseShellExecute = false,
  39. CreateNoWindow = true,
  40. };
  41. try
  42. {
  43. bool bSuccess = false;
  44. string lastError = "";
  45. AnsiConsole.Progress()
  46. .AutoClear(false)
  47. .Columns(new ProgressColumn[]
  48. {
  49. new TaskDescriptionColumn(),
  50. new SpinnerColumn(Spinner.Known.Ascii),
  51. })
  52. .Start(ctx =>
  53. {
  54. var cmakeTask = ctx.AddTask("Generating VS Solution", autoStart: false).IsIndeterminate();
  55. cmakeTask.StartTask();
  56. using (Process process = new Process())
  57. {
  58. process.StartInfo = startInfo;
  59. process.Start();
  60. string output = process.StandardOutput.ReadToEnd();
  61. lastError = process.StandardError.ReadToEnd();
  62. process.WaitForExit();
  63. cmakeTask.StopTask();
  64. if (process.ExitCode == 0)
  65. {
  66. bSuccess = true;
  67. }
  68. }
  69. });
  70. if (bSuccess == true)
  71. {
  72. AnsiConsole.WriteLine("VS solution generated successfully.");
  73. }
  74. else
  75. {
  76. AnsiConsole.WriteLine($"Error running CMake configuration: {lastError}");
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. AnsiConsole.WriteLine("[red]ERROR[/] " + ex.Message);
  82. }
  83. Console.ReadLine();
  84. }
  85. public static string AskCMakePath()
  86. {
  87. return AnsiConsole.Prompt(
  88. new TextPrompt<string>("What's your [green]CMake path[/] (default: C:\\Program Files\\CMake\\bin\\cmake.exe)?")
  89. .AllowEmpty());
  90. }
  91. public static List<string> AskOptions()
  92. {
  93. var options = AnsiConsole.Prompt(
  94. new MultiSelectionPrompt<string>()
  95. .PageSize(10)
  96. .Title("Select the preferred [green]options[/]?")
  97. .MoreChoicesText("[grey](Move up and down to reveal more options)[/]")
  98. .InstructionsText("[grey](Press [blue]<space>[/] to toggle an option, [green]<enter>[/] to accept)[/]")
  99. .AddChoiceGroup("Avx", new[]
  100. {
  101. "Avx2", "Avx512"
  102. })
  103. .AddChoiceGroup("Cuda", new[]
  104. {
  105. "Cuda"
  106. })
  107. .AddChoices(new[]
  108. {
  109. "x64",
  110. })
  111. .AddChoiceGroup("Visual Studio", new[]
  112. {
  113. "Visual Studio 16 2019",
  114. "Visual Studio 17 2022"
  115. })
  116. );
  117. if (options.Count > 0)
  118. {
  119. AnsiConsole.MarkupLine("You have selected: [yellow]{0}[/]", string.Join(",",options));
  120. }
  121. return options;
  122. }
  123. }
  124. }