diff --git a/build/premake/premake4.lua b/build/premake/premake4.lua index 852554605f..fd19439f80 100644 --- a/build/premake/premake4.lua +++ b/build/premake/premake4.lua @@ -11,6 +11,7 @@ newoption { trigger = "without-nvtt", description = "Disable use of NVTT" } newoption { trigger = "without-tests", description = "Disable generation of test projects" } newoption { trigger = "without-pch", description = "Disable generation and usage of precompiled headers" } newoption { trigger = "without-lobby", description = "Disable the use of gloox and the multiplayer lobby" } +newoption { trigger = "without-miniupnpc", description = "Disable use of miniupnpc for port forwarding" } newoption { trigger = "with-system-nvtt", description = "Search standard paths for nvidia-texture-tools library, instead of using bundled copy" } newoption { trigger = "with-system-enet", description = "Search standard paths for libenet, instead of using bundled copy" } newoption { trigger = "with-system-miniupnpc", description = "Search standard paths for libminiupnpc, instead of using bundled copy" } @@ -183,6 +184,10 @@ function project_set_build_flags() defines { "CONFIG2_LOBBY=0" } end + if _OPTIONS["without-miniupnpc"] then + defines { "CONFIG2_MINIUPNPC=0" } + end + -- required for the lowlevel library. must be set from all projects that use it, otherwise it assumes it is -- being used as a DLL (which is currently not the case in 0ad) defines { "LIB_STATIC_LINK" } @@ -574,8 +579,10 @@ function setup_all_libs () "spidermonkey", "enet", "boost", -- dragged in via server->simulation.h->random - "miniupnpc" } + if not _OPTIONS["without-miniupnpc"] then + table.insert(extern_libs, "miniupnpc") + end setup_static_lib_project("network", source_dirs, extern_libs, {}) @@ -848,7 +855,6 @@ used_extern_libs = { "libcurl", "valgrind", - "miniupnpc", } if not os.is("windows") and not _OPTIONS["android"] and not os.is("macosx") then @@ -870,6 +876,10 @@ if not _OPTIONS["without-lobby"] then table.insert(used_extern_libs, "gloox") end +if not _OPTIONS["without-miniupnpc"] then + table.insert(used_extern_libs, "miniupnpc") +end + -- Bundles static libs together with main.cpp and builds game executable. function setup_main_exe () diff --git a/source/lib/config2.h b/source/lib/config2.h index 34936fbeea..7dbee5ac73 100644 --- a/source/lib/config2.h +++ b/source/lib/config2.h @@ -116,4 +116,9 @@ # define CONFIG2_LOBBY 1 #endif +// allow use of miniupnpc +#ifndef CONFIG2_MINIUPNPC +# define CONFIG2_MINIUPNPC 1 +#endif + #endif // #ifndef INCLUDED_CONFIG2 diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp index 116480fbc7..e8dba1e15d 100644 --- a/source/network/NetServer.cpp +++ b/source/network/NetServer.cpp @@ -31,11 +31,13 @@ #include "simulation2/Simulation2.h" #include "ps/ConfigDB.h" +#if CONFIG2_MINIUPNPC // Next four files are for UPnP port forwarding. #include #include #include #include +#endif #define DEFAULT_SERVER_NAME L"Unnamed Server" #define DEFAULT_WELCOME_MESSAGE L"Welcome" @@ -189,13 +191,16 @@ bool CNetServerWorker::SetupConnection() int ret = pthread_create(&m_WorkerThread, NULL, &RunThread, this); ENSURE(ret == 0); +#if CONFIG2_MINIUPNPC // Launch the UPnP thread ret = pthread_create(&m_UPnPThread, NULL, &SetupUPnP, NULL); ENSURE(ret == 0); +#endif return true; } +#if CONFIG2_MINIUPNPC void* CNetServerWorker::SetupUPnP(void*) { // Values we want to set. @@ -293,6 +298,7 @@ void* CNetServerWorker::SetupUPnP(void*) return NULL; } +#endif // CONFIG2_MINIUPNPC bool CNetServerWorker::SendMessage(ENetPeer* peer, const CNetMessage* message) { diff --git a/source/network/NetServer.h b/source/network/NetServer.h index c6896fcac5..c0c82ab78a 100644 --- a/source/network/NetServer.h +++ b/source/network/NetServer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -21,6 +21,7 @@ #include "NetFileTransfer.h" #include "NetHost.h" +#include "lib/config2.h" #include "ps/ThreadUtil.h" #include "scriptinterface/ScriptVal.h" @@ -299,11 +300,13 @@ private: private: // Thread-related stuff: +#if CONFIG2_MINIUPNPC /** * Try to find a UPnP root on the network and setup port forwarding. */ static void* SetupUPnP(void*); pthread_t m_UPnPThread; +#endif static void* RunThread(void* data); void Run();