且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在使用 cmake 构建的项目中添加头文件和 .cpp 文件

更新时间:2023-11-12 21:30:16

您可以将所有头文件/源文件放在同一个文件夹中并使用类似

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})

这样,您可以通过以下两种方法之一将新添加的 header/source 添加到 VS 中:

In this way, you can do either of the following two methods to add new added header/source into VS:

  1. 需要再次在 CMake 中生成.
  2. 假编辑CMakeLists.txt 一点点,例如只需添加一个空格.然后在 VS 中构建您的解决方案,它会自动添加新的头文件/源文件.
  1. need to generate in CMake again.
  2. 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.