Make building with GeoIP, Python, Capabilities and c-ares
authorJörg Mayer <jmayer@loplof.de>
Sat, 12 Sep 2009 17:20:08 +0000 (17:20 -0000)
committerJörg Mayer <jmayer@loplof.de>
Sat, 12 Sep 2009 17:20:08 +0000 (17:20 -0000)
actually work.

svn path=/trunk/; revision=29870

CMakeLists.txt
ConfigureChecks.cmake
README.cmake
cmake/modules/FindCAP.cmake
cmake/modules/FindCARES.cmake
cmake/modules/FindPYTHON.cmake [new file with mode: 0644]
cmakeconfig.h.in
epan/CMakeLists.txt

index 6e1d94a9c5d7abb19a87fa182f6deede9123c769..217281aa106f320b240d8763b21094589c9571c6 100644 (file)
@@ -82,17 +82,17 @@ option(ENABLE_ADNS       "Build with adns support" ON)
 option(ENABLE_PCRE       "Build with pcre support" ON)
 option(ENABLE_PORTAUDIO  "Build with portaudio support" ON)
 option(ENABLE_Z                 "Build with zlib compression support" ON)
+# todo wslua currently seems to be broken
 option(ENABLE_LUA       "Build with lua dissector support" OFF)
+option(ENABLE_PYTHON    "Build with python dissector support" ON)
 option(ENABLE_SMI       "Build with smi snmp support" ON)
 option(ENABLE_GNUTLS    "Build with GNU TLS support" ON)
 option(ENABLE_GCRYPT    "Build with GNU crypto support" ON)
+option(ENABLE_GEOIP     "Build with GeoIP support" ON)
+option(ENABLE_CAP       "Build with posix capabilities support" ON)
+option(ENABLE_CARES      "Build with c_ares support" ON)
 # todo Mostly hardcoded
 option(ENABLE_KERBEROS  "Build with Kerberos support" ON)
-# Untested
-option(ENABLE_GEOIP     "Build with GeoIP support" OFF)
-option(ENABLE_CAP       "Build with posix capabilities support" OFF)
-option(ENABLE_CARES      "Build with c_ares support" OFF)
-option(ENABLE_PYTHON    "Build with python dissector support" OFF)
 
 
 if(ENABLE_EXTRA_GCC_CHECKS)
@@ -154,13 +154,11 @@ if(ENABLE_PORTAUDIO)
        set(PACKAGELIST PORTAUDIO ${PACKAGELIST})
 endif()
 
-# C Asynchronouse resolver
-if(ENABLE_CARES)
-       set(PACKAGELIST CARES ${PACKAGELIST})
-endif()
 
-#Gnu asynchronous DNS
-if(ENABLE_ADNS)
+# Prefer c-ares over adns
+if(ENABLE_CARES)        # C Asynchronouse resolver
+       set(PACKAGELIST CARES ${PACKAGELIST})
+elseif(ENABLE_ADNS)     # Gnu asynchronous DNS
        set(PACKAGELIST ADNS ${PACKAGELIST})
 endif()
 
@@ -184,6 +182,10 @@ if(ENABLE_CAP)
        set(PACKAGELIST CAP ${PACKAGELIST})
 endif()
 
+if(ENABLE_PYTHON)
+       set(PACKAGELIST PYTHON ${PACKAGELIST})
+endif()
+
 set(PROGLIST text2pcap mergecap capinfos editcap dumpcap)
 
 #Let's loop the package list
@@ -191,24 +193,17 @@ foreach(PACKAGE ${PACKAGELIST})
        find_package(${PACKAGE} REQUIRED)
        message(${PACKAGE}_FOUND)
        if (${PACKAGE}_FOUND)
-               set(HAVE_LIB${PACKAGE} "1")
+               set(HAVE_LIB${PACKAGE} 1)
                include_directories(${${PACKAGE}_INCLUDE_DIRS})
                message(STATUS "${PACKAGE} includes: ${${PACKAGE}_INCLUDE_DIRS}")
                message(STATUS "${PACKAGE} libs: ${${PACKAGE}_LIBRARIES}")
        endif()
 endforeach()
 
