Skip to content

Commit

Permalink
Added pcap as build option
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-jonsson committed Jun 27, 2024
1 parent 77b1175 commit 574f5c3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
4 changes: 2 additions & 2 deletions front/sdl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,8 @@ int main(int argc, char *argv[]) {
front_interface.disk.userdata = &icon_fade;
}

#ifdef VXTU_STATIC_MODULES
printf("Modules are staticlly linked!\n");
#ifndef VXTU_STATIC_MODULES
printf("Modules are dynamically linked!\n");
#endif
printf("Loaded modules:\n");

Expand Down
11 changes: 9 additions & 2 deletions modules/network/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
//
// 3. This notice may not be removed or altered from any source distribution.

#define _DEFAULT_SOURCE 1

#include <vxt/vxtu.h>

#ifdef LIBPACAP

#include <string.h>
#include <stdlib.h>
#include <pcap/pcap.h>
Expand Down Expand Up @@ -221,3 +221,10 @@ VXTU_MODULE_CREATE(network, {
PIREPHERAL->io.in = &in;
PIREPHERAL->io.out = &out;
})

#else

struct network { int _; };
VXTU_MODULE_CREATE(network, { return NULL; })

#endif
28 changes: 17 additions & 11 deletions modules/network/premake5.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
-- Disable this module by default.
module_ignore()
newoption {
trigger = "pcap",
description = "Link with libpcap for network support"
}

files "network.c"

filter "system:windows"
includedirs "../../tools/npcap/sdk/Include"
defines "_WINSOCK_DEPRECATED_NO_WARNINGS"

module_link_callback(function()
filter "not system:windows"
links "pcap"
if _OPTIONS["pcap"] then
defines { "LIBPCAP", "_DEFAULT_SOURCE=1" }

filter "system:windows"
links { "Ws2_32", "../../tools/npcap/sdk/Lib/x64/wpcap" }
end)
includedirs "../../tools/npcap/sdk/Include"
defines "_WINSOCK_DEPRECATED_NO_WARNINGS"

module_link_callback(function()
filter "not system:windows"
links "pcap"

filter "system:windows"
links { "Ws2_32", "../../tools/npcap/sdk/Lib/x64/wpcap" }
end)
end
38 changes: 14 additions & 24 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ newoption {

newoption {
trigger = "test",
description = "Generate make files for libvxt tests"
description = "Generate makefiles for libvxt tests"
}

newoption {
Expand Down Expand Up @@ -99,7 +99,6 @@ workspace "virtualxt"

filter { "toolset:clang or gcc", "configurations:debug" }
buildoptions "-Wno-error"
sanitize { "Address", "Fuzzer" }

local modules = {}
local modules_link_callback = {}
Expand Down Expand Up @@ -133,22 +132,17 @@ workspace "virtualxt"
end
end

for _,name in ipairs(mod_list) do
module_link_callback = function(f)
if _OPTIONS["dynamic"] then
filter {}
f()
filter {}
else
table.insert(modules_link_callback, f)
end
end

module_ignore = function()
module_ignore = nil
module_link_callback = function() end
module_link_callback = function(f)
if _OPTIONS["dynamic"] then
filter {}
f()
filter {}
else
table.insert(modules_link_callback, f)
end

end

for _,name in ipairs(mod_list) do
project(name)
if _OPTIONS["dynamic"] then
kind "SharedLib"
Expand All @@ -174,13 +168,10 @@ workspace "virtualxt"
filter {}

dofile("modules/" .. name .. "/premake5.lua")
if module_ignore then
table.insert(modules, name)
end

module_ignore = nil
module_link_callback = nil
table.insert(modules, name)
end

module_link_callback = nil
end

-- This is just a dummy project.
Expand Down Expand Up @@ -421,7 +412,6 @@ if _OPTIONS["test"] then

optimize "Off"
symbols "On"
sanitize { "Address", "Fuzzer" }

postbuildcommands "./test/test"
cleancommands "{RMDIR} test"
Expand Down

0 comments on commit 574f5c3

Please sign in to comment.