From 5eff3391c316d5ab325b78024296e74127c6747c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sun, 21 Apr 2013 16:45:37 +0200
Subject: Fix compilation when 3rdParty/ is not there.

Change-Id: I6d86bf7d8dcc750ff69ff08500c9987b3c1de43e

diff --git a/3rdParty/LibMiniUPnPc/SConscript b/3rdParty/LibMiniUPnPc/SConscript
index 0cf0be7..505060f 100644
--- a/3rdParty/LibMiniUPnPc/SConscript
+++ b/3rdParty/LibMiniUPnPc/SConscript
@@ -7,6 +7,7 @@ if env.get("LIBMINIUPNPC_BUNDLED", False) :
 ################################################################################
 
 	if env["SCONS_STAGE"] == "flags" :
+		env["HAVE_LIBMINIUPNPC"] = True
 		env["LIBMINIUPNPC_FLAGS"] = {
 				"CPPPATH": [Dir("src/miniupnpc")],
 				"LIBPATH": [Dir(".")],
diff --git a/3rdParty/LibNATPMP/SConscript b/3rdParty/LibNATPMP/SConscript
index 7adaa51..5d08698 100644
--- a/3rdParty/LibNATPMP/SConscript
+++ b/3rdParty/LibNATPMP/SConscript
@@ -7,6 +7,7 @@ if env.get("LIBNATPMP_BUNDLED", False) :
 ################################################################################
 
 	if env["SCONS_STAGE"] == "flags" :
+		env["HAVE_LIBNATPMP"] = True
 		env["LIBNATPMP_FLAGS"] = {
 				"CPPPATH": [Dir("src/libnatpmp")],
 				"LIBPATH": [Dir(".")],
diff --git a/3rdParty/Lua/SConscript b/3rdParty/Lua/SConscript
index 0c1d075..acb2fba 100644
--- a/3rdParty/Lua/SConscript
+++ b/3rdParty/Lua/SConscript
@@ -7,6 +7,7 @@ if env.get("LUA_BUNDLED", False) :
 ################################################################################
 
 	if env["SCONS_STAGE"] == "flags" :
+		env["HAVE_LUA"] = True
 		cppdefines = []
 		if not env["optimize"] :
 			cppdefines.append("LUA_USE_APICHECK")
diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct
index d5faaf4..ada291e 100644
--- a/BuildTools/SCons/SConstruct
+++ b/BuildTools/SCons/SConstruct
@@ -349,7 +349,6 @@ if env["experimental"] :
 		env["LIBMINIUPNPC_FLAGS"] = { "LIBS": ["miniupnpc"] }
 		env["LIBMINIUPNPC_FLAGS"].update(libminiupnpc_flags)
 	else :
-		env["HAVE_LIBMINIUPNPC"] = 1
 		env["LIBMINIUPNPC_BUNDLED"] = 1
 	conf.Finish()
 else :
@@ -371,7 +370,6 @@ if env["experimental"] :
 		env["LIBNATPMP_FLAGS"] = { "LIBS": ["natpmp"] }
 		env["LIBNATPMP_FLAGS"].update(libnatpmp_flags)
 	else :
-		env["HAVE_LIBNATPMP"] = 1
 		env["LIBNATPMP_BUNDLED"] = 1
 	conf.Finish()
 else :
@@ -563,13 +561,14 @@ else :
 
 # Modules
 modules = []
-for dir in os.listdir(Dir("#/3rdParty").abspath) :
-	full_dir = os.path.join(Dir("#/3rdParty").abspath, dir)
-	if not os.path.isdir(full_dir) :
-		continue
-	sconscript = os.path.join(full_dir, "SConscript")
-	if os.path.isfile(sconscript) :
-		modules.append("3rdParty/" + dir)
+if os.path.isdir(Dir("#/3rdParty").abspath) :
+	for dir in os.listdir(Dir("#/3rdParty").abspath) :
+		full_dir = os.path.join(Dir("#/3rdParty").abspath, dir)
+		if not os.path.isdir(full_dir) :
+			continue
+		sconscript = os.path.join(full_dir, "SConscript")
+		if os.path.isfile(sconscript) :
+			modules.append("3rdParty/" + dir)
 for dir in os.listdir(Dir("#").abspath) :
 	full_dir = os.path.join(Dir("#").abspath, dir)
 	if not os.path.isdir(full_dir) :
diff --git a/Sluift/SConscript b/Sluift/SConscript
index f6388a0..2c247d8 100644
--- a/Sluift/SConscript
+++ b/Sluift/SConscript
@@ -2,7 +2,12 @@ import Version, os.path
 
 Import(["env", "conf_env"])
 
-if env["SCONS_STAGE"] == "build" :
+if env["SCONS_STAGE"] == "build" and not GetOption("help") and not env.get("HAVE_LUA", 0) :
+	print "Warning: Lua was not found. Sluift will not be built."
+	if "Sluift" in env["PROJECTS"] :
+		env["PROJECTS"].remove("Sluift")
+		
+elif env["SCONS_STAGE"] == "build" :
 	lib_env = env.Clone()
 	lib_env.UseFlags(env["LUA_FLAGS"])
 	lib_env.UseFlags(env["SWIFTEN_FLAGS"])
diff --git a/SwifTools/SConscript b/SwifTools/SConscript
index d91c5d4..9aa3bed 100644
--- a/SwifTools/SConscript
+++ b/SwifTools/SConscript
@@ -61,8 +61,8 @@ if env["SCONS_STAGE"] == "build" :
 		swiftools_env.Append(CPPDEFINES = ["HAVE_XSS"])
 		sources += ["Idle/XSSIdleQuerier.cpp"]
 
-	swiftools_env.UseFlags(swiftools_env["BREAKPAD_FLAGS"])
-	if env["HAVE_BREAKPAD"] :
+	if env.get("HAVE_BREAKPAD", False) :
+		swiftools_env.UseFlags(swiftools_env["BREAKPAD_FLAGS"])
 		swiftools_env.Append(CPPDEFINES = ["HAVE_BREAKPAD"])
 	sources += ["CrashReporter.cpp"]
 	
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index 53db2df..d71375d 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -36,7 +36,8 @@ if myenv["HAVE_SPARKLE"] :
   myenv.UseFlags(env["SPARKLE_FLAGS"])
 myenv.UseFlags(env["SWIFTEN_FLAGS"])
 myenv.UseFlags(env["SWIFTEN_DEP_FLAGS"])
-myenv.UseFlags(env["BREAKPAD_FLAGS"])
+if myenv.get("HAVE_BREAKPAD") :
+  myenv.UseFlags(env["BREAKPAD_FLAGS"])
 if myenv.get("HAVE_GROWL", False) :
 	myenv.UseFlags(myenv["GROWL_FLAGS"])
 	myenv.Append(CPPDEFINES = ["HAVE_GROWL"])
diff --git a/Swiften/Network/PlatformNATTraversalWorker.cpp b/Swiften/Network/PlatformNATTraversalWorker.cpp
index 40d6da6..133b006 100644
--- a/Swiften/Network/PlatformNATTraversalWorker.cpp
+++ b/Swiften/Network/PlatformNATTraversalWorker.cpp
@@ -14,8 +14,12 @@
 #include <Swiften/Network/NATTraversalGetPublicIPRequest.h>
 #include <Swiften/Network/NATTraversalForwardPortRequest.h>
 #include <Swiften/Network/NATTraversalRemovePortForwardingRequest.h>
+#ifdef HAVE_LIBNATPMP
 #include <Swiften/Network/NATPMPInterface.h>
+#endif
+#ifdef HAVE_LIBMINIUPNPC
 #include <Swiften/Network/MiniUPnPInterface.h>
+#endif
 
 namespace Swift {
 
@@ -117,12 +121,17 @@ PlatformNATTraversalWorker::~PlatformNATTraversalWorker() {
 	addRequestToQueue(boost::shared_ptr<PlatformNATTraversalRequest>());
 	thread->join();
 	delete thread;
+#ifdef HAVE_LIBNATPMP
 	delete natPMPInterface;
+#endif
+#ifdef HAVE_LIBMINIUPNPC
 	delete miniUPnPInterface;
+#endif
 	delete nullNATTraversalInterface;
 }
 
 NATTraversalInterface* PlatformNATTraversalWorker::getNATTraversalInterface() const {
+#ifdef HAVE_LIBMINIUPNPC
 	if (boost::logic::indeterminate(miniUPnPSupported)) {
 		miniUPnPInterface = new MiniUPnPInterface();
 		miniUPnPSupported = miniUPnPInterface->isAvailable();
@@ -130,8 +139,9 @@ NATTraversalInterface* PlatformNATTraversalWorker::getNATTraversalInterface() co
 	if (miniUPnPSupported) {
 		return miniUPnPInterface;
 	}
+#endif
 
-
+#ifdef HAVE_LIBNATPMP
 	if (boost::logic::indeterminate(natPMPSupported)) {
 		natPMPInterface = new NATPMPInterface();
 		natPMPSupported = natPMPInterface->isAvailable();
@@ -139,6 +149,7 @@ NATTraversalInterface* PlatformNATTraversalWorker::getNATTraversalInterface() co
 	if (natPMPSupported) {
 		return natPMPInterface;
 	}
+#endif
 
 	return nullNATTraversalInterface;
 }
diff --git a/Swiften/Network/SConscript b/Swiften/Network/SConscript
index b742bfe..e0e5e63 100644
--- a/Swiften/Network/SConscript
+++ b/Swiften/Network/SConscript
@@ -72,20 +72,24 @@ else :
 
 objects = myenv.SwiftenObject(sourceList)
 
-if myenv["experimental"] :
+if myenv["experimental"] :	
 	# LibNATPMP classes
-	natpmp_env = myenv.Clone()
-	natpmp_env.Append(CPPDEFINES = natpmp_env["LIBNATPMP_FLAGS"].get("INTERNAL_CPPDEFINES", []))
-	objects += natpmp_env.SwiftenObject([
-				"NATPMPInterface.cpp",
-			])
+	if myenv.get("HAVE_LIBNATPMP", False) :
+		natpmp_env = myenv.Clone()	
+		natpmp_env.Append(CPPDEFINES = natpmp_env["LIBNATPMP_FLAGS"].get("INTERNAL_CPPDEFINES", []))
+		myenv.Append(CPPDEFINES = ["HAVE_LIBNATPMP"])
+		objects += natpmp_env.SwiftenObject([
+					"NATPMPInterface.cpp",
+				])
 
 	# LibMINIUPnP classes
-	upnp_env = myenv.Clone()
-	upnp_env.Append(CPPDEFINES = upnp_env["LIBMINIUPNPC_FLAGS"].get("INTERNAL_CPPDEFINES", []))
-	objects += upnp_env.SwiftenObject([
-				"MiniUPnPInterface.cpp",
-			])
+	if myenv.get("HAVE_LIBMINIUPNPC", False) :
+		upnp_env = myenv.Clone()
+		upnp_env.Append(CPPDEFINES = upnp_env["LIBMINIUPNPC_FLAGS"].get("INTERNAL_CPPDEFINES", []))
+		myenv.Append(CPPDEFINES = ["HAVE_LIBMINIUPNPC"])
+		objects += upnp_env.SwiftenObject([
+					"MiniUPnPInterface.cpp",
+				])
 	objects += myenv.SwiftenObject([
 				"PlatformNATTraversalWorker.cpp",
 			])
diff --git a/Swiftob/SConscript b/Swiftob/SConscript
index 4f6464a..424ae72 100644
--- a/Swiftob/SConscript
+++ b/Swiftob/SConscript
@@ -1,7 +1,11 @@
 Import("env")
 
+if env["SCONS_STAGE"] == "build" and not GetOption("help") and not env.get("HAVE_LUA", 0) :
+	print "Warning: Lua was not found. Swiftob will not be built."
+	if "Sluift" in env["PROJECTS"] :
+		env["PROJECTS"].remove("Sluift")
 
-if env["SCONS_STAGE"] == "build":
+elif env["SCONS_STAGE"] == "build":
 	myenv = env.Clone()
 	# Too many compile warnings here at the moment
 	myenv.Replace(CXXFLAGS = [flag for flag in env["CXXFLAGS"] if flag != "-Weverything"])
-- 
cgit v0.10.2-6-g49f6