-if(ENABLE_PYTHON)
-       find_package(FindPythonLibs)
-       message(PYTHONLIBS_FOUND)
-       if (PYTHONLIBS_FOUND)
-               set(HAVE_LIBPYTHON "1")
-               include_directories(PYTHON_INCLUDE_PATH)
-               message(STATUS "${PACKAGE} includes: ${PYTHON_INCLUDE_PATH}")
-               message(STATUS "${PACKAGE} libs: ${PYTHON_LIBRARIES}")
-       endif()
+if(HAVE_LIBPYTHON)
+       set(HAVE_PYTHON 1)
+       set(PYTHON_DIR "${CMAKE_INSTALL_PREFIX}/lib/wireshark/python/${VERSION}")
 endif()
-
 if(HAVE_LIBLUA)
        set(HAVE_LUA_H 1)
        set(HAVE_LUA_5_1 1)
@@ -219,9 +214,13 @@ if(HAVE_LIBKERBEROS)
        set(HAVE_MIT_KERBEROS 1)
        set(HAVE_KEYTYPE_ARCFOUR_56 1)
 endif()
+if(HAVE_LIBGEOIP)
+       set(HAVE_GEOIP 1)
+endif()
 if(HAVE_LIBCARES)
        set(HAVE_C_ARES 1)
-elseif(HAVE_LIBADNS)
+endif()
+if(HAVE_LIBADNS)
        set(HAVE_GNU_ADNS 1)
 endif()
 if(ENABLE_AIRPCAP)
@@ -591,12 +590,12 @@ if(BUILD_dumpcap)
 #              @INET_NTOP_LO@
                ${GLIB2_LIBRARIES}
                ${PCAP_LIBRARIES}
+               ${CAP_LIBRARIES}
 #              @SOCKET_LIBS@
 #              @NSL_LIBS@
 #              @FRAMEWORKS@
                ${GCRYPT_LIBRARIES}
                ${GNUTLS_LIBRARIES}
-#              @LIBCAP_LIBS@
                ${Z_LIBRARIES}
 
        )
index b8fb94bd2d58cea05937724ef7c78cb7357e9ace..6e728cef580e0c4d0d0902f149f0c6922d62d832 100644 (file)
@@ -1,3 +1,6 @@
+# todo: result for NEED_... is wrong (inverted), at least\r
+#   in the case of getopt\r
+\r
 #check system for includes\r
 include(CheckIncludeFile)\r
 check_include_file("arpa/inet.h"         HAVE_ARPA_INET_H)\r
index b6112edc6fadf6a2a09998029d5dc025fa148b77..a3beabde426d5c9a29df10461d6df7e2a65b5fa5 100644 (file)
@@ -64,7 +64,6 @@ clean source.
 What needs to be done?
 ======================
 
-- Test detection/build with a few remaining packages
 - Add back -Werror flags.
 - Redo glib2 and gtk2 find modules.
 - Add back platform specific objects.
index 04e20d6df1cedbcc01744f4438479d606ef872ca..607b2b16337c328140522db8b59f3d4d1ccb928c 100644 (file)
@@ -11,7 +11,7 @@ IF (CAP_INCLUDE_DIRS)
   SET(CAP_FIND_QUIETLY TRUE)
 ENDIF (CAP_INCLUDE_DIRS)
 
-FIND_PATH(CAP_INCLUDE_DIR cap.h)
+FIND_PATH(CAP_INCLUDE_DIR sys/capability.h)
 
 SET(CAP_NAMES cap)
 FIND_LIBRARY(CAP_LIBRARY NAMES ${CAP_NAMES} )
index 6c046bec146a8403bff5b4efbc1a26d7d1baee02..e821453e0732ab5a6faec796b1f544a7ed99fb2b 100644 (file)
@@ -11,7 +11,7 @@ IF (CARES_INCLUDE_DIRS)
   SET(CARES_FIND_QUIETLY TRUE)
 ENDIF (CARES_INCLUDE_DIRS)
 
