From df3b4fc503e8683aa84d109ed3f76e77c9fab33b Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 24 Dec 2023 20:27:59 +0100 Subject: [PATCH] feat: auto-detect libnet --- CMakeLists.txt | 19 +++++++++++++------ src/Makefile | 10 ---------- 2 files changed, 13 insertions(+), 16 deletions(-) delete mode 100644 src/Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 95e4b3b..674bc49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.25) # Set the project name and version project(IGMPPacketGenerator VERSION 1.0) @@ -7,11 +7,18 @@ project(IGMPPacketGenerator VERSION 1.0) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED True) -# Find the libnet library -find_package(Libnet REQUIRED) - # Add the executable -add_executable(igmp_packet_generator src/igmpgen.c) +add_executable(igmpgen src/igmpgen.c) + +# Detect the net library +find_library(LIBNET_LIBRARY NAMES net libnet libnet1 REQUIRED) +message(STATUS "libnet detected as ${LIBNET_LIBRARY}") + +# Add the directories where the compiler can find the libnet headers +target_include_directories(igmpgen PRIVATE /usr/include) + +# Add the directories where the compiler can find the libnet libraries +target_link_directories(igmpgen PRIVATE /usr/lib) # Link the executable to the libnet library -target_link_libraries(igmp_packet_generator Libnet::Libnet) +target_link_libraries(igmpgen ${LIBNET_LIBRARY}) diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 73570d5..0000000 --- a/src/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -IGMPPROG=igmpgen -CFLAGS=-Werror -Wall `libnet-config --defines` -D_DEFAULT_SOURCE -LDFLAGS=`libnet-config --libs` - -all: - gcc $(CFLAGS) $(IGMPPROG).c -o $(IGMPPROG) $(LDFLAGS) - -clean: - rm -f $(IGMPPROG) -