'How to use check_prototype_definition in CMake

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...



Solution 1:[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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 arrowd