• <legend id='mcNJM'><style id='mcNJM'><dir id='mcNJM'><q id='mcNJM'></q></dir></style></legend>
      <bdo id='mcNJM'></bdo><ul id='mcNJM'></ul>
  • <small id='mcNJM'></small><noframes id='mcNJM'>

    <i id='mcNJM'><tr id='mcNJM'><dt id='mcNJM'><q id='mcNJM'><span id='mcNJM'><b id='mcNJM'><form id='mcNJM'><ins id='mcNJM'></ins><ul id='mcNJM'></ul><sub id='mcNJM'></sub></form><legend id='mcNJM'></legend><bdo id='mcNJM'><pre id='mcNJM'><center id='mcNJM'></center></pre></bdo></b><th id='mcNJM'></th></span></q></dt></tr></i><div id='mcNJM'><tfoot id='mcNJM'></tfoot><dl id='mcNJM'><fieldset id='mcNJM'></fieldset></dl></div>

      1. <tfoot id='mcNJM'></tfoot>

        使用 Visual Studio 创建一个 cmake 项目

        Creating a cmake project with visual studio(使用 Visual Studio 创建一个 cmake 项目)
          <bdo id='FF6Xy'></bdo><ul id='FF6Xy'></ul>
              <i id='FF6Xy'><tr id='FF6Xy'><dt id='FF6Xy'><q id='FF6Xy'><span id='FF6Xy'><b id='FF6Xy'><form id='FF6Xy'><ins id='FF6Xy'></ins><ul id='FF6Xy'></ul><sub id='FF6Xy'></sub></form><legend id='FF6Xy'></legend><bdo id='FF6Xy'><pre id='FF6Xy'><center id='FF6Xy'></center></pre></bdo></b><th id='FF6Xy'></th></span></q></dt></tr></i><div id='FF6Xy'><tfoot id='FF6Xy'></tfoot><dl id='FF6Xy'><fieldset id='FF6Xy'></fieldset></dl></div>

                  <small id='FF6Xy'></small><noframes id='FF6Xy'>

                    <tbody id='FF6Xy'></tbody>
                  <legend id='FF6Xy'><style id='FF6Xy'><dir id='FF6Xy'><q id='FF6Xy'></q></dir></style></legend>
                1. <tfoot id='FF6Xy'></tfoot>
                  本文介绍了使用 Visual Studio 创建一个 cmake 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Visual Studio 2017 为处理 CMake 项目提供内置支持.

                  这将创建一个简单的

                  它在给定的文件夹中生成以下文件,然后在其上使用打开文件夹":

                  CMakeLists.txtCMakeSettings.json我的项目1.cpp

                  后续步骤

                  可能的下一步是:

                  • 为一些基本的项目/编译器设置添加一个交互式向导对话框
                  • 还添加了一个项目向导,以便能够将源文件添加到 CMakeLists.txt

                  我期待收到有关基本想法的反馈.请将任何请求直接添加到:

                  https://github.com/FloriansGit/VSCMakeWizards/issues

                  代码

                  这里是威世智的基本/初始代码作为参考:

                  WizardImplementationClass.cs

                  //基于 https://docs.microsoft.com/en-us/visualstudio/extensibility/how-to-use-wizards-with-project-templates//和 https://stackoverflow.com/questions/3882764/issue-with-visual-studio-template-directory-creation使用系统;使用 System.IO;使用 System.Collections.Generic;使用 System.Text.RegularExpressions;使用 EnvDTE;使用 Microsoft.VisualStudio.TemplateWizard;使用 Microsoft.VisualStudio.Shell;使用 Microsoft.VisualStudio.Shell.Interop;使用 EnvDTE80;命名空间 VSCMakeWizards{公共类 WizardImplementation : IWizard{公共无效运行开始(对象自动化对象,字典<字符串,字符串>替换字典,WizardRunKind runKind, object[] customParams){var destinationDir = replacementsDictionary["$destinationdirectory$"];var requiredNamespace = replacementsDictionary["$safeprojectname$"];var templatePath = Path.GetDirectoryName((string)customParams[0]);var dte = 自动化对象作为 DTE2;var solution = dte.Solution as EnvDTE100.Solution4;如果(解决方案.IsOpen){解决方案.关闭();}File.Copy(Path.Combine(templatePath, "CMakeSettings.json"), Path.Combine(destinationDir, "CMakeSettings.json"));File.Copy(Path.Combine(templatePath, "main.cpp"), Path.Combine(destinationDir, desiredNamespace + ".cpp"));//参见 https://stackoverflow.com/questions/1231768/c-sharp-string-replace-with-dictionaryRegex re = new Regex(@"($w+$)", RegexOptions.Compiled);string input = File.ReadAllText(Path.Combine(templatePath, "CMakeLists.txt"));字符串输出 = re.Replace(input, match => replacementsDictionary[match.Groups[1].Value]);File.WriteAllText(Path.Combine(destinationDir, "CMakeLists.txt"), output);var vsSolution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution7;如果(vsSolution!= null){vsSolution.OpenFolder(destinationDir);}抛出新的 WizardCancelledException();}//在打开任何项目之前调用此方法//具有 OpenInEditor 属性.public void BeforeOpeningFile(ProjectItem projectItem){}public void ProjectFinishedGenerating(项目项目){}//该方法只对项目模板调用,//不适用于项目模板.public void ProjectItemFinishedGenerating(ProjectItem项目){}//该方法在项目创建后调用.public void RunFinished(){}//该方法只对项目模板调用,//不适用于项目模板.public bool ShouldAddProjectItem(字符串文件路径){返回假;}}}

                  注意:WizardCancelledException 是必要的,否则 Visual Studio 会尝试生成/打开实际解决方案.尚不支持打开文件夹"类型的项目向导(没有用于此的 SDK API).

                  参考资料

                  • visual studio 模板问题&创建目录
                  • C# 用字典替换字符串

                  Visual Studio 2017 provides built-in support for handling CMake projects. The documentation mostly covers scenarios based on pre-existing cmake projects. But is there any support for creating a cmake project without having to fiddle with the CMakeLists.txt file?

                  解决方案

                  EDIT: VS2017 15.6 added an official New Project CMake Wizard

                  With version 15.6 came the feature of "Create CMake projects from the Add New Project dialog."

                  This creates a simple ninja based C++ "Hello CMake" project.

                  A Custom CMake Wizard

                  Your question and the lack of an existing Wizard inspired me to write one. It's a very basic setup and would most definitely benefit if people with more experience in writing Visual Studio extensions would contribute, but here it is:

                  https://github.com/FloriansGit/VSCMakeWizards

                  Edit: Latest VSIX installer is now also available for free on VS Marketplace

                  https://marketplace.visualstudio.com/items?itemName=oOFlorianOo.CMakeProjectWizards

                  The new "CMake Executable Template" will show up after a restart of your Visual Studio 2017 under "File/New/Project/Visual C++":

                  It generates the following files in the given folder and then uses "Open Folder" on it:

                  CMakeLists.txt
                  CMakeSettings.json
                  MyProject1.cpp 
                  

                  Next Steps

                  Possible next steps would be to:

                  • Add an interactive Wizard Dialog for some basic project/compiler settings
                  • Add also an Item Wizard to be able to add source files to the CMakeLists.txt

                  I'm looking forward getting feedback on the basic idea. Please add any requests directly to:

                  https://github.com/FloriansGit/VSCMakeWizards/issues

                  The Code

                  And here is the Wizards basic/initial code as a reference:

                  WizardImplementationClass.cs

                  // Based on https://docs.microsoft.com/en-us/visualstudio/extensibility/how-to-use-wizards-with-project-templates
                  //      and https://stackoverflow.com/questions/3882764/issue-with-visual-studio-template-directory-creation
                  
                  using System;
                  using System.IO;
                  using System.Collections.Generic;
                  using System.Text.RegularExpressions;
                  using EnvDTE;
                  using Microsoft.VisualStudio.TemplateWizard;
                  using Microsoft.VisualStudio.Shell;
                  using Microsoft.VisualStudio.Shell.Interop;
                  using EnvDTE80;
                  
                  namespace VSCMakeWizards
                  {
                      public class WizardImplementation : IWizard
                      {
                          public void RunStarted(object automationObject,
                              Dictionary<string, string> replacementsDictionary,
                              WizardRunKind runKind, object[] customParams)
                          {
                              var destinationDir = replacementsDictionary["$destinationdirectory$"];
                              var desiredNamespace = replacementsDictionary["$safeprojectname$"];
                              var templatePath = Path.GetDirectoryName((string)customParams[0]);
                  
                              var dte = automationObject as DTE2;
                              var solution = dte.Solution as EnvDTE100.Solution4;
                  
                              if (solution.IsOpen)
                              {
                                  solution.Close();
                              }
                  
                              File.Copy(Path.Combine(templatePath, "CMakeSettings.json"), Path.Combine(destinationDir, "CMakeSettings.json"));
                              File.Copy(Path.Combine(templatePath, "main.cpp"), Path.Combine(destinationDir, desiredNamespace + ".cpp"));
                  
                              // see https://stackoverflow.com/questions/1231768/c-sharp-string-replace-with-dictionary
                              Regex re = new Regex(@"($w+$)", RegexOptions.Compiled);
                              string input = File.ReadAllText(Path.Combine(templatePath, "CMakeLists.txt"));
                              string output = re.Replace(input, match => replacementsDictionary[match.Groups[1].Value]);
                  
                              File.WriteAllText(Path.Combine(destinationDir, "CMakeLists.txt"), output);
                  
                              var vsSolution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution7;
                  
                              if (vsSolution != null)
                              {
                                  vsSolution.OpenFolder(destinationDir);
                              }
                  
                              throw new WizardCancelledException();
                          }
                  
                          // This method is called before opening any item that   
                          // has the OpenInEditor attribute.  
                          public void BeforeOpeningFile(ProjectItem projectItem)
                          {
                          }
                  
                          public void ProjectFinishedGenerating(Project project)
                          {
                          }
                  
                          // This method is only called for item templates,  
                          // not for project templates.  
                          public void ProjectItemFinishedGenerating(ProjectItem
                              projectItem)
                          {
                          }
                  
                          // This method is called after the project is created.  
                          public void RunFinished()
                          {
                          }
                  
                          // This method is only called for item templates,  
                          // not for project templates.  
                          public bool ShouldAddProjectItem(string filePath)
                          {
                              return false;
                          }
                      }
                  }
                  

                  Note: The WizardCancelledException is necessary, because Visual Studio otherwise would try to generate/open an actual solution. An "Open Folder" kind of project wizard is not yet supported (no SDK API for this).

                  References

                  • Issue with visual studio template & directory creation
                  • C# String replace with dictionary

                  这篇关于使用 Visual Studio 创建一个 cmake 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                  <small id='8Rrrl'></small><noframes id='8Rrrl'>

                  <i id='8Rrrl'><tr id='8Rrrl'><dt id='8Rrrl'><q id='8Rrrl'><span id='8Rrrl'><b id='8Rrrl'><form id='8Rrrl'><ins id='8Rrrl'></ins><ul id='8Rrrl'></ul><sub id='8Rrrl'></sub></form><legend id='8Rrrl'></legend><bdo id='8Rrrl'><pre id='8Rrrl'><center id='8Rrrl'></center></pre></bdo></b><th id='8Rrrl'></th></span></q></dt></tr></i><div id='8Rrrl'><tfoot id='8Rrrl'></tfoot><dl id='8Rrrl'><fieldset id='8Rrrl'></fieldset></dl></div>
                2. <legend id='8Rrrl'><style id='8Rrrl'><dir id='8Rrrl'><q id='8Rrrl'></q></dir></style></legend>

                        <tbody id='8Rrrl'></tbody>
                        <tfoot id='8Rrrl'></tfoot>

                            <bdo id='8Rrrl'></bdo><ul id='8Rrrl'></ul>