问题描述
我已经使用cmake和一些库构建了一个项目。但是我想在要编写代码的项目中添加一些头文件和.cpp文件,最简单的方法是什么?我可以创建一个。 cpp和头文件,然后在Visual Studio中再次构建项目?还是由于我不能使用cmake构建项目?
I have built a project using cmake and some libraries.I want however to add some header and .cpp files in the project which I am going to code.What is the easiest way to do it?Can I just create a .cpp and header files and then build again project in Visual Studio? Or due to the fact that project was built using cmake I can't?
推荐答案
您可以将所有头文件/源文件放入相同的文件夹并使用类似的东西
You can put all header/source files in the same folder and use something like
file(GLOB SOURCES
header-folder/*.h
source-folder/*.cpp
)
add_executable(yourProj ${SOURCES})
通过这种方式,您可以执行以下两种方法之一,将新添加的标头/源添加到VS:
In this way, you can do either of the following two methods to add new added header/source into VS:
- 需要再次在CMake中生成。
- 伪造一些内容来编辑
CMakeLists.txt
,例如只需添加一个空格。然后在VS中构建解决方案,它将自动添加新的头文件/源文件。
- need to generate in CMake again.
- fake to edit the
CMakeLists.txt
a little bit, e.g. simply add a space. And then build your solution in VS, it will automatically add new header/source files.
这篇关于在使用cmake构建的项目中添加标头和.cpp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!