How to add dependencies based on C file contents?


I am compiling some C++ code in a custom system which has file dependencies defined in the contents which also need to be compiled and linked.
Does anything know how this could be done?


// Dependencies defined here
// dep: something.cpp

#include <something.hpp>

int main()
  return 0;

(Chris Doré) #2

Is this code already being built by some system? If so, how are the dependencies parsed and managed in that system? What does the file tree look like?


The code is being built using a system written with rake. The file is parsed for any source dependencies specified at the top of the file as a comment, to be compiled in. The path of it is relative to the current file.

The reason it has been done like this is for test purposes for the ability to selectively compile either mocks or the actual source.

(Chris Doré) #4

I’m not familiar with rake at all, is this a feature it provides or is this some custom functionality you’ve baked in?
You may be able to port this functionality into Gradle and configure the C++ model as needed. I’m guessing you’ve already taken a look at the native software documentation in the user guide.

Have you considered refactoring/reorganizing the mocks vs real code into static libs and then switching between them with the linker? That might relatively easy to model using the existing Gradle C++ support, but I’m not totally sure since my native experience in Gradle is limited to some basic experiments.

(Chris Doré) #5

There’s another thread that is similar in nature to this one. I made a sample project that reads the dependencies from a source file How to override getInputs()?
I’m not really sure how you could fit such a thing into the native build support but maybe it’ll help you in some way.