2

I am looking at the documentation of check_prototype_definition here: https://cmake.org/cmake/help/latest/module/CheckPrototypeDefinition.html

check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE)

FUNCTION - The name of the function (used to check if prototype exists)
PROTOTYPE- The prototype to check.
RETURN - The return value of the function.
HEADER - The header files required.
VARIABLE - The variable to store the result.
           Will be created as an internal cache variable.

I don't understand what RETURN value of the function means, I am not passing parameters to the function I am checking the prototype, is this the value to store in named VARIABLE ?

I see a function name, a prototype (which I guess includes the function) and a header... Is the exact prototype string matched and found inside the header?

I can't seem to find much information online on how to use this...

eri0o
  • 2,285
  • 4
  • 27
  • 43

1 Answers1

1

According to CheckPrototypeDefinition.cmake, the check works by implementing a function with a PROTOTYPE signature. Literally. That is, CMake creates a source file with, say

struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)
{
     ???
}

And to make it compile, it also has to put something instead of ???. This part is filled with

return RETURN;

So, you can provide any valid value that matches the return value of the signature you're checking for: 0 for int, "blabla" for char* and so on.

arrowd
  • 33,231
  • 8
  • 79
  • 110
  • I feel like this moves me closer to understand the mechanism but I still am not quite sure on the usecase for this. Is it to check an attribute is correctly defined in a header? I am failing at grasping which problems this is meant to solve. :/ – eri0o Mar 28 '22 at 12:43
  • @eri0o "this" - the `RETURN` keyword? You simply can't use `check_prototype_definition` without providing a correct `RETURN` value. – arrowd Mar 28 '22 at 13:51
  • @eri0o If you're talking about `check_prototype_definition`, then it is used when you want to check not only function's existence, but also its signature. For instance, some non-POSIX C functions have different number of arguments on Linux and FreeBSD. – arrowd Mar 28 '22 at 13:53