-FIND_PATH(CARES_INCLUDE_DIR cares.h)
+FIND_PATH(CARES_INCLUDE_DIR ares.h)
 
 SET(CARES_NAMES cares)
 FIND_LIBRARY(CARES_LIBRARY NAMES ${CARES_NAMES} )
diff --git a/cmake/modules/FindPYTHON.cmake b/cmake/modules/FindPYTHON.cmake
new file mode 100644 (file)
index 0000000..9f12f3c
--- /dev/null
@@ -0,0 +1,196 @@
+# - Find python libraries
+# This module finds if Python is installed and determines where the
+# include files and libraries are. It also determines what the name of
+# the library is. This code sets the following variables:
+#
+#  PYTHON_FOUND     = have the Python libs been found
+#  PYTHON_LIBRARIES     = path to the python library
+#  PYTHON_INCLUDE_DIRS  = path to where Python.h is found
+#
+
+FIND_PROGRAM(CMAKE_PYTHON_CONFIG_EXECUTABLE
+  NAMES
+    python-config
+  DOC
+    "python-config executable"
+  PATHS
+    $ENV{PYTHON}
+    $ENV{PYTHON}/bin
+)
+
+# check wether python-config was found:
+IF(CMAKE_PYTHON_CONFIG_EXECUTABLE)
+  EXEC_PROGRAM(${CMAKE_PYTHON_CONFIG_EXECUTABLE}
+    ARGS
+      --includes
+    OUTPUT_VARIABLE
+      PYTHON_CONFIG_INCLUDE_DIR
+  )
+  EXEC_PROGRAM(${CMAKE_PYTHON_CONFIG_EXECUTABLE}
+    ARGS
+      --libs
+    OUTPUT_VARIABLE
+      PYTHON_CONFIG_LIBRARIES
+  )
+  string(REGEX REPLACE
+    "^ *-I"
+    ""
+    PYTHON_CONFIG_INCLUDE_DIR
+    "${PYTHON_CONFIG_INCLUDE_DIR}"
+  )
+  string(REGEX REPLACE
+    "^ *-l"
+    ""
+    PYTHON_CONFIG_LIBRARIES
+    "${PYTHON_CONFIG_LIBRARIES}"
+  ) 
+  string(REGEX REPLACE
+    " +-I"
+    ";"
+    PYTHON_INCLUDE_DIR
+    "${PYTHON_CONFIG_INCLUDE_DIR}"
+  )
+  string(REGEX REPLACE
+    " +-l"
+    ";"
+    PYTHON_LIBRARY
+    "${PYTHON_CONFIG_LIBRARIES}"
+  ) 
+ELSE(CMAKE_PYTHON_CONFIG_EXECUTABLE)
+  INCLUDE(CMakeFindFrameworks)
+  # Search for the python framework on Apple.
+  CMAKE_FIND_FRAMEWORKS(Python)
+  
+  FOREACH(_CURRENT_VERSION 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
+    STRING(REPLACE "." "" _CURRENT_VERSION_NO_DOTS ${_CURRENT_VERSION})
+
+    FIND_LIBRARY(PYTHON_LIBRARY
+      NAMES python${_CURRENT_VERSION_NO_DOTS} python${_CURRENT_VERSION}
+      PATHS
+        [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
+      PATH_SUFFIXES
+        python${_CURRENT_VERSION}/config
+    )
+  
+    SET(PYTHON_FRAMEWORK_INCLUDES)
+    IF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR)
+      FOREACH(dir ${Python_FRAMEWORKS})
+        SET(PYTHON_FRAMEWORK_INCLUDES ${PYTHON_FRAMEWORK_INCLUDES}
+          ${dir}/Versions/${_CURRENT_VERSION}/include/python${_CURRENT_VERSION})
+      ENDFOREACH(dir)
+    ENDIF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR)
+  
+    FIND_PATH(PYTHON_INCLUDE_DIR
+      NAMES Python.h
+      PATHS
+        ${PYTHON_FRAMEWORK_INCLUDES}
+        [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
+      PATH_SUFFIXES
+        python${_CURRENT_VERSION}
+    )
+    
+  ENDFOREACH(_CURRENT_VERSION)
+ENDIF(CMAKE_PYTHON_CONFIG_EXECUTABLE)
+
+# Python Should be built and installed as a Framework on OSX
+IF(Python_FRAMEWORKS)
+  # If a framework has been selected for the include path,
+  # make sure "-framework" is used to link it.
+  IF("${PYTHON_INCLUDE_DIR}" MATCHES "Python\\.framework")
+    SET(PYTHON_LIBRARY "")
+  ENDIF("${PYTHON_INCLUDE_DIR}" MATCHES "Python\\.framework")
+  IF(NOT PYTHON_LIBRARY)
+    SET (PYTHON_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" FORCE)
+  ENDIF(NOT PYTHON_LIBRARY)
+ENDIF(Python_FRAMEWORKS)
+
+MARK_AS_ADVANCED(
+  PYTHON_LIBRARIES
+  PYTHON_INCLUDE_DIRS
+)
+
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PYTHON DEFAULT_MSG PYTHON_LIBRARY PYTHON_INCLUDE_DIR)
+
+IF(PYTHON_FOUND)
+  SET( PYTHON_LIBRARIES ${PYTHON_LIBRARY} )
+  SET( PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR} )
+ELSE(PYTHON_FOUND)
+  SET( PYTHON_LIBRARIES )
+  SET( PYTHON_INCLUDE_DIRS )
+ENDIF(PYTHON_FOUND)
+
+# PYTHON_ADD_MODULE(<name> src1 src2 ... srcN) is used to build modules for python.
+# PYTHON_WRITE_MODULES_HEADER(<filename>) writes a header file you can include 
+# in your sources to initialize the static python modules
+
+GET_PROPERTY(_TARGET_SUPPORTS_SHARED_LIBS
+  GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
+
+FUNCTION(PYTHON_ADD_MODULE _NAME )
+  OPTION(PYTHON_ENABLE_MODULE_${_NAME} "Add module ${_NAME}" TRUE)
+  OPTION(PYTHON_MODULE_${_NAME}_BUILD_SHARED "Add module ${_NAME} shared" ${_TARGET_SUPPORTS_SHARED_LIBS})
+
+  IF(PYTHON_ENABLE_MODULE_${_NAME})
+    IF(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
+      SET(PY_MODULE_TYPE MODULE)
+    ELSE(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
+      SET(PY_MODULE_TYPE STATIC)
+      SET_PROPERTY(GLOBAL  APPEND  PROPERTY  PY_STATIC_MODULES_LIST ${_NAME})
+    ENDIF(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
+
+    SET_PROPERTY(GLOBAL  APPEND  PROPERTY  PY_MODULES_LIST ${_NAME})
+    ADD_LIBRARY(${_NAME} ${PY_MODULE_TYPE} ${ARGN})
+#    TARGET_LINK_LIBRARIES(${_NAME} ${PYTHON_LIBRARIES})
+
+  ENDIF(PYTHON_ENABLE_MODULE_${_NAME})
+ENDFUNCTION(PYTHON_ADD_MODULE)
+
+FUNCTION(PYTHON_WRITE_MODULES_HEADER _filename)
+
+  GET_PROPERTY(PY_STATIC_MODULES_LIST  GLOBAL  PROPERTY PY_STATIC_MODULES_LIST)
+
+  GET_FILENAME_COMPONENT(_name "${_filename}" NAME)
+  STRING(REPLACE "." "_" _name "${_name}")
+  STRING(TOUPPER ${_name} _name)
+
+  SET(_filenameTmp "${_filename}.in")
+  FILE(WRITE ${_filenameTmp} "/*Created by cmake, do not edit, changes will be lost*/\n")
+  FILE(APPEND ${_filenameTmp} 
+"#ifndef ${_name}
+#define ${_name}
+
+#include <Python.h>
+
+#ifdef __cplusplus
+extern \"C\" {
+#endif /* __cplusplus */
+
+")
+
+  FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
+    FILE(APPEND ${_filenameTmp} "extern void init${PYTHON_MODULE_PREFIX}${_currentModule}(void);\n\n")
+  ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
+
+  FILE(APPEND ${_filenameTmp} 
+"#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+")
+
+
+  FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
+    FILE(APPEND ${_filenameTmp} "int CMakeLoadPythonModule_${_currentModule}(void) \n{\n  static char name[]=\"${PYTHON_MODULE_PREFIX}${_currentModule}\"; return PyImport_AppendInittab(name, init${PYTHON_MODULE_PREFIX}${_currentModule});\n}\n\n")
+  ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
+
+  FILE(APPEND ${_filenameTmp} "#ifndef EXCLUDE_LOAD_ALL_FUNCTION\nvoid CMakeLoadAllPythonModules(void)\n{\n")
+  FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
+    FILE(APPEND ${_filenameTmp} "  CMakeLoadPythonModule_${_currentModule}();\n")
+  ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
+  FILE(APPEND ${_filenameTmp} "}\n#endif\n\n#endif\n")
+  
+# with CONFIGURE_FILE() cmake complains that you may not use a file created using FILE(WRITE) as input file for CONFIGURE_FILE()
+  EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_filenameTmp}" "${_filename}" OUTPUT_QUIET ERROR_QUIET)
+
+ENDFUNCTION(PYTHON_WRITE_MODULES_HEADER)
index 699bd26f949b0cd5e42d733b91e85e8b4ec59c82..98ab89b5593fee8735729c7a2987b2b3fa3797f4 100644 (file)
@@ -1,5 +1,8 @@
 /* cmakeconfig.h.in */
 
+/* Version number of package */
+#define VERSION "@CPACK_PACKAGE_VERSION@"
+
 /* Directory for data */
 #define DATAFILE_DIR "@CMAKE_INSTALL_PREFIX@/share/@CPACK_PACKAGE_NAME@"
 
 /* Define to use SMI SNMP library */
 #cmakedefine HAVE_LIBSMI 1
 
+/* Define to use GEOIP library */
+#cmakedefine HAVE_GEOIP 1
+
+/* Define to use capabilities library */
+#cmakedefine HAVE_LIBCAP 1
+
 /* Define to use GNU ADNS library */
 #cmakedefine HAVE_GNU_ADNS 1
 
 /* Define to 1 if you have the <lua.h> header file. */
 #cmakedefine HAVE_LUA_H 1
 
+/* Define to 1 if you have libpython. */
+#cmakedefine HAVE_PYTHON 1
+
+/* Path to Python. */
+#cmakedefine PYTHON_DIR "${CMAKE_INSTALL_PREFIX}/lib/${CPACK_PACKAGE_NAME}/python/${VERSION}"
+
 /* Define to 1 if you have the <memory.h> header file. */
 #cmakedefine HAVE_MEMORY_H 1
 
 /* Note: not use in the code */
 #cmakedefine STDC_HEADERS 1
 
-/* Version number of package */
-#define VERSION "@CPACK_PACKAGE_VERSION@"
-
 /* Define to 1 if your processor stores words with the most significant byte
    first (like Motorola and SPARC, unlike Intel and VAX). */
 #cmakedefine WORDS_BIGENDIAN 1
index ef7e79359abc4059c5d2dd93ee1d8829f286112d..c56d335b00844e4aac54d40b877a48c3c7397ea2 100644 (file)
@@ -1175,7 +1175,7 @@ add_library(epan SHARED
 
 target_link_libraries(epan
        ${WSLUA_LIB}
-       ${PYTHON_LIB}
+       ${WSPYTHON_LIB}
 )
 
 add_dependencies(epan lemon)