Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically add header files to project?

How would I go about having a CMake buildsystem, which scans for source files now using AUX_SOURCE_DIRECTORY, scan for header files too in the same directory, preferably using a similar command?

I didn't find an easy way to do this in the documentation yet, so I now have a crappy bash script to post-process my (CodeBlocks) project file...

like image 313
Tobi Avatar asked Nov 09 '08 12:11

Tobi


People also ask

How do I add a header path in Visual Studio?

Place your caret on the first line of any C# or Visual Basic file. Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Add file header. To apply the file header to an entire project or solution, select Project or Solution under the Fix all occurrences in: option.

How do you keep the same header file being added multiple times?

To avoid multiple inclusions of the same header file we use the #ifndef, #define and #endif preprocessor directives. Just write the entire program in only file and include headers once only.

How do I insert a header from another project?

In the project where you want to #include the header file from another project, you will need to add the path of the header file into the Additional Include Directories section in the project configuration. To access the project configuration: Right-click on the project, and select Properties.

Can you use header files twice in a program?

If a header file happens to be included twice, the compiler will process its contents twice. This is very likely to cause an error, e.g. when the compiler sees the same structure definition twice. Even if it does not, it will certainly waste time.


1 Answers

You can use the file(GLOB ... ) command. For example:

set(dir my_search_dir)
file (GLOB headers "${dir}/*.h")
message("My headers: " ${headers})

This command can also recurse, and list your files relative to a given path. See the "file" command entry in the cmake doc.

like image 84
David Avatar answered Nov 09 '22 10:11

David