Adding header and .cpp files in a project built with cmake

后端 未结 3 1424
清歌不尽
清歌不尽 2020-12-03 14:22

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

3条回答
  •  眼角桃花
    2020-12-03 14:40

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

    In this way, you can do either of the following two methods to add new added header/source into 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.

提交回复
热议问题