Browse Source

osip: add windows support (#6679)

* Add `windows` to `osip`

* Fix build

* Proxying ARM64.

* re

* re

* Fixup

* Proxying

* Improve vcxproj

* check plats

* Fixup

* Finish

* Fixup

* Update xmake.lua

* workaround ...

* Update xmake.lua

* Update xmake.lua
Saikari 5 months ago
parent
commit
5d43be9f34
1 changed files with 84 additions and 2 deletions
  1. 84 2
      packages/o/osip/xmake.lua

+ 84 - 2
packages/o/osip/xmake.lua

@@ -8,16 +8,98 @@ package("osip")
 
     add_versions("5.3.0", "593c9d61150b230f7e757b652d70d5fe336c84db7e4db190658f9ef1597d59ed")
 
-    add_deps("autoconf", "automake", "m4", "libtool")
+    if is_plat("wasm") then
+        add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
+    end
+
+    if is_plat("windows") then
+        add_syslinks("advapi32")
+    else
+        add_deps("autoconf", "automake", "libtool")
+    end
+
     add_links("osip2", "osipparser2")
 
-    on_install("linux", "macosx", function (package)
+    on_install("windows", function(package)
+        import("package.tools.msbuild")
+
+        os.cp("include", package:installdir())
+
+        -- rename *source* directory to *osip* directory
+        local curdir = os.curdir()
+        os.cd("..")
+        os.mv(curdir, "osip")
+        os.cd("osip")
+
+        local arch = package:is_arch("x64") and "x64" or "Win32"
+        if package:is_arch("arm64") then
+            arch = "ARM64"
+            io.replace("platform/vsnet/osip.sln", "|x64", "|ARM64", {plain = true})
+        end
+        local mode = package:debug() and "Debug" or "Release"
+        local configs = { "osip.sln" }
+        table.insert(configs, "/property:Configuration=" .. mode)
+        table.insert(configs, "/property:Platform=" .. arch)
+        os.cd("platform/vsnet")
+
+        -- Add external symbols into .def file for .DLL library
+        local osip2_def_content = io.readfile("osip2.def")
+        io.writefile("osip2.def", osip2_def_content .. [[
+            osip_transaction_set_naptr_record @138
+        ]])
+
+        local osipparser2_def_content = io.readfile("osipparser2.def")
+        io.writefile("osipparser2.def", osipparser2_def_content .. [[
+            osip_realloc @417
+            osip_strcasestr @418
+            __osip_uri_escape_userinfo @419
+            osip_list_clone @420
+        ]])
+
+        local files = {
+            "osip2.vcxproj",
+            "osipparser2.vcxproj"
+        }
+
+        for _, vcxproj in ipairs(files) do
+            if package:is_arch("arm64") then
+                io.replace(vcxproj, "|x64", "|ARM64", {plain = true})
+                io.replace(vcxproj, "<Platform>x64", "<Platform>ARM64", {plain = true})
+            end
+            if not package:has_runtime("MT", "MTd") then
+                -- Allow MD, MDd
+                io.replace(vcxproj, "MultiThreaded", "MultiThreadedDLL", {plain = true})
+                io.replace(vcxproj, "MultiThreadedDebug", "MultiThreadedDebugDLL", {plain = true})
+            end
+            if package:config("shared") then
+                -- Pass .def file
+                io.replace(vcxproj, "</ClCompile>",
+                    "</ClCompile><Link><ModuleDefinitionFile>$(ProjectDir)/$(TargetName).def</ModuleDefinitionFile></Link>", {plain = true})
+                -- Allow build shared lib
+                io.replace(vcxproj, "StaticLibrary", "DynamicLibrary", {plain = true})
+            end
+            -- Allow use another Win SDK
+            io.replace(vcxproj, "<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>", "", {plain = true})
+        end
+
+        msbuild.build(package, configs)
+
+        os.cp("**.lib", package:installdir("lib"))
+        if package:config("shared") then
+            os.cp("**.dll", package:installdir("bin"))
+        end
+    end)
+
+    on_install("linux", "macosx", "bsd", "android@linux,macosx", "iphoneos", "cross", "wasm", function (package)
         local configs = {"--disable-trace"}
         table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
         table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
         if not package:debug() then
             table.insert(configs, "--disable-debug")
         end
+        if package:is_plat("android") then
+            table.insert(configs, "--enable-pthread=force")
+        end
         import("package.tools.autoconf").install(package, configs)
     end)