Blob Blame Raw
From 5203c6c7b388e65ceeb7315c5bafa93e71d17a8e Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Sat, 2 Oct 2010 17:54:11 +0400
Subject: [PATCH 13/19] Search for possibly missing res_search

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
 CMakeLists.txt                |  6 ++++
 cmake/CheckSymbolExists.cmake | 83 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100644 cmake/CheckSymbolExists.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1302857..34f27e5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -213,6 +213,12 @@ ELSE(LIBEV_FOUND)
 ENDIF(LIBEV_FOUND)
 
 
+# Check for res_search in -lresolv
+include(${CMAKE_SOURCE_DIR}/cmake/CheckSymbolExists.cmake)
+SET(CMAKE_REQUIRED_LIBRARIES resolv)
+CHECK_SYMBOL_EXISTS(res_search resolv.h HAVE_RES_SEARCH)
+MESSAGE(STATUS "Have res_search: ${HAVE_RES_SEARCH} ")
+
 INCLUDE_DIRECTORIES (${SEMS_SOURCE_DIR}/core/ampi)
 INCLUDE_DIRECTORIES (${SEMS_SOURCE_DIR}/core/amci)
 INCLUDE_DIRECTORIES (${SEMS_SOURCE_DIR}/core)
diff --git a/cmake/CheckSymbolExists.cmake b/cmake/CheckSymbolExists.cmake
new file mode 100644
index 0000000..d48b65f
--- /dev/null
+++ b/cmake/CheckSymbolExists.cmake
@@ -0,0 +1,83 @@
+# - Check if the symbol exists in include files
+# CHECK_SYMBOL_EXISTS(SYMBOL FILES VARIABLE)
+#
+#  SYMBOL   - symbol
+#  FILES    - include files to check
+#  VARIABLE - variable to return result
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
+#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+#  CMAKE_REQUIRED_INCLUDES = list of include directories
+#  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+
+#=============================================================================
+# Copyright 2003-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distributed this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+MACRO(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
+  IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+    SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
+    SET(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS})
+    IF(CMAKE_REQUIRED_LIBRARIES)
+      SET(CHECK_SYMBOL_EXISTS_LIBS 
+        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
+    ELSE(CMAKE_REQUIRED_LIBRARIES)
+      SET(CHECK_SYMBOL_EXISTS_LIBS)
+    ENDIF(CMAKE_REQUIRED_LIBRARIES)
+    IF(CMAKE_REQUIRED_INCLUDES)
+      SET(CMAKE_SYMBOL_EXISTS_INCLUDES
+        "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+    ELSE(CMAKE_REQUIRED_INCLUDES)
+      SET(CMAKE_SYMBOL_EXISTS_INCLUDES)
+    ENDIF(CMAKE_REQUIRED_INCLUDES)
+    FOREACH(FILE ${FILES})
+      SET(CMAKE_CONFIGURABLE_FILE_CONTENT
+        "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
+    ENDFOREACH(FILE)
+    SET(CMAKE_CONFIGURABLE_FILE_CONTENT
+      "${CMAKE_CONFIGURABLE_FILE_CONTENT}\nvoid cmakeRequireSymbol(int dummy,...){(void)dummy;}\nint main()\n{\n#ifndef ${SYMBOL}\n  cmakeRequireSymbol(0,&${SYMBOL});\n#endif\n  return 0;\n}\n")
+
+    CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
+      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" @ONLY)
+
+    MESSAGE(STATUS "Looking for ${SYMBOL}")
+    TRY_COMPILE(${VARIABLE}
+      ${CMAKE_BINARY_DIR}
+      ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c
+      COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+      CMAKE_FLAGS 
+      -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS}
+      "${CHECK_SYMBOL_EXISTS_LIBS}"
+      "${CMAKE_SYMBOL_EXISTS_INCLUDES}"
+      OUTPUT_VARIABLE OUTPUT)
+    IF(${VARIABLE})
+      MESSAGE(STATUS "Looking for ${SYMBOL} - found")
+      SET(${VARIABLE} 1 CACHE INTERNAL "Have symbol ${SYMBOL}")
+      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
+        "Determining if the ${SYMBOL} "
+        "exist passed with the following output:\n"
+        "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c:\n"
+        "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
+    ELSE(${VARIABLE})
+      MESSAGE(STATUS "Looking for ${SYMBOL} - not found.")
+      SET(${VARIABLE} "" CACHE INTERNAL "Have symbol ${SYMBOL}")
+      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
+        "Determining if the ${SYMBOL} "
+        "exist failed with the following output:\n"
+        "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c:\n"
+        "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
+    ENDIF(${VARIABLE})
+  ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+ENDMACRO(CHECK_SYMBOL_EXISTS)
-- 
1.8.3.1