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

you need to add every .h and .cpp file to CMakeList.txt like this:

# Local header files here ONLY
SET(TARGET_H
    Header.h
    Plugin.h
    messagelog.h
    win32application.h
    timer.h    
   )

# Local source files here
SET(TARGET_SRC
    Plugin.cpp
    messagelog.cpp
    win32application.cpp
    timer.cpp
    )

then configure and build the solution again and reload it in VS.


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.