Skip to content

Commit

Permalink
Merge pull request #94 from ofalk/devel
Browse files Browse the repository at this point in the history
Prepare new release, including cmake support, updated autotools and a few small fixes
  • Loading branch information
ofalk authored Oct 12, 2023
2 parents 8a0163b + 926b3a3 commit 912f784
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 104 deletions.
118 changes: 108 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14)

project(libdnet VERSION 1.16.4 LANGUAGES C)
project(dnet VERSION 1.17.0 LANGUAGES C)

find_package(TCL)

Expand All @@ -11,8 +11,9 @@ include(CheckStructHasMember)
include(CheckSymbolExists)
include(CheckTypeSize)
include(CheckCSourceCompiles)
include(GNUInstallDirs)

set(WINDOWS_EXPORT_ALL_SYMBOLS True)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS True)
option(BUILD_SHARED_LIBS "Build in shared lib mode" OFF)

foreach (header stdio.h stdlib.h string.h inttypes.h)
Expand Down Expand Up @@ -40,10 +41,10 @@ if(UNIX)
foreach (header strings.h
unistd.h sys/bufmod.h sys/dlpi.h sys/dlpihdr.h sys/dlpi_ext.h
sys/ioctl.h sys/mib.h sys/ndd_var.h sys/socket.h sys/sockio.h
sys/sysctl.h sys/time.h sys/stat.h net/if.h net/if_var.h
net/if_arp.h net/if_dl.h net/pfilt.h
net/pfvar.h net/radix.h net/raw.h net/route.h netinet/in_var.h
net/if_tun.h linux/if_tun.h netinet/ip_fw.h linux/ip_fw.h
sys/time.h sys/stat.h net/if.h net/if_var.h
net/if_dl.h net/pfilt.h
net/radix.h net/raw.h net/route.h netinet/in_var.h
linux/if_tun.h netinet/ip_fw.h linux/ip_fw.h
linux/ip_fwchains.h linux/netfilter_ipv4/ipchains_core.h
ip_fil_compat.h netinet/ip_fil_compat.h ip_compat.h
netinet/ip_compat.h ip_fil.h netinet/ip_fil.h
Expand All @@ -54,6 +55,10 @@ if(UNIX)
endforeach ()

check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
check_include_files("sys/types.h;net/if_arp.h" HAVE_NET_IF_ARP_H)
check_include_files("sys/types.h;net/if_tun.h" HAVE_NET_IF_TUN_H)
check_include_files("sys/types.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
check_include_files("sys/types.h;sys/sysctl.h" HAVE_SYS_SYSCTL_H)
endif()

set(CMAKE_REQUIRED_LIBRARIES )
Expand All @@ -69,7 +74,7 @@ if (UNIX)

CHECK_STRUCT_HAS_MEMBER("struct arpreq" arp_dev net/if_arp.h HAVE_ARPREQ_ARP_DEV LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct sockaddr" sa_len sys/socket.h HAVE_SOCKADDR_SA_LEN LANGUAGE C)
check_symbol_exists(rt_msghdr net/route.h HAVE_ROUTE_RT_MSGHDR)
CHECK_STRUCT_HAS_MEMBER("struct rt_msghdr" rtm_msglen "sys/socket.h;net/if.h;net/route.h" HAVE_ROUTE_RT_MSGHDR LANGUAGE C)

set(CMAKE_EXTRA_INCLUDE_FILES "netinet/in.h")
check_type_size("struct sockaddr_in6" HAVE_SOCKADDR_IN6 LANGUAGE C)
Expand Down Expand Up @@ -272,10 +277,103 @@ else()
list(APPEND PLATFORM_SOURCES src/tun-none.c)
endif()

add_library(${PROJECT_NAME} src/addr-util.c src/addr.c src/blob.c src/ip-util.c src/ip6.c src/rand.c ${PLATFORM_SOURCES})

target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR} )
add_library(${PROJECT_NAME}
src/addr-util.c
src/addr.c
src/blob.c
src/err.c
src/ip-util.c
src/ip6.c
src/rand.c
${PLATFORM_SOURCES})

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/dnet>
)

set(DNET_HEADERS
include/dnet/addr.h
include/dnet/arp.h
include/dnet/blob.h
include/dnet/eth.h
include/dnet/fw.h
include/dnet/icmp.h
include/dnet/intf.h
include/dnet/ip.h
include/dnet/ip6.h
include/dnet/ndisc.h
include/dnet/os.h
include/dnet/rand.h
include/dnet/route.h
include/dnet/sctp.h
include/dnet/tcp.h
include/dnet/tun.h
include/dnet/udp.h
)
set(DNET_HEADERS1
include/dnet.h
include/err.h
include/queue.h
${CMAKE_CURRENT_BINARY_DIR}/config.h
)
set_target_properties(
${PROJECT_NAME}
PROPERTIES
PUBLIC_HEADER "${DNET_HEADERS}"
)

if (MSVC)
target_link_libraries(${PROJECT_NAME} PUBLIC Iphlpapi ws2_32)
endif()

install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${PROJECT_NAME} COMPONENT devel
)


install(FILES ${DNET_HEADERS1}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
COMPONENT devel)

install(EXPORT ${PROJECT_NAME}Targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
COMPONENT devel
)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
@ONLY
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config-version.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
@ONLY
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/
COMPONENT devel
)

