]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Improve cmake detecting a function on linux.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 19 Mar 2009 22:21:35 +0000 (18:21 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Thu, 19 Mar 2009 22:21:35 +0000 (18:21 -0400)
The GNU C library defines stub functions(chflags, fchflags..),
and so cmake detecting the function process found out that
stub function. This commit avoid detecting the stub function.

SVN-Revision: 812

build/cmake/CheckFuncs.cmake
build/cmake/CheckFuncs_stub.c.in [new file with mode: 0644]

index b7aa3f166d59ccd726215668fd01eabbc32cbd59..108774fdd42c1d67924caf309befb85b454d0921 100644 (file)
@@ -14,7 +14,6 @@
 # Redistribution and use is allowed according to the terms of the BSD license.
 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 
-
 INCLUDE(CheckFunctionExists)
 INCLUDE(CheckSymbolExists)
 
@@ -23,17 +22,34 @@ MACRO (CHECK_FUNCS _FUNCS)
       STRING(TOUPPER ${_func} _funcvar)
       SET(_funcvar "HAVE_${_funcvar}")
       SET(_include "")
-      IF (WIN32 AND "${_func}" MATCHES "^wmemcmp$")
-        SET(_include "wchar.h")
-      ENDIF (WIN32 AND "${_func}" MATCHES "^wmemcmp$")
-      IF (WIN32 AND "${_func}" MATCHES "^wmemcpy$")
-        SET(_include "wchar.h")
-      ENDIF (WIN32 AND "${_func}" MATCHES "^wmemcpy$")
-      IF ("${_include}" STREQUAL "")
-        CHECK_FUNCTION_EXISTS("${_func}" "${_funcvar}")
-      ELSE ("${_include}" STREQUAL "")
-        CHECK_SYMBOL_EXISTS("${_func}" "${_include}" "${_funcvar}")
-      ENDIF ("${_include}" STREQUAL "")
+      IF ("${_funcvar}" MATCHES "^${_funcvar}$")
+        IF (WIN32 AND "${_func}" MATCHES "^wmemcmp$")
+          SET(_include "wchar.h")
+        ENDIF (WIN32 AND "${_func}" MATCHES "^wmemcmp$")
+        IF (WIN32 AND "${_func}" MATCHES "^wmemcpy$")
+          SET(_include "wchar.h")
+        ENDIF (WIN32 AND "${_func}" MATCHES "^wmemcpy$")
+        IF ("${_include}" STREQUAL "")
+          SET(CHECK_STUB_FUNC_1 "__stub_${_func}")
+          SET(CHECK_STUB_FUNC_2 "__stub___${_func}")
+          CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/build/cmake/CheckFuncs_stub.c.in
+            ${CMAKE_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c IMMEDIATE)
+          TRY_COMPILE(__stub
+            ${CMAKE_BINARY_DIR}
+            ${CMAKE_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c
+            COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+            CMAKE_FLAGS
+            -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
+            "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}")
+          IF (__stub)
+            SET("${_funcvar}" "" CACHE INTERNAL "Have function ${_func}")
+          ELSE (__stub)
+            CHECK_FUNCTION_EXISTS("${_func}" "${_funcvar}")
+          ENDIF (__stub)
+        ELSE ("${_include}" STREQUAL "")
+          CHECK_SYMBOL_EXISTS("${_func}" "${_include}" "${_funcvar}")
+        ENDIF ("${_include}" STREQUAL "")
+      ENDIF ("${_funcvar}" MATCHES "^${_funcvar}$")
    ENDFOREACH (_func)
 ENDMACRO (CHECK_FUNCS)
 
diff --git a/build/cmake/CheckFuncs_stub.c.in b/build/cmake/CheckFuncs_stub.c.in
new file mode 100644 (file)
index 0000000..50da414
--- /dev/null
@@ -0,0 +1,16 @@
+#ifdef __STDC__
+#include <limits.h>
+#else
+#include <assert.h>
+#endif
+
+int
+main()
+{
+#if defined ${CHECK_STUB_FUNC_1} || defined ${CHECK_STUB_FUNC_2}
+  return 0;
+#else
+this system have stub
+  return 0;
+#endif
+}