Bug #839
closedCMake function "CHECK_FUNCTION_EXISTS" does not work on 32-bit Windows platforms
100%
Description
Our CMake script "GenerateDCMTKConfigure.cmake" contains several calls to the CMake function "CHECK_FUNCTION_EXISTS
".
This function apparently does not work reliably on Windows in 32 bit mode, because of name mangling in the ABI calling conventions.
For example, on library level, the function gethostname()
has the symbol __imp__gethostname@8
, and the test
CHECK_FUNCTION_EXISTS(gethostname HAVE_GETHOSTNAME)returns "not found" on 32-bit Windows despite the function being present.
This is even documented in the CMake manual: [[https://cmake.org/cmake/help/v3.8/module/CheckFunctionExists.html]]
Prefer using CheckSymbolExists instead of this module, for the following reasons:- check_function_exists() can’t detect functions that are inlined in headers or specified as a macro.
- check_function_exists() can’t detect anything in the 32-bit versions of the Win32 API, because of a mismatch in calling conventions.
- check_function_exists() only verifies linking, it does not verify that the function is declared in system headers.
Using "CHECK_SYMBOL_EXISTS
" is not a solution because it checks the declaration of a function in a header file,
and not the presence of a symbol in a library. On some platforms, like Solaris, there are some functions present
in a system library but the declaration in the header files is missing, and some tests explicitly look for that situation.
This would break if we just moved all tests to "CHECK_SYMBOL_EXISTS
".
I would propose to define a new test function that calls CHECK_SYMBOL_EXISTS when running on (32 bit?) Windows
and CHECK_FUNCTION_EXISTS in all other cases. This new function should then replace all calls
to "CHECK_FUNCTION_EXISTS
" in "GenerateDCMTKConfigure.cmake". This will make sure that the tests for
missing function declarations continue to work, while making sure that system functions are found correctly on Windows.
The case where a system function exists but is not declared in any header file has not occured yet on Windows,
so the unability of the new function to detect this situation is acceptable.
Updated by Jan Schlamelcher almost 7 years ago
- Assignee set to Jan Schlamelcher
Close by commit #a3102b2b7576dcf2.
Updated by Jan Schlamelcher almost 7 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100