MantisBT - CMake
View Issue Details
0011565CMakeCMakepublic2010-12-02 16:352016-06-10 14:31
Daniel Richard G. 
Kitware Robot 
normalfeaturealways
closedmoved 
CMake-2-8 
 
0011565: CHECK_{FUNCTION,LIBRARY}_EXISTS() macros need a way to specify function declaration
I want to check for the existence of a library+function. On Windows, however, the function must be declared using the WINAPI keyword (which is available after #including<windows.h>) in order for the linker to find it. This keyword changes the symbol that the linker looks for in a manner that cannot otherwise be represented in valid C code, so there is no alternative to its use.

There is currently no way to shoehorn this keyword into the C file used by the CHECK_{FUNCTION,LIBRARY}_EXISTS() macros, or otherwise to modify the trivial "char foo();" function declaration therein; the best you can do is create a custom C file and invoke TRY_COMPILE() yourself.
No tags attached.
related to 0010090closed Brad King check_prototype_definition() - Check if the protoype we expect is correct 
Issue History
2010-12-02 16:35Daniel Richard G.New Issue
2011-01-17 12:57David ColeNote Added: 0024777
2011-01-17 12:57David ColeAssigned To => David Cole
2011-01-17 12:57David ColeStatusnew => assigned
2011-01-17 13:17Daniel Richard G.Note Added: 0024781
2011-01-17 13:20Daniel Richard G.Note Edited: 0024781bug_revision_view_page.php?bugnote_id=24781#r135
2011-01-17 14:34David ColeRelationship addedrelated to 0010090
2011-02-09 13:58David ColeStatusassigned => backlog
2011-02-09 13:59David ColeAssigned ToDavid Cole =>
2011-03-18 14:11Brad KingNote Added: 0025820
2011-03-18 14:41Daniel Richard G.Note Added: 0025823
2016-06-10 14:28Kitware RobotNote Added: 0041767
2016-06-10 14:28Kitware RobotStatusbacklog => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0024777)
David Cole   
2011-01-17 12:57   
I suggest invoking try_compile yourself with exactly the right details according to what you're looking for.

Do you have a suggestion for making this a more general purpose facility? A concrete proposed patch, including documentation and testing...?

Are you currently using a home-made CMake macro or function of any sort?
(0024781)
Daniel Richard G.   
2011-01-17 13:17   
(edited on: 2011-01-17 13:20)
I'm using try_compile() directly at the moment, but it seems silly to have to do that when all you want to change is a small part of the function declaration.

What about a new variable that can be set before calling the function to modify the declaration? Where you could do e.g.

    set(CMAKE_REQUIRED_DECLARATION "WINAPI int")

and that gets used in the C code instead of "char"?

Of course, that would also need the Windows header... maybe something like

    set(CMAKE_REQUIRED_PREAMBLE "#ifdef WIN32\n#include<windows.h>\n#endif")

as well?

(0025820)
Brad King   
2011-03-18 14:11   
Please see the fix to issue 0010090:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4f252abe [^]

Is this sufficient?
(0025823)
Daniel Richard G.   
2011-03-18 14:41   
In my particular case, I'm checking for a function in a library for which no header file is available. (I.e. the consuming code provides the prototype.)

A link stage is still necessary, especially here when it's with a non-default ABI.
(0041767)
Kitware Robot   
2016-06-10 14:28   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.