I'm trying to split my code to multiple files for the sake of code clarity and ease of debugging since I notices I'm scrolling too much ,trying to achieve it like with arduino tabs as this guys explains here: https://www.youtube.com/watch?v=HtYlQXt14zU
does anybody know how to do it or if it's possible without creating header files and using #include,lib.h> for the other source files?
Concatenating and compiling multiple source files in ESP IDF CMAKE? (Similar to arduino tabs)
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: Concatenating and compiling multiple source files in ESP IDF CMAKE? (Similar to arduino tabs)
You could theoretically add a hack to your CMakeFiles to concatenate source files before compiling it, but you'd run into file order issues... there's not really a clean way to do it. Better to bite the bullet and make header files.
Re: Concatenating and compiling multiple source files in ESP IDF CMAKE? (Similar to arduino tabs)
The reason behind splitting and concatenating files rather than make a library for each is that the functions I write and want to put in the other source files activate and read other functions and global variables from the main.c file that I want to access there without tripling or more my work by not having to create more folders header files extra declarations extra double the memory and pointer engineer all the methods, that's why it makes sense to split and concatenate main.c to multiple source files, correct me if I'm wrong.
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: Concatenating and compiling multiple source files in ESP IDF CMAKE? (Similar to arduino tabs)
There's no reason why using separate C files and headers would use more memory; you can simply declare your global variables as extern in your headers as well. Aside from that, well, if you still insist on getting this to work, while esp-idf does not support this out of the box, the build system does have hooks to generate source files from something else; perhaps you can hack that into something usable.
Re: Concatenating and compiling multiple source files in ESP IDF CMAKE? (Similar to arduino tabs)
I was just sure that's how programmers with big system projects do it this way since using the file concatenation method is realy just a cut and paste solution rather then then header file library approach which requires more involvement and thinking which is hard and sucks when no-one pays you to do it which is the case with this currently personal project which will also be a base for my further official projects and contributions.
Anyways this section in the link you send might be the way to do concatenation but ESP doesn't give specific references and examples to their explanations in the docs so I can't confirm what is FOO there and how'd behave.
Anyways I just needed to hear from more pro people that have experience with creating big system project(similar to marlin 3D printing controller but with CMAKE instead of arduino) that it's acceptable to create a header for init and declaration source files in project and not with concatenation and CMAKE.
BTW @Sprite do you mind sharing a large project you made with ESP IDF or direct me to something available I can look through to take examples from?
Anyways this section in the link you send might be the way to do concatenation but ESP doesn't give specific references and examples to their explanations in the docs so I can't confirm what is FOO there and how'd behave.
Anyways I just needed to hear from more pro people that have experience with creating big system project(similar to marlin 3D printing controller but with CMAKE instead of arduino) that it's acceptable to create a header for init and declaration source files in project and not with concatenation and CMAKE.
BTW @Sprite do you mind sharing a large project you made with ESP IDF or direct me to something available I can look through to take examples from?
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: Concatenating and compiling multiple source files in ESP IDF CMAKE? (Similar to arduino tabs)
Sure. Note that in ESP-IDF, some people even go a step further and make things like drivers not only into separate source files, but even separate components. One (somewhat extreme) example of that would be esp-drone. MrBuddyCasino's WiFi BT radio project also does that, but is less extreme. (I personally only tend to stuff the larger drivers, with actual business logic, into separate components, but that's a matter of taste.) If you want something comparable with Merlin, you could look at FluidNC which has a similar purpose; it does not use components to separate the code but uses the 'classic' way of having directories full of source files.
Re: Concatenating and compiling multiple source files in ESP IDF CMAKE? (Similar to arduino tabs)
Thanks again for saving the day and being super useful once again very appreciated,
The esp-drone example is particularly useful I'll try compiling my code with a CMAKE structure similar to his and see how I get started going with the idf_component_register() components registration method in cmake without getting errors later.
The esp-drone example is particularly useful I'll try compiling my code with a CMAKE structure similar to his and see how I get started going with the idf_component_register() components registration method in cmake without getting errors later.
Who is online
Users browsing this forum: Majestic-12 [Bot] and 94 guests