From e2385da3debfdd372630fa36f70e2440f9c13ac4 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Thu, 2 Oct 2014 12:34:50 +0100
Subject: Allow scons to not require an IDN library

This will clearly break all the tests, Swift, Sluift etc., but is useful
if someone wants to use Swiften and inject their own IDN provider.

Test-information:

Compiles with Isode's IDN provider

Change-Id: Ia55991054f42f332bf34b653d7b55f64f654820e

diff --git a/BuildTools/SCons/SConscript.boot b/BuildTools/SCons/SConscript.boot
index 51be9ab..0a4eb33 100644
--- a/BuildTools/SCons/SConscript.boot
+++ b/BuildTools/SCons/SConscript.boot
@@ -66,6 +66,7 @@ vars.Add(BoolVariable("try_libidn", "Try configuring for LibIDN?", "true"))
 vars.Add(PathVariable("libidn_includedir", "LibIDN headers location", None, PathVariable.PathAccept))
 vars.Add(PathVariable("libidn_libdir", "LibIDN library location", None, PathVariable.PathAccept))
 vars.Add("libidn_libname", "LibIDN library name",  os.name == "nt" and "libidn" or "idn")
+vars.Add(BoolVariable("need_idn", "Whether an IDN library is required. Without this, most internal binaries will fail", "true"))
 vars.Add(PathVariable("libminiupnpc_includedir", "LibMiniUPNPC headers location", None, PathVariable.PathAccept))
 vars.Add(PathVariable("libminiupnpc_libdir", "LibMiniUPNPC library location", None, PathVariable.PathAccept))
 vars.Add("libminiupnpc_libname", "LibMiniUPNPC library name", "libminiupnpc" if os.name == "nt" else "miniupnpc")
diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct
index 7bda9c1..5db30f8 100644
--- a/BuildTools/SCons/SConstruct
+++ b/BuildTools/SCons/SConstruct
@@ -328,6 +328,8 @@ if not env.get("HAVE_EXPAT", 0) and not env.get("HAVE_LIBXML", 0) :
 # IDN library
 ################################################################################
 
+env["NEED_IDN"] = env.get("need_idn", True)
+
 # ICU
 icu_env = conf_env.Clone()
 use_icu = bool(env["icu"])
@@ -367,9 +369,11 @@ if not env.get("HAVE_ICU", False) and not env.get("HAVE_LIBIDN", False) :
 	if env.get("libidn_bundled_enable", True)  :
 		env["HAVE_LIBIDN"] = 1
 		env["LIBIDN_BUNDLED"] = 1
-	else :
+	elif env.get("need_idn", True):
 		print "Error: ICU and LIBIDN not found, and libidn_bundled_enable is false"
 		Exit(1)
+	else:
+		print "Proceeding without an IDN library because need_idn was false. This will break all internal binaries"
 
 # Unbound
 if env["unbound"] :
diff --git a/Swiften/IDN/PlatformIDNConverter.cpp b/Swiften/IDN/PlatformIDNConverter.cpp
index 6d9cff7..4882b60 100644
--- a/Swiften/IDN/PlatformIDNConverter.cpp
+++ b/Swiften/IDN/PlatformIDNConverter.cpp
@@ -19,7 +19,9 @@ IDNConverter* PlatformIDNConverter::create() {
 #elif defined(HAVE_ICU)
 	return new ICUConverter();
 #else
+#if defined(NEED_IDN)
 #error "No IDN implementation"
+#endif
 	return 0;
 #endif
 }
diff --git a/Swiften/IDN/SConscript b/Swiften/IDN/SConscript
index 9d3b8f9..4c1a71d 100644
--- a/Swiften/IDN/SConscript
+++ b/Swiften/IDN/SConscript
@@ -4,6 +4,8 @@ Import("swiften_env", "env")
 objects = swiften_env.SwiftenObject(["IDNConverter.cpp"])
 
 myenv = swiften_env.Clone()
+if myenv.get("NEED_IDN"):
+	myenv.Append(CPPDEFINES = ["NEED_IDN"])
 if myenv.get("HAVE_ICU") :
 	myenv.MergeFlags(swiften_env["ICU_FLAGS"])
 	myenv.Append(CPPDEFINES = ["HAVE_ICU"])
-- 
cgit v0.10.2-6-g49f6