changeset 320:cfa8c1f4c07a

Cleaned FindSCTP.cmake module, added FindGNUTLS
author Sebastien Decugis <sdecugis@nict.go.jp>
date Mon, 02 Mar 2009 14:06:51 +0900
parents 25d722e650d4
children 6b69942ecadb
files cmake/Modules/FindGNUTLS.cmake cmake/Modules/FindSCTP.cmake cmake/Modules/LibFindMacros.cmake extensions/sec_tls_gnutls/CMakeLists.txt waaad/CMakeLists.txt waaad/waaad-host.h.in
diffstat 6 files changed, 180 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/Modules/FindGNUTLS.cmake	Mon Mar 02 14:06:51 2009 +0900
@@ -0,0 +1,29 @@
+# - Try to find GNU TLS library and headers
+# Once done, this will define
+#
+#  GNUTLS_FOUND - system has GNU TLS
+#  GNUTLS_INCLUDE_DIRS - the GNU TLS include directories
+#  GNUTLS_LIBRARIES - link these to use GNU TLS
+
+include(LibFindMacros)
+
+# Use pkg-config to get hints about paths
+libfind_pkg_check_modules(GNUTLS_PKGCONF gnutls)
+
+# Include dir
+find_path(GNUTLS_INCLUDE_DIR
+  NAMES gnutls/gnutls.h
+  PATHS ${GNUTLS_PKGCONF_INCLUDE_DIRS}
+)
+
+# Finally the library itself
+find_library(GNUTLS_LIBRARY
+  NAMES gnutls
+  PATHS ${GNUTLS_PKGCONF_LIBRARY_DIRS}
+)
+
+# Set the include dir variables and the libraries and let libfind_process do the rest.
+# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
+set(GNUTLS_PROCESS_INCLUDES GNUTLS_INCLUDE_DIR)
+set(GNUTLS_PROCESS_LIBS GNUTLS_LIBRARY)
+libfind_process(GNUTLS)
--- a/cmake/Modules/FindSCTP.cmake	Mon Mar 02 12:07:38 2009 +0900
+++ b/cmake/Modules/FindSCTP.cmake	Mon Mar 02 14:06:51 2009 +0900
@@ -1,28 +1,29 @@
-# Will set the required definitions for SCTP:
-#  SCTP_FOUND
-#  SCTP_LIBRARIES
-
-INCLUDE (CheckSymbolExists) 
+# - Try to find SCTP library and headers
+# Once done, this will define
+#
+#  SCTP_FOUND - system has SCTP
+#  SCTP_INCLUDE_DIRS - the SCTP include directories
+#  SCTP_LIBRARIES - link these to use SCTP
 
-SET(SCTP_FOUND FALSE)
+include(LibFindMacros)
 
-# Search compile information
-CHECK_SYMBOL_EXISTS(IPPROTO_SCTP "sys/socket.h;netinet/in.h;netinet/sctp.h" HAVE_IPPROTO_SCTP)
-IF ( NOT HAVE_IPPROTO_SCTP )
-   MESSAGE( SEND_ERROR "Symbol IPPROTO_SCTP was not found in standard headers." )
-ENDIF ( NOT HAVE_IPPROTO_SCTP )
+# Use pkg-config to get hints about paths (Note: not yet supported?)
+# libfind_pkg_check_modules(SCTP_PKGCONF sctp)
 
-# Search link information
-CHECK_FUNCTION_EXISTS (sctp_getladdrs HAVE_SCTP_GETLADDRS)
-IF (HAVE_SCTP_GETLADDRS)
-   SET(SCTP_LIBRARIES "")
-ELSE (HAVE_SCTP_GETLADDRS)
-   CHECK_LIBRARY_EXISTS (sctp sctp_getladdrs "" HAVE_LIBSCTP)
-   IF (HAVE_LIBSCTP)
-     SET(SCTP_LIBRARIES "-lsctp")
-   ELSE (HAVE_LIBSCTP)
-     MESSAGE( SEND_ERROR "Function sctp_getladdrs was not found, please install libsctp." )
-   ENDIF (HAVE_LIBSCTP)
-ENDIF (HAVE_SCTP_GETLADDRS)
+# Include dir
+find_path(SCTP_INCLUDE_DIR
+  NAMES netinet/sctp.h
+  PATHS ${SCTP_PKGCONF_INCLUDE_DIRS}
+)
 
