From 9b55c094105cc2746dc5e4929d3b7c2cd0956a37 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Wed, 16 Mar 2011 19:46:51 +0100
Subject: Added possibility to dynamically link Swiften.

Resolves: #798

diff --git a/Swiften/Avatars/SConscript b/Swiften/Avatars/SConscript
index acf2592..46ae897 100644
--- a/Swiften/Avatars/SConscript
+++ b/Swiften/Avatars/SConscript
@@ -1,6 +1,6 @@
 Import("swiften_env")
 
-objects = swiften_env.StaticObject([
+objects = swiften_env.SwiftenObject([
 			"AvatarFileStorage.cpp",
 			"VCardUpdateAvatarManager.cpp",
 			"VCardAvatarManager.cpp",
diff --git a/Swiften/Base/SConscript b/Swiften/Base/SConscript
index ca22044..01252e5 100644
--- a/Swiften/Base/SConscript
+++ b/Swiften/Base/SConscript
@@ -1,6 +1,6 @@
 Import("swiften_env")
 
-objects = swiften_env.StaticObject([
+objects = swiften_env.SwiftenObject([
 			"ByteArray.cpp",
 			"Error.cpp",
 			"Log.cpp",
diff --git a/Swiften/Component/SConscript b/Swiften/Component/SConscript
index 0ca5a02..0a9f250 100644
--- a/Swiften/Component/SConscript
+++ b/Swiften/Component/SConscript
@@ -9,4 +9,4 @@ sources = [
 		"Component.cpp",
 	]
 
-swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.StaticObject(sources))
+swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.SwiftenObject(sources))
diff --git a/Swiften/Disco/SConscript b/Swiften/Disco/SConscript
index ef2bd1b..9982192 100644
--- a/Swiften/Disco/SConscript
+++ b/Swiften/Disco/SConscript
@@ -1,6 +1,6 @@
 Import("swiften_env")
 
-objects = swiften_env.StaticObject([
+objects = swiften_env.SwiftenObject([
 			"CapsInfoGenerator.cpp",
 			"CapsManager.cpp",
 			"EntityCapsManager.cpp",
diff --git a/Swiften/Entity/SConscript b/Swiften/Entity/SConscript
index 78a298c..1342ec1 100644
--- a/Swiften/Entity/SConscript
+++ b/Swiften/Entity/SConscript
@@ -1,6 +1,6 @@
 Import("swiften_env")
 
-objects = swiften_env.StaticObject([
+objects = swiften_env.SwiftenObject([
 			"Entity.cpp",
 		])
 swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/EventLoop/SConscript b/Swiften/EventLoop/SConscript
index 31ad9a8..21ae8b9 100644
--- a/Swiften/EventLoop/SConscript
+++ b/Swiften/EventLoop/SConscript
@@ -7,13 +7,13 @@ sources = [
 		"SimpleEventLoop.cpp",
 	]
 
-objects = swiften_env.StaticObject(sources)
+objects = swiften_env.SwiftenObject(sources)
 swiften_env.Append(SWIFTEN_OBJECTS = [objects])
 
 if swiften_env["PLATFORM"] == "darwin" :
 	myenv = swiften_env.Clone()
 	myenv.Append(CXXFLAGS = myenv["OBJCCFLAGS"])
-	objects = myenv.StaticObject([
+	objects = myenv.SwiftenObject([
 			"Cocoa/CocoaEventLoop.mm",
 			"Cocoa/CocoaEvent.mm"
 		])
diff --git a/Swiften/FileTransfer/SConscript b/Swiften/FileTransfer/SConscript
index 9f3234f..ea9e7bb 100644
--- a/Swiften/FileTransfer/SConscript
+++ b/Swiften/FileTransfer/SConscript
@@ -16,4 +16,4 @@ sources = [
 		"IBBReceiveSession.cpp",
 	]
 
-swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.StaticObject(sources))
+swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.SwiftenObject(sources))
diff --git a/Swiften/History/SConscript b/Swiften/History/SConscript
index c197653..9c2a9d6 100644
--- a/Swiften/History/SConscript
+++ b/Swiften/History/SConscript
@@ -4,7 +4,7 @@ Import("swiften_env")
 #if myenv["target"] == "native":
 #   myenv.MergeFlags(swiften_env.get("SQLITE_FLAGS", {}))
 #
-#objects = myenv.StaticObject([
+#objects = myenv.SwiftenObject([
 #			"HistoryManager.cpp",
 #			"SQLiteHistoryManager.cpp",
 #		])
diff --git a/Swiften/IDN/SConscript b/Swiften/IDN/SConscript
index bfdb42c..7382578 100644
--- a/Swiften/IDN/SConscript
+++ b/Swiften/IDN/SConscript
@@ -3,7 +3,7 @@ Import("swiften_env")
 myenv = swiften_env.Clone()
 myenv.MergeFlags(swiften_env["LIBIDN_FLAGS"])
 
-objects = myenv.StaticObject([
+objects = myenv.SwiftenObject([
 			"StringPrep.cpp",
 			"IDNA.cpp",
 		])
diff --git a/Swiften/JID/SConscript b/Swiften/JID/SConscript
index d48fbb0..d347cd9 100644
--- a/Swiften/JID/SConscript
+++ b/Swiften/JID/SConscript
@@ -3,7 +3,7 @@ Import("swiften_env")
 myenv = swiften_env.Clone()
 myenv.MergeFlags(swiften_env["LIBIDN_FLAGS"])
 
-objects = myenv.StaticObject([
+objects = myenv.SwiftenObject([
 			"JID.cpp",
 		])
 swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/Jingle/SConscript b/Swiften/Jingle/SConscript
index c1aadea..a8890b7 100644
--- a/Swiften/Jingle/SConscript
+++ b/Swiften/Jingle/SConscript
@@ -8,4 +8,4 @@ sources = [
 		"JingleSession.cpp",
 	]
 
-swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.StaticObject(sources))
+swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.SwiftenObject(sources))
diff --git a/Swiften/LinkLocal/SConscript b/Swiften/LinkLocal/SConscript
index 3d4d737..6edf993 100644
--- a/Swiften/LinkLocal/SConscript
+++ b/Swiften/LinkLocal/SConscript
@@ -34,5 +34,5 @@ elif myenv.get("HAVE_AVAHI", 0) :
 			"DNSSD/Avahi/AvahiQuery.cpp"
 		]
 
-objects = myenv.StaticObject(sources)
+objects = myenv.SwiftenObject(sources)
 swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/Network/SConscript b/Swiften/Network/SConscript
index 2e376af..fa186fa 100644
--- a/Swiften/Network/SConscript
+++ b/Swiften/Network/SConscript
@@ -32,5 +32,5 @@ if myenv.get("HAVE_CARES", False) :
    sourceList.append("CAresDomainNameResolver.cpp")
 		
 
-objects = myenv.StaticObject(sourceList)
+objects = myenv.SwiftenObject(sourceList)
 swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 90b3b78..cbb2190 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -71,5 +71,5 @@ if myenv.get("HAVE_LIBXML", 0) :
 	myenv.Append(CPPDEFINES = "HAVE_LIBXML")
 	sources += ["LibXMLParser.cpp"]
 
-objects = myenv.StaticObject(sources)
+objects = myenv.SwiftenObject(sources)
 swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/Presence/SConscript b/Swiften/Presence/SConscript
index 6911d45..33acbd3 100644
--- a/Swiften/Presence/SConscript
+++ b/Swiften/Presence/SConscript
@@ -1,6 +1,6 @@
 Import("swiften_env")
 
-objects = swiften_env.StaticObject([
+objects = swiften_env.SwiftenObject([
 			"PresenceOracle.cpp",
 			"PresenceSender.cpp",
 			"DirectedPresenceSender.cpp",
diff --git a/Swiften/SASL/SConscript b/Swiften/SASL/SConscript
index 0ef9581..5a0cdef 100644
--- a/Swiften/SASL/SConscript
+++ b/Swiften/SASL/SConscript
@@ -3,7 +3,7 @@ Import("swiften_env", "env")
 myenv = swiften_env.Clone()
 myenv.MergeFlags(swiften_env["LIBIDN_FLAGS"])
 
-objects = myenv.StaticObject([
+objects = myenv.SwiftenObject([
 		"ClientAuthenticator.cpp",
 		"PLAINClientAuthenticator.cpp",
 		"PLAINMessage.cpp",
diff --git a/Swiften/SConscript b/Swiften/SConscript
index 8eeab37..7b8991e 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -6,12 +6,14 @@ Import("env")
 # Flags
 ################################################################################
 
+swiften_dep_modules = ["BOOST", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT"]
+
 if env["SCONS_STAGE"] == "flags" :
 	swiften_env = env.Clone()
 	swiften_env["LIBPATH"] = [Dir(".")]
 	swiften_env["LIBS"] = ["Swiften"]
 	dep_env = env.Clone()
-	for module in ["BOOST", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT"] :
+	for module in swiften_dep_modules :
 		if env.get(module + "_BUNDLED", False) :
 			swiften_env.UseFlags(env.get(module + "_FLAGS", {}))
 		else :
@@ -33,12 +35,20 @@ if env["SCONS_STAGE"] == "flags" :
 
 if env["SCONS_STAGE"] == "build" :
 	swiften_env = env.Clone()
-	swiften_env.MergeFlags(swiften_env["BOOST_FLAGS"])
+	for module in swiften_dep_modules :
+		swiften_env.UseFlags(swiften_env.get(module + "_FLAGS", {}))
+	swiften_env.UseFlags(swiften_env["PLATFORM_FLAGS"])
+	def buildObject(env, sources) :
+		if ARGUMENTS.get("swiften_dll", False) :
+			return env.SharedObject(sources)
+		else :
+			return env.StaticObject(sources)
+	swiften_env.AddMethod(buildObject, "SwiftenObject")
+
 	Export("swiften_env")
 
 # TODO: Move all this to a submodule SConscript
 	myenv = swiften_env.Clone()
-	myenv.MergeFlags(myenv["ZLIB_FLAGS"])
 	sources = [
 			"Chat/ChatStateTracker.cpp",
 			"Chat/ChatStateNotifier.cpp",
@@ -167,7 +177,10 @@ if env["SCONS_STAGE"] == "build" :
 			"Examples"
 		])
 
-	myenv.StaticLibrary("Swiften", sources + swiften_env["SWIFTEN_OBJECTS"])
+	if ARGUMENTS.get("swiften_dll", False) :
+		myenv.SharedLibrary("Swiften", sources + swiften_env["SWIFTEN_OBJECTS"])
+	else :
+		myenv.StaticLibrary("Swiften", sources + swiften_env["SWIFTEN_OBJECTS"])
 
 	env.Append(UNITTEST_SOURCES = [
 			File("Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp"),
diff --git a/Swiften/StreamManagement/SConscript b/Swiften/StreamManagement/SConscript
index d3fab8e..4eaef67 100644
--- a/Swiften/StreamManagement/SConscript
+++ b/Swiften/StreamManagement/SConscript
@@ -5,4 +5,4 @@ sources = [
 		"StanzaAckResponder.cpp",
 	]
 
-swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.StaticObject(sources))
\ No newline at end of file
+swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.SwiftenObject(sources))
\ No newline at end of file
diff --git a/Swiften/StreamStack/SConscript b/Swiften/StreamStack/SConscript
index 0aca8d2..022c695 100644
--- a/Swiften/StreamStack/SConscript
+++ b/Swiften/StreamStack/SConscript
@@ -11,5 +11,5 @@ sources = [
 		"XMPPLayer.cpp",
 	]
 
-objects = myenv.StaticObject(sources)
+objects = myenv.SwiftenObject(sources)
 swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/TLS/SConscript b/Swiften/TLS/SConscript
index 43f7db6..b5829d6 100644
--- a/Swiften/TLS/SConscript
+++ b/Swiften/TLS/SConscript
@@ -1,6 +1,6 @@
 Import("swiften_env")
 
-objects = swiften_env.StaticObject([
+objects = swiften_env.SwiftenObject([
 			"Certificate.cpp",
 			"CertificateFactory.cpp",
 			"CertificateTrustChecker.cpp",
@@ -12,14 +12,14 @@ objects = swiften_env.StaticObject([
 myenv = swiften_env.Clone()
 if myenv.get("HAVE_OPENSSL", 0) :
 	myenv.MergeFlags(myenv["OPENSSL_FLAGS"])
-	objects += myenv.StaticObject([
+	objects += myenv.SwiftenObject([
 			"OpenSSL/OpenSSLContext.cpp",
 			"OpenSSL/OpenSSLCertificate.cpp",
 			"OpenSSL/OpenSSLContextFactory.cpp",
 		])
 	myenv.Append(CPPDEFINES = "HAVE_OPENSSL")
 
-objects += myenv.StaticObject(["PlatformTLSFactories.cpp"])
+objects += myenv.SwiftenObject(["PlatformTLSFactories.cpp"])
 
 		
 
diff --git a/Swiften/VCards/SConscript b/Swiften/VCards/SConscript
index 13be7d3..e980ba3 100644
--- a/Swiften/VCards/SConscript
+++ b/Swiften/VCards/SConscript
@@ -1,6 +1,6 @@
 Import("swiften_env")
 
-objects = swiften_env.StaticObject([
+objects = swiften_env.SwiftenObject([
 			"VCardManager.cpp",
 			"VCardStorage.cpp",
 			"VCardFileStorage.cpp",
-- 
cgit v0.10.2-6-g49f6