if(UNIX)
if(NOT CPACK_GENERATOR)
set(CPACK_GENERATOR "DEB")
endif()

set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_STRIP_FILES 1)
if(${CMAKE_VERSION} VERSION_GREATER "3.5")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
endif()
endif()

include(CPack)
80 changes: 6 additions & 74 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])

# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
# serial 11 (pkg-config-0.29.1)
# serial 12 (pkg-config-0.29.2)

dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
Expand Down Expand Up @@ -63,7 +63,7 @@ dnl
dnl See the "Since" comment for each macro you use to see what version
dnl of the macros you require.
m4_defun([PKG_PREREQ],
[m4_define([PKG_MACROS_VERSION], [0.29.1])
[m4_define([PKG_MACROS_VERSION], [0.29.2])
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
])dnl PKG_PREREQ
Expand Down Expand Up @@ -164,7 +164,7 @@ AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
pkg_failed=no
AC_MSG_CHECKING([for $1])
AC_MSG_CHECKING([for $2])
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
Expand All @@ -174,11 +174,11 @@ and $1[]_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.])
if test $pkg_failed = yes; then
AC_MSG_RESULT([no])
AC_MSG_RESULT([no])
_PKG_SHORT_ERRORS_SUPPORTED
if test $_pkg_short_errors_supported = yes; then
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
else
else
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
Expand All @@ -195,7 +195,7 @@ installed software in a non-standard prefix.
_PKG_TEXT])[]dnl
])
elif test $pkg_failed = untried; then
AC_MSG_RESULT([no])
AC_MSG_RESULT([no])
m4_default([$4], [AC_MSG_FAILURE(
[The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
Expand Down Expand Up @@ -296,74 +296,6 @@ AS_VAR_COPY([$1], [pkg_cv_][$1])
AS_VAR_IF([$1], [""], [$5], [$4])dnl
])dnl PKG_CHECK_VAR

dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
dnl [DESCRIPTION], [DEFAULT])
dnl ------------------------------------------
dnl
dnl Prepare a "--with-" configure option using the lowercase
dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and
dnl PKG_CHECK_MODULES in a single macro.
AC_DEFUN([PKG_WITH_MODULES],
[
m4_pushdef([with_arg], m4_tolower([$1]))
m4_pushdef([description],
[m4_default([$5], [build with ]with_arg[ support])])
m4_pushdef([def_arg], [m4_default([$6], [auto])])
m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])
m4_case(def_arg,
[yes],[m4_pushdef([with_without], [--without-]with_arg)],
[m4_pushdef([with_without],[--with-]with_arg)])
AC_ARG_WITH(with_arg,
AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
[AS_TR_SH([with_]with_arg)=def_arg])
AS_CASE([$AS_TR_SH([with_]with_arg)],
[yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
[auto],[PKG_CHECK_MODULES([$1],[$2],
[m4_n([def_action_if_found]) $3],
[m4_n([def_action_if_not_found]) $4])])
m4_popdef([with_arg])
m4_popdef([description])
m4_popdef([def_arg])
])dnl PKG_WITH_MODULES

dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
dnl [DESCRIPTION], [DEFAULT])
dnl -----------------------------------------------
dnl
dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES
dnl check._[VARIABLE-PREFIX] is exported as make variable.
AC_DEFUN([PKG_HAVE_WITH_MODULES],
[
PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])
AM_CONDITIONAL([HAVE_][$1],
[test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
])dnl PKG_HAVE_WITH_MODULES

dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
dnl [DESCRIPTION], [DEFAULT])
dnl ------------------------------------------------------
dnl
dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make
dnl and preprocessor variable.
AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],
[
PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])
AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
[AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
])dnl PKG_HAVE_DEFINE_WITH_MODULES

# Copyright (C) 2002-2021 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
Expand Down
12 changes: 12 additions & 0 deletions cmake/dnet-config-version.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SET(PACKAGE_VERSION @PROJECT_VERSION@)
IF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
SET(PACKAGE_VERSION_EXACT "true")
ENDIF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
IF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
SET(PACKAGE_VERSION_COMPATIBLE "true")
ELSE (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
SET(PACKAGE_VERSION_UNSUITABLE "true")
ENDIF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
IF (PACKAGE_VERSION_UNSUITABLE)
MESSAGE("VERSION CHECK FAILED FOR ${PACKAGE_FIND_NAME}. WANTED ${PACKAGE_FIND_VERSION}, HAVE ${PACKAGE_VERSION}")
ENDIF(PACKAGE_VERSION_UNSUITABLE)
5 changes: 5 additions & 0 deletions cmake/dnet-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SET(prefix "@CMAKE_INSTALL_PREFIX@")
SET(exec_prefix "@CMAKE_INSTALL_PREFIX@")
SET(dnet_FOUND "TRUE")

include("${CMAKE_CURRENT_LIST_DIR}/dnetTargets.cmake")
3 changes: 0 additions & 3 deletions config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
/* Define if arpreq struct has arp_dev. */
#cmakedefine HAVE_ARPREQ_ARP_DEV

/* Define if you have the Berkeley Packet Filter. */
#cmakedefine HAVE_BSD_BPF

/* Define to 1 if you have the <dlfcn.h> header file. */
#cmakedefine HAVE_DLFCN_H

Expand Down
Loading

0 comments on commit 912f784

Please sign in to comment.