-SET(SCTP_FOUND TRUE)
+# Finally the library itself
+find_library(SCTP_LIBRARY
+  NAMES sctp
+  PATHS ${SCTP_PKGCONF_LIBRARY_DIRS}
+)
+
+# Set the include dir variables and the libraries and let libfind_process do the rest.
+# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
+set(SCTP_PROCESS_INCLUDES SCTP_INCLUDE_DIR)
+set(SCTP_PROCESS_LIBS SCTP_LIBRARY)
+libfind_process(SCTP)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/Modules/LibFindMacros.cmake	Mon Mar 02 14:06:51 2009 +0900
@@ -0,0 +1,99 @@
+# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
+# used for the current package. For this to work, the first parameter must be the
+# prefix of the current package, then the prefix of the new package etc, which are
+# passed to find_package.
+macro (libfind_package PREFIX)
+  set (LIBFIND_PACKAGE_ARGS ${ARGN})
+  if (${PREFIX}_FIND_QUIETLY)
+    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
+  endif (${PREFIX}_FIND_QUIETLY)
+  if (${PREFIX}_FIND_REQUIRED)
+    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
+  endif (${PREFIX}_FIND_REQUIRED)
+  find_package(${LIBFIND_PACKAGE_ARGS})
+endmacro (libfind_package)
+
+# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
+# where they added pkg_check_modules. Consequently I need to support both in my scripts
+# to avoid those deprecated warnings. Here's a helper that does just that.
+# Works identically to pkg_check_modules, except that no checks are needed prior to use.
+macro (libfind_pkg_check_modules PREFIX PKGNAME)
+  if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+    include(UsePkgConfig)
+    pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
+  else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+    find_package(PkgConfig)
+    if (PKG_CONFIG_FOUND)
+      pkg_check_modules(${PREFIX} ${PKGNAME})
+    endif (PKG_CONFIG_FOUND)
+  endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+endmacro (libfind_pkg_check_modules)
+
+# Do the final processing once the paths have been detected.
+# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
+# all the variables, each of which contain one include directory.
+# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
+# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
+# Also handles errors in case library detection was required, etc.
+macro (libfind_process PREFIX)
+  # Skip processing if already processed during this run
+  if (NOT ${PREFIX}_FOUND)
+    # Start with the assumption that the library was found
+    set (${PREFIX}_FOUND TRUE)
+
+    # Process all includes and set _FOUND to false if any are missing
+    foreach (i ${${PREFIX}_PROCESS_INCLUDES})
+      if (${i})
+        set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
+        mark_as_advanced(${i})
+      else (${i})
+        set (${PREFIX}_FOUND FALSE)
+      endif (${i})
+    endforeach (i)
+
+    # Process all libraries and set _FOUND to false if any are missing
+    foreach (i ${${PREFIX}_PROCESS_LIBS})
+      if (${i})
+        set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
+        mark_as_advanced(${i})
+      else (${i})
+        set (${PREFIX}_FOUND FALSE)
+      endif (${i})
+    endforeach (i)
+
+    # Print message and/or exit on fatal error
+    if (${PREFIX}_FOUND)
+      if (NOT ${PREFIX}_FIND_QUIETLY)
+        message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
+      endif (NOT ${PREFIX}_FIND_QUIETLY)
+    else (${PREFIX}_FOUND)
+      if (${PREFIX}_FIND_REQUIRED)
+        foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
+          message("${i}=${${i}}")
+        endforeach (i)
+        message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
+      endif (${PREFIX}_FIND_REQUIRED)
+    endif (${PREFIX}_FOUND)
+  endif (NOT ${PREFIX}_FOUND)
+endmacro (libfind_process)
+
+macro(libfind_library PREFIX basename)
+  set(TMP "")
+  if(MSVC80)
+    set(TMP -vc80)
+  endif(MSVC80)
+  if(MSVC90)
+    set(TMP -vc90)
+  endif(MSVC90)
+  set(${PREFIX}_LIBNAMES ${basename}${TMP})
+  if(${ARGC} GREATER 2)
+    set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
+    string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
+    set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
+  endif(${ARGC} GREATER 2)
+  find_library(${PREFIX}_LIBRARY
+    NAMES ${${PREFIX}_LIBNAMES}
+    PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
+  )
+endmacro(libfind_library)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/sec_tls_gnutls/CMakeLists.txt	Mon Mar 02 14:06:51 2009 +0900
@@ -0,0 +1,24 @@
+# The sec_tls_gnutls extension
+PROJECT("TLS security waaad extension using gnutls" C)
+
+# Parser files
+#BISON_FILE(stgt_conf.y)
+#FLEX_FILE(stgt_conf.l)
+#SET_SOURCE_FILES_PROPERTIES(lex.stgt_conf.c stgt_conf.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}")
+
+# We need to link to GNUTLS library
+FIND_PACKAGE(GNUTLS REQUIRED)
+INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIRS})
+
+# List of source files
+SET( SEC_TLSGNUTLS_SRC
+	sec_tls_gnutls.c
+	sec_tls_gnutls.h
+	gnutls_sctp_wrapper.h
+	gnutls_sctp_wrapper.c
+	todo.c
+)
+
+# Compile these files as a module
+ADD_LIBRARY(sec_tls_gnutls MODULE ${SEC_TLSGNUTLS_SRC})
+TARGET_LINK_LIBRARIES(sec_tls_gnutls ${GNUTLS_LIBRARIES})
--- a/waaad/CMakeLists.txt	Mon Mar 02 12:07:38 2009 +0900
+++ b/waaad/CMakeLists.txt	Mon Mar 02 14:06:51 2009 +0900
@@ -48,7 +48,8 @@
 
 # We need the sctp_getladdrs function ( -lsctp )
 # We need the IPPROTO_SCTP symbol from sys/socket.h, netinet/in.h or netinet/sctp.h
-INCLUDE(FindSCTP)
+FIND_PACKAGE(SCTP REQUIRED)
+INCLUDE_DIRECTORIES(${SCTP_INCLUDE_DIRS})
 SET(WAAAD_LIBS ${WAAAD_LIBS} ${SCTP_LIBRARIES})
 
 
--- a/waaad/waaad-host.h.in	Mon Mar 02 12:07:38 2009 +0900
+++ b/waaad/waaad-host.h.in	Mon Mar 02 14:06:51 2009 +0900
@@ -38,6 +38,7 @@
 #define _WAAAD_HOST_H
 
 #cmakedefine HAVE_NTOHLL
+#cmakedefine HAVE_MALLOC_H
 
 #cmakedefine PROJECT_NAME "@PROJECT_NAME@"
 #cmakedefine CMAKE_PROJECT_NAME "@CMAKE_PROJECT_NAME@"
"Welcome to our mercurial repository"