MantisBT - CMake
View Issue Details
0010044CMakeModulespublic2009-12-12 19:042011-01-31 16:02
Johannes Simon 
Brad King 
normalminoralways
closedfixed 
CMake-2-8 
CMake 2.8.4CMake 2.8.4 
0010044: check_function_exists( fdatasync HAVE_FDATASYNC ) erroneously sets HAVE_FDATASYNC to 1
On Mac OS X 10.6 (Snow Leopard), and probably on Mac OS X in general, check_function_exists(fdatasync HAVE_FDATASYNC) will wrongly set HAVE_FDATASYNC to 1, though there is no such function on Mac OS. There's only fsync.
To test it, the following CMakeLists.txt will do:
  1 include(CheckFunctionExists)
  2 check_function_exists(fdatasync HAVE_FDATASYNC)
  3 message( ${HAVE_FDATASYNC} )
No tags attached.
related to 0011685closed Brad King CHECK_SYMBOL_EXISTS doesn't find enum constants 
Issue History
2009-12-12 19:04Johannes SimonNew Issue
2010-08-03 12:24Kovarththanan RajaratnamCategoryCMake => Modules
2011-01-17 12:25David ColeAssigned To => Brad King
2011-01-17 12:25David ColeStatusnew => assigned
2011-01-17 12:26David ColeNote Added: 0024773
2011-01-17 12:50Brad KingNote Added: 0024774
2011-01-17 12:51Brad KingNote Added: 0024775
2011-01-17 12:52Brad KingNote Added: 0024776
2011-01-17 12:55Brad KingRelationship addedrelated to 0011685
2011-01-17 14:08Brad KingNote Added: 0024784
2011-01-17 14:08Brad KingStatusassigned => closed
2011-01-17 14:08Brad KingResolutionopen => fixed
2011-01-31 16:02David ColeFixed in Version => CMake 2.8.4
2011-01-31 16:02David ColeTarget Version => CMake 2.8.4

Notes
(0024773)
David Cole   
2011-01-17 12:26   
Brad,

I can reproduce this, but I'm not 100% certain about what's going wrong yet... Is this just a short-coming of CheckFunctionExists, or is this a real problem that needs fixing?
(0024774)
Brad King   
2011-01-17 12:50   
The effective test source file used by the try_compile is:

$ cat test.c
char fdatasync();
int main(void) {
  fdatasync();
  return 0;
}

which does compile:

$ gcc test.c

The CheckSymbolExists module is better because it actually ensures there is a declaration in the header file.
(0024775)
Brad King   
2011-01-17 12:51   
$ nm /usr/lib/libSystem.B.dylib |grep fdatasync
00000000000b46f0 t ___fdatasync
00000000000b46f0 T _fdatasync
(0024776)
Brad King   
2011-01-17 12:52   
$ grep fdatasync /usr/include/* /usr/include/sys/*
/usr/include/sys/syscall.h:#define SYS_fdatasync 187
(0024784)
Brad King   
2011-01-17 14:08   
I clarified the documentation of the module to state exactly what is checked:

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

In that sense this is "fixed".

Use CheckSymbolExists to verify that a declaration is available too. Use CheckCSourceCompiles to try compiling and linking an actual call to the function.