Permalink
Browse files

Build system modified to find libraries and compile depending on avil…

…able libraries. Also added template for netlink driver.
  • Loading branch information...
sh0 committed Sep 13, 2011
1 parent c4f3f1f commit 6ff4cc43a8c66b9eb635a6d4d7c5668941ddcb6b
View
@@ -33,9 +33,12 @@ INCLUDE(airown-helpers)
INCLUDE(airown-libs-general)
INCLUDE(airown-libs-glib)
INCLUDE(airown-libs-openssl)
+INCLUDE(airown-libs-pcap)
INCLUDE(airown-libs-lorcon)
+INCLUDE(airown-libs-netlink)
INCLUDE(airown-libs-libnet)
INCLUDE(airown-libs-ncurses)
+MESSAGE(STATUS "################################################")
# Config files
INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}")
@@ -6,11 +6,11 @@ IF (NOT GLIB_CHECKED)
# Messages
MESSAGE(STATUS "################################################")
- MESSAGE(STATUS "Checking for GLib")
+ MESSAGE(STATUS "Checking for GLIB (glib-2.0, gthread-2.0)")
# Find
PKG_CHECK_MODULES(GLIB glib-2.0 gthread-2.0)
- PRINT_LIBRARY_INFO("GLib" GLIB_FOUND "${GLIB_CFLAGS}" "${GLIB_LDFLAGS}")
+ PRINT_LIBRARY_INFO("GLIB" GLIB_FOUND "${GLIB_CFLAGS}" "${GLIB_LDFLAGS}")
# Set as checked
SET(GLIB_CHECKED 1)
@@ -6,14 +6,21 @@ IF (NOT LIBNET_CHECKED)
# Messages
MESSAGE(STATUS "################################################")
- MESSAGE(STATUS "Checking for libnet")
+ MESSAGE(STATUS "Checking for LIBNET (libnet)")
# Find
- #PKG_CHECK_MODULES(LIBNET libnet)
- SET(LIBNET_FOUND 1)
- SET(LIBNET_CFLAGS "")
- SET(LIBNET_LDFLAGS "-lnet")
- PRINT_LIBRARY_INFO("Libnet" LIBNET_FOUND "${LIBNET_CFLAGS}" "${LIBNET_LDFLAGS}" FATAL_ERROR)
+ FIND_PATH(LIBNET_INCLUDE_DIR NAMES libnet.h PATH_SUFFIXES libnet)
+ FIND_LIBRARY(LIBNET_LIBRARY NAMES net)
+
+ # Result
+ IF (LIBNET_INCLUDE_DIR AND LIBNET_LIBRARY)
+ SET(LIBNET_FOUND 1)
+ ENDIF (LIBNET_INCLUDE_DIR AND LIBNET_LIBRARY)
+
+ # Compiler
+ SET(LIBNET_CFLAGS "-I${LIBNET_INCLUDE_DIR}")
+ SET(LIBNET_LDFLAGS "${LIBNET_LIBRARY}")
+ PRINT_LIBRARY_INFO("LIBNET" LIBNET_FOUND "${LIBNET_CFLAGS}" "${LIBNET_LDFLAGS}" FATAL_ERROR)
# Set as checked
SET(LIBNET_CHECKED 1)
@@ -6,13 +6,20 @@ IF (NOT LORCON_CHECKED)
# Messages
MESSAGE(STATUS "################################################")
- MESSAGE(STATUS "Checking for LORCON")
+ MESSAGE(STATUS "Checking for LORCON (liborcon)")
# Find
- #PKG_CHECK_MODULES(LORCON lorcon)
- SET(LORCON_FOUND 1)
- SET(LORCON_CFLAGS "-I/usr/include/lorcon2")
- SET(LORCON_LDFLAGS "-lorcon2")
+ FIND_PATH(LORCON_INCLUDE_DIR NAMES lorcon.h PATH_SUFFIXES lorcon lorcon2)
+ FIND_LIBRARY(LORCON_LIBRARY NAMES orcon2)
+
+ # Result
+ IF (LORCON_INCLUDE_DIR AND LORCON_LIBRARY)
+ SET(LORCON_FOUND 1)
+ ENDIF (LORCON_INCLUDE_DIR AND LORCON_LIBRARY)
+
+ # Compiler
+ SET(LORCON_CFLAGS "-I${LORCON_INCLUDE_DIR}")
+ SET(LORCON_LDFLAGS "${LORCON_LIBRARY}")
PRINT_LIBRARY_INFO("LORCON" LORCON_FOUND "${LORCON_CFLAGS}" "${LORCON_LDFLAGS}" FATAL_ERROR)
# Set as checked
@@ -6,24 +6,20 @@ IF (NOT NCURSES_CHECKED)
# Messages
MESSAGE(STATUS "################################################")
- MESSAGE(STATUS "Checking for ncurses")
+ MESSAGE(STATUS "Checking for NCURSES (libncurses)")
# Find
- FIND_LIBRARY(CURSES_NCURSES_LIBRARY NAMES ncurses)
-
- GET_FILENAME_COMPONENT(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH)
- GET_FILENAME_COMPONENT(_cursesParentDir "${_cursesLibDir}" PATH)
-
- FIND_FILE(CURSES_HAVE_NCURSES_H ncurses.h)
- FIND_FILE(CURSES_HAVE_NCURSES_NCURSES_H ncurses/ncurses.h)
- FIND_FILE(CURSES_HAVE_NCURSES_CURSES_H ncurses/curses.h)
+ FIND_PATH(NCURSES_INCLUDE_DIR NAMES ncurses.h PATH_SUFFIXES ncurses)
+ FIND_LIBRARY(NCURSES_LIBRARY NAMES ncurses)
- FIND_PATH(CURSES_NCURSES_INCLUDE_PATH ncurses.h ncurses/ncurses.h ncurses/curses.h)
- FIND_PATH(CURSES_NCURSES_INCLUDE_PATH curses.h HINTS "${_cursesParentDir}/include")
+ # Result
+ IF (NCURSES_INCLUDE_DIR AND NCURSES_LIBRARY)
+ SET(NCURSES_FOUND 1)
+ ENDIF (NCURSES_INCLUDE_DIR AND NCURSES_LIBRARY)
- SET(NCURSES_FOUND CURSES_NCURSES_INCLUDE_PATH)
- SET(NCURSES_CFLAGS "-I${CURSES_NCURSES_INCLUDE_PATH}")
- SET(NCURSES_LDFLAGS "${CURSES_NCURSES_LIBRARY}")
+ # Compiler
+ SET(NCURSES_CFLAGS "-I${NCURSES_INCLUDE_DIR}")
+ SET(NCURSES_LDFLAGS "${NCURSES_LIBRARY}")
PRINT_LIBRARY_INFO("NCURSES" NCURSES_FOUND "${NCURSES_CFLAGS}" "${NCURSES_LDFLAGS}" FATAL_ERROR)
# Set as checked
@@ -0,0 +1,19 @@
+################################################################################
+### Netlink ####################################################################
+################################################################################
+
+IF (NOT NETLINK_CHECKED)
+
+ # Messages
+ MESSAGE(STATUS "################################################")
+ MESSAGE(STATUS "Checking for NETLINK (libnl-1)")
+
+ # Find
+ PKG_CHECK_MODULES(NETLINK libnl-1)
+ PRINT_LIBRARY_INFO("NETLINK" NETLINK_FOUND "${NETLINK_CFLAGS}" "${NETLINK_LDFLAGS}")
+
+ # Set as checked
+ SET(NETLINK_CHECKED 1)
+
+ENDIF (NOT NETLINK_CHECKED)
+
@@ -6,7 +6,7 @@ IF (NOT OPENSSL_CHECKED)
# Messages
MESSAGE(STATUS "################################################")
- MESSAGE(STATUS "Checking for OpenSSL")
+ MESSAGE(STATUS "Checking for OPENSSL")
# Find
PKG_CHECK_MODULES(OPENSSL openssl)
@@ -0,0 +1,29 @@
+################################################################################
+### Pcap #######################################################################
+################################################################################
+
+IF (NOT PCAP_CHECKED)
+
+ # Messages
+ MESSAGE(STATUS "################################################")
+ MESSAGE(STATUS "Checking for PCAP (libpcap)")
+
+ # Find
+ FIND_PATH(PCAP_INCLUDE_DIR NAMES pcap.h PATH_SUFFIXES pcap)
+ FIND_LIBRARY(PCAP_LIBRARY NAMES pcap)
+
+ # Result
+ IF (PCAP_INCLUDE_DIR AND PCAP_LIBRARY)
+ SET(PCAP_FOUND 1)
+ ENDIF (PCAP_INCLUDE_DIR AND PCAP_LIBRARY)
+
+ # Compiler
+ SET(PCAP_CFLAGS "-I${PCAP_INCLUDE_DIR}")
+ SET(PCAP_LDFLAGS "${PCAP_LIBRARY}")
+ PRINT_LIBRARY_INFO("PCAP" PCAP_FOUND "${PCAP_CFLAGS}" "${PCAP_LDFLAGS}" FATAL_ERROR)
+
+ # Set as checked
+ SET(PCAP_CHECKED 1)
+
+ENDIF (NOT PCAP_CHECKED)
+
View
@@ -4,11 +4,11 @@
# Includes
SET(AIROWN_CFLAGS_INT "-Wall -O2 -g")
-SET(AIROWN_CFLAGS_EXT "${GLIB_CFLAGS} ${OPENSSL_CFLAGS} ${LORCON_CFLAGS} ${LIBNET_CFLAGS} ${NCURSES_CFLAGS}")
+SET(AIROWN_CFLAGS_EXT "${GLIB_CFLAGS} ${OPENSSL_CFLAGS} ${PCAP_CFLAGS} ${LORCON_CFLAGS} ${NETLINK_CFLAGS} ${LIBNET_CFLAGS} ${NCURSES_CFLAGS}")
# Libraries
SET(AIROWN_LINK_INT "")
-SET(AIROWN_LINK_EXT "${GLIB_LDFLAGS} ${OPENSSL_LDFLAGS} ${LORCON_LDFLAGS} ${LIBNET_LDFLAGS} ${NCURSES_LDFLAGS}")
+SET(AIROWN_LINK_EXT "${GLIB_LDFLAGS} ${OPENSSL_LDFLAGS} ${PCAP_LDFLAGS} ${LORCON_LDFLAGS} ${NETLINK_LDFLAGS} ${LIBNET_LDFLAGS} ${NCURSES_LDFLAGS}")
# Sources
FILE(GLOB AIROWN_SRC ${AIROWN_SRC_DIR}/*.cpp)
View
@@ -24,5 +24,10 @@
// Version
#define AO_VERSION "@VERSION@"
+// Libraries
+#cmakedefine PCAP_FOUND
+#cmakedefine LORCON_FOUND
+#cmakedefine NETLINK_FOUND
+
#endif
View
@@ -69,85 +69,137 @@ bool c_context::init(
// RX driver and mode
if (!g_strcmp0(conf_drv_rx, "pcap")) {
- m_rx_type = DRIVER_PCAP;
- if (!g_strcmp0(conf_mode_rx, "file")) {
- m_rx_mode = PCAP_MODE_FILE;
- } else if (!g_strcmp0(conf_mode_rx, "dev")) {
- m_rx_mode = PCAP_MODE_DEV;
- } else {
- g_critical("[sys] driver pcap does not support rx mode %s, please use either \"file\" or \"dev\"!", conf_mode_rx);
+ #ifdef PCAP_FOUND
+ m_rx_type = DRIVER_PCAP;
+ if (!g_strcmp0(conf_mode_rx, "file")) {
+ m_rx_mode = PCAP_MODE_FILE;
+ } else if (!g_strcmp0(conf_mode_rx, "dev")) {
+ m_rx_mode = PCAP_MODE_DEV;
+ } else {
+ g_critical("[sys] driver pcap does not support rx mode %s, please use either \"file\" or \"dev\"!", conf_mode_rx);
+ goto err_drv_find;
+ }
+ #else
+ g_critical("[sys] pcap driver not enabled in this build, choose another driver or rebuild airown!");
goto err_drv_find;
- }
+ #endif
} else if (!g_strcmp0(conf_drv_rx, "lorcon")) {
- m_rx_type = DRIVER_LORCON;
- if (g_strcmp0(conf_mode_rx, "dev")) {
- g_critical("[sys] driver lorcon does not support rx mode %s, please use \"dev\"!", conf_mode_rx);
+ #ifdef LORCON_FOUND
+ m_rx_type = DRIVER_LORCON;
+ if (g_strcmp0(conf_mode_rx, "dev")) {
+ g_critical("[sys] driver lorcon does not support rx mode %s, please use \"dev\"!", conf_mode_rx);
+ goto err_drv_find;
+ }
+ #else
+ g_critical("[sys] lorcon driver not enabled in this build, choose another driver or rebuild airown!");
goto err_drv_find;
- }
+ #endif
+ } else if (!g_strcmp0(conf_drv_rx, "netlink")) {
+ #ifdef NETLINK_FOUND
+ m_rx_type = DRIVER_NETLINK;
+ if (g_strcmp0(conf_mode_rx, "dev")) {
+ g_critical("[sys] driver netlink does not support rx mode %s, please use \"dev\"!", conf_mode_rx);
+ goto err_drv_find;
+ }
+ #else
+ g_critical("[sys] netlink driver not enabled in this build, choose another driver or rebuild airown!");
+ goto err_drv_find;
+ #endif
}
// TX driver and mode
if (!g_strcmp0(conf_drv_tx, "pcap")) {
- m_tx_type = DRIVER_PCAP;
- if (!g_strcmp0(conf_mode_tx, "file")) {
- m_tx_mode = PCAP_MODE_FILE;
- } else {
- g_critical("[sys] driver pcap does not support tx mode %s, please use \"file\"!", conf_mode_tx);
+ #ifdef PCAP_FOUND
+ m_tx_type = DRIVER_PCAP;
+ if (!g_strcmp0(conf_mode_tx, "file")) {
+ m_tx_mode = PCAP_MODE_FILE;
+ } else {
+ g_critical("[sys] driver pcap does not support tx mode %s, please use \"file\"!", conf_mode_tx);
+ goto err_drv_find;
+ }
+ #else
+ g_critical("[sys] pcap driver not enabled in this build, choose another driver or rebuild airown!");
goto err_drv_find;
- }
+ #endif
} else if (!g_strcmp0(conf_drv_tx, "lorcon")) {
- m_tx_type = DRIVER_LORCON;
- if (g_strcmp0(conf_mode_tx, "dev")) {
- g_critical("[sys] driver lorcon does not support tx mode %s, please use \"dev\"!", conf_mode_tx);
+ #ifdef LORCON_FOUND
+ m_tx_type = DRIVER_LORCON;
+ if (g_strcmp0(conf_mode_tx, "dev")) {
+ g_critical("[sys] driver lorcon does not support tx mode %s, please use \"dev\"!", conf_mode_tx);
+ goto err_drv_find;
+ }
+ #else
+ g_critical("[sys] lorcon driver not enabled in this build, choose another driver or rebuild airown!");
goto err_drv_find;
- }
+ #endif
+ } else if (!g_strcmp0(conf_drv_tx, "netlink")) {
+ #ifdef NETLINK_FOUND
+ m_tx_type = DRIVER_NETLINK;
+ if (g_strcmp0(conf_mode_tx, "dev")) {
+ g_critical("[sys] driver netlink does not support tx mode %s, please use \"dev\"!", conf_mode_tx);
+ goto err_drv_find;
+ }
+ #else
+ g_critical("[sys] netlink driver not enabled in this build, choose another driver or rebuild airown!");
+ goto err_drv_find;
+ #endif
}
// Check drivers
if (m_rx_type == DRIVER_NONE && m_tx_type == DRIVER_NONE) {
- g_critical("[sys] unable to find capture driver %s! please use either pcap or lorcon!", conf_drv_rx);
+ g_critical("[sys] no specified rx or tx drivers found! rx_drv=%s, tx_drv=%s", conf_drv_rx, conf_drv_tx);
goto err_drv_find;
}
// Pcap
- if (m_rx_type == DRIVER_PCAP || m_tx_type == DRIVER_PCAP) {
- if (m_rx_type == DRIVER_PCAP && m_tx_type == DRIVER_PCAP) {
- m_tx_drv = m_rx_drv = new c_drv_pcap(conf_dev_rx, m_rx_mode, conf_dev_tx, m_tx_mode);
- if (!m_rx_drv->init())
- goto err_drv_init;
- } else if (m_rx_type == DRIVER_PCAP) {
- m_rx_drv = new c_drv_pcap(conf_dev_rx, m_rx_mode, conf_dev_tx, m_tx_mode);
- if (!m_rx_drv->init())
- goto err_drv_init;
- } else if (m_tx_type == DRIVER_PCAP) {
- m_tx_drv = new c_drv_pcap(conf_dev_rx, m_rx_mode, conf_dev_tx, m_tx_mode);
- if (!m_tx_drv->init())
- goto err_drv_init;
+ #ifdef PCAP_FOUND
+ if (m_rx_type == DRIVER_PCAP || m_tx_type == DRIVER_PCAP) {
+ if (m_rx_type == DRIVER_PCAP && m_tx_type == DRIVER_PCAP) {
+ m_tx_drv = m_rx_drv = new c_drv_pcap(conf_dev_rx, m_rx_mode, conf_dev_tx, m_tx_mode);
+ if (!m_rx_drv->init())
+ goto err_drv_init;
+ } else if (m_rx_type == DRIVER_PCAP) {
+ m_rx_drv = new c_drv_pcap(conf_dev_rx, m_rx_mode, conf_dev_tx, m_tx_mode);
+ if (!m_rx_drv->init())
+ goto err_drv_init;
+ } else if (m_tx_type == DRIVER_PCAP) {
+ m_tx_drv = new c_drv_pcap(conf_dev_rx, m_rx_mode, conf_dev_tx, m_tx_mode);
+ if (!m_tx_drv->init())
+ goto err_drv_init;
+ }
}
- }
+ #endif
- if (m_rx_type == DRIVER_LORCON || m_tx_type == DRIVER_LORCON) {
- if (m_rx_type == DRIVER_LORCON && m_tx_type == DRIVER_LORCON && !g_strcmp0(conf_dev_rx, conf_dev_tx)) {
- m_tx_drv = m_rx_drv = new c_drv_lorcon(conf_dev_rx, NULL, 0);
- if (!m_rx_drv->init())
- goto err_drv_init;
- } else if (m_rx_type == DRIVER_LORCON && m_tx_type == DRIVER_LORCON) {
- m_rx_drv = new c_drv_lorcon(conf_dev_rx, NULL, 0);
- if (!m_rx_drv->init())
- goto err_drv_init;
- m_tx_drv = new c_drv_lorcon(conf_dev_tx, NULL, 0);
- if (!m_tx_drv->init())
- goto err_drv_init;
- } else if (m_rx_type == DRIVER_LORCON) {
- m_rx_drv = new c_drv_lorcon(conf_dev_rx, NULL, 0);
- if (!m_rx_drv->init())
- goto err_drv_init;
- } else if (m_tx_type == DRIVER_LORCON) {
- m_tx_drv = new c_drv_lorcon(conf_dev_tx, NULL, 0);
- if (!m_tx_drv->init())
- goto err_drv_init;
+ // Lorcon
+ #ifdef LORCON_FOUND
+ if (m_rx_type == DRIVER_LORCON || m_tx_type == DRIVER_LORCON) {
+ if (m_rx_type == DRIVER_LORCON && m_tx_type == DRIVER_LORCON && !g_strcmp0(conf_dev_rx, conf_dev_tx)) {
+ m_tx_drv = m_rx_drv = new c_drv_lorcon(conf_dev_rx, NULL, 0);
+ if (!m_rx_drv->init())
+ goto err_drv_init;
+ } else if (m_rx_type == DRIVER_LORCON && m_tx_type == DRIVER_LORCON) {
+ m_rx_drv = new c_drv_lorcon(conf_dev_rx, NULL, 0);
+ if (!m_rx_drv->init())
+ goto err_drv_init;
+ m_tx_drv = new c_drv_lorcon(conf_dev_tx, NULL, 0);
+ if (!m_tx_drv->init())
+ goto err_drv_init;
+ } else if (m_rx_type == DRIVER_LORCON) {
+ m_rx_drv = new c_drv_lorcon(conf_dev_rx, NULL, 0);
+ if (!m_rx_drv->init())
+ goto err_drv_init;
+ } else if (m_tx_type == DRIVER_LORCON) {
+ m_tx_drv = new c_drv_lorcon(conf_dev_tx, NULL, 0);
+ if (!m_tx_drv->init())
+ goto err_drv_init;
+ }
}
- }
+ #endif
+
+ // Netlink
+ #ifdef NETLINK_FOUND
+
+ #endif
/*
// Libnet
Oops, something went wrong.

0 comments on commit 6ff4cc4

Please sign in to comment.