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

I created a project using cmake and some libraries. However, I want to add some header and .cpp files to the project I'm going to create. What is the easiest way to do this? Can I just create a. cpp and header files, and then create the project again in Visual Studio? Or because the project was built using cmake, I can’t?

+5
source share
3 answers

You can put all the header / source files in the same folder and use something like

file(GLOB SOURCES header-folder/*.h source-folder/*.cpp ) add_executable(yourProj ${SOURCES}) 

Thus, you can use either of the following two methods to add the newly added header / source to VS:

  • need to be created again in CMake.
  • fake for editing CMakeLists.txt bit, for example. just add a space. And then create your solution in VS, it will automatically add new header / source files.
+8
source

you need to add each .h and .cpp file to CMakeList.txt as follows:

 # 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 re-create the solution and reload it in VS.

+2
source

Although his late reply and I only saw him. I use the CLion IDE from JetBrains, which automatically adds these header and .cpp files when they are created. Althogh, this may not be your need. It can be useful for other people who see it.

0
source

All Articles