Creating a cmake project with visual studio(使用 Visual Studio 创建一个 cmake 项目)
问题描述
Visual Studio 2017 为处理 CMake 项目提供内置支持.
这将创建一个简单的
它在给定的文件夹中生成以下文件,然后在其上使用打开文件夹":
后续步骤
可能的下一步是:
- 为一些基本的项目/编译器设置添加一个交互式向导对话框
- 还添加了一个项目向导,以便能够将源文件添加到
CMakeLists.txt
我期待收到有关基本想法的反馈.请将任何请求直接添加到:
https://github.com/FloriansGit/VSCMakeWizards/issues
代码
这里是威世智的基本/初始代码作为参考:
WizardImplementationClass.cs
注意: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:
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
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 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!