I have a C program which has lots of includes in it, There are lots of macros in use to auto generate functions for the modules and in the build process, for example
#define MODULE_DEFINE(M) void M##_init (module* module) {\
module->name = #M;
#define MODULE_END };
MODULE_DEFINE (hello)
printf("module name is : %s\n",module->name);
MODULE_END
Now once the modules are compiled and linked, i need to include them all inside a common header file . One method would be to manually include all of them, but i am wondering if there is some better way to go around it ? I am already passing on them as as array shown below.
module mod_list[] = {
MOD( hello )
};
The MOD
used is yet another macro. Now the relevant part is, all the modules follow the include as
#include <modules/hello.h>
as in the example shown above. Can i somehow iterate over or create a list to auto-include from the list ? I don't mind changing from array to something else because i know that an array is defined at runtime and not possible for macro to actually iterate over that. If the iteration is possible i can define a common list to make all includes and define the array thereby automating the process a little. Thanks for any help.
Edit
As pointed this is not entirely possible only with macros. Now i am using CMake
as my build tool. All the modules are placed in a separate directory in the format
modules
└── hello
├── hello.c
└── hello.h
So can i somehow list all folders in CMake
inside modules and pass them to configure_file
to make the needed imports ?
So can i somehow list all folders in CMake inside modules
- file(GLOB) should help you in that task.and pass them to configure_file to make the needed imports?
- Withfor
loop on folders found, you may fill a variable with a list of#include<>
directives. Then you may use this variable inconfigure_file
.