1

Recently I have learnt a gcc compile option called -finstrument-functions. What it does is to add a function decorator to each function, by changing the function from

void f(...) {
  ...
}

into

void f(...) {
  __cyg_profile_func_enter(this_func, call_site);
  ...
  __cyg_profile_func_exit(this_func, call_site);
}

What I need to do is to add the definition of __cyg_profile_func_enter and __cyg_profile_func_exit.

It is easy to add the definition in a small project with only a few files, but how could I add the function definition to all files in a big cmake project? Is there an option in cmake, or a compile option, to add the definition without updating the configuration of all targets in the cmake project manually?

Acesrc
  • 21
  • 3
  • What you want to add is not a "global definition and declaration" but rather a compiler flag, right? Updating your question title might give better answers. – Thomas Mar 20 '22 at 09:30
  • Reading https://stackoverflow.com/questions/6176284/why-doesnt-finstrument-functions-work-for-me, it seems to me that you don't need to declare these functions (the magic is added by the compiler) but you do need to define them. This is done by linking with an object file that contains the definitions, but you need to do that only once per resulting artifact (executable or library). – Thomas Mar 20 '22 at 09:32
  • @Thomas I am looking forward to a way to do that linking in the case that you don't fully understand the the cmake structure of the project. – Acesrc Mar 20 '22 at 09:55

0 Answers0