Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include all files of a directory with cmake?

I want to try CMake to manage a new C++ project. However, some files are automatically generated. I have no way to know the name of the generated files. The only thing I know is that these files are all generated in the foo/ directory. Is there a way to ask CMake to include all .cpp files from foo/ ?

Thank you.

like image 524
ascobol Avatar asked Jul 17 '09 14:07

ascobol


People also ask

How do I include a directory in CMake?

First, you use include_directories() to tell CMake to add the directory as -I to the compilation command line. Second, you list the headers in your add_executable() or add_library() call.

Where does CMake look for include files?

cmake is searched first in CMAKE_MODULE_PATH , then in the CMake module directory. There is one exception to this: if the file which calls include() is located itself in the CMake builtin module directory, then first the CMake builtin module directory is searched and CMAKE_MODULE_PATH afterwards.

What does Add_subdirectory do in CMake?

Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.


1 Answers

You may do this with GLOB

FILE(GLOB ALL_CPP_SRCS *.cpp)
like image 87
J-16 SDiZ Avatar answered Oct 05 '22 17:10

J-16 SDiZ