xmake.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package("exosip")
  2. set_homepage("https://savannah.nongnu.org/projects/exosip")
  3. set_description("eXosip is a library that hides the complexity of using the SIP protocol for mutlimedia session establishement")
  4. set_license("GPL-2.0")
  5. add_urls("https://www.antisip.com/download/exosip2/libexosip2-$(version).tar.gz", {alias = "mirror"})
  6. add_urls("https://git.savannah.nongnu.org/cgit/exosip.git/snapshot/exosip-$(version).tar.gz", {alias = "archive"})
  7. add_urls("git://git.savannah.gnu.org/exosip.git", {alias = "github"})
  8. add_versions("mirror:5.3.0", "5b7823986431ea5cedc9f095d6964ace966f093b2ae7d0b08404788bfcebc9c2")
  9. add_versions("archive:5.3.0", "66c2b2ddcfdc8807054fa31f72a6068ef66d98bedd9aedb25b9031718b9906a2")
  10. add_versions("github:5.3.0", "7b0983106eaf7f9bad227922e8905bcf0a7b4f59")
  11. if is_plat("windows") then
  12. add_resources("5.3.0", "nameser_header", "https://raw.githubusercontent.com/c-ares/c-ares/refs/tags/curl-7_20_0/nameser.h", "8acc1a774896c0d02180b355bcb67dba4935a10e5ef54f4290600ae61bb9aa3d")
  13. end
  14. if not is_plat("windows") then
  15. add_deps("autotools", "pkg-config")
  16. end
  17. add_deps("osip", "c-ares", "openssl3")
  18. if is_plat("windows") then
  19. add_links("eXosip")
  20. else
  21. add_links("eXosip2", "osip2", "osipparser2")
  22. end
  23. if is_plat("windows") then
  24. add_syslinks("dnsapi")
  25. elseif is_plat("macosx") then
  26. add_syslinks("resolv")
  27. add_frameworks("CoreFoundation", "CoreServices", "Security")
  28. elseif is_plat("bsd", "linux") then
  29. add_syslinks("pthread", "resolv")
  30. end
  31. on_install("windows", function(package)
  32. import("package.tools.msbuild")
  33. os.cp("include", package:installdir())
  34. local headerdir = package:resourcedir("nameser_header")
  35. os.cp(path.join(headerdir, "../nameser.h"), "include/nameser.h")
  36. os.cp(path.join(package:scriptdir(), "port", "exosip2.def"), "platform/vsnet/eXosip2.def")
  37. local arch = package:is_arch("x64") and "x64" or "Win32"
  38. if package:is_arch("arm64") then
  39. arch = "ARM64"
  40. io.replace("platform/vsnet/eXosip.sln", "|x64", "|ARM64", {plain = true})
  41. end
  42. local mode = package:is_debug() and "Debug" or "Release"
  43. local configs = { "eXosip.sln" }
  44. table.insert(configs, "/t:eXosip")
  45. table.insert(configs, "/p:Configuration=" .. mode)
  46. table.insert(configs, "/p:Platform=" .. arch)
  47. table.insert(configs, "/p:BuildProjectReferences=false")
  48. local include_paths = {}
  49. local lib_paths = {}
  50. local libs = {"dnsapi.lib"}
  51. for _, dep in ipairs({"osip", "c-ares", "openssl3"}) do
  52. local packagedep = package:dep(dep)
  53. if packagedep then
  54. local fetchinfo = packagedep:fetch()
  55. if fetchinfo then
  56. for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  57. table.insert(include_paths, includedir)
  58. end
  59. for _, linkdir in ipairs(fetchinfo.linkdirs) do
  60. table.insert(lib_paths, linkdir)
  61. end
  62. for _, syslink in ipairs(fetchinfo.syslinks) do
  63. table.insert(libs, syslink .. ".lib")
  64. end
  65. for _, link in ipairs(fetchinfo.libfiles) do
  66. -- Exclude ossl-modules/legacy.lib
  67. if not link:lower():match("legacy.dll") then
  68. table.insert(libs, link)
  69. end
  70. end
  71. end
  72. end
  73. end
  74. os.cd("platform/vsnet")
  75. io.replace("eXosip.vcxproj",
  76. "<AdditionalIncludeDirectories>.-</AdditionalIncludeDirectories>",
  77. "<AdditionalIncludeDirectories>" .. table.concat(include_paths, ";") .. "</AdditionalIncludeDirectories>")
  78. io.replace("eXosip.vcxproj", [[<AdditionalIncludeDirectories>]], [[<AdditionalIncludeDirectories>..\..\..\source\include;]], {plain = true})
  79. if package:is_arch("arm64") then
  80. io.replace("eXosip.vcxproj", "|x64", "|ARM64", {plain = true})
  81. io.replace("eXosip.vcxproj", "<Platform>x64", "<Platform>ARM64", {plain = true})
  82. end
  83. if not package:has_runtime("MT", "MTd") then
  84. -- Allow MD, MDd
  85. io.replace("eXosip.vcxproj", "MultiThreadedDebug", "MultiThreadedDebugDLL", {plain = true})
  86. io.replace("eXosip.vcxproj", "MultiThreaded", "MultiThreadedDLL", {plain = true})
  87. end
  88. if package:config("shared") then
  89. -- Pass .def file
  90. io.replace("eXosip.vcxproj", [[</ClCompile>]],
  91. [[</ClCompile><Link><ModuleDefinitionFile>$(ProjectDir)/eXosip2.def</ModuleDefinitionFile></Link>]], {plain = true})
  92. io.replace("eXosip.vcxproj", [[</Link>]],
  93. [[<AdditionalLibraryDirectories>]] .. table.concat(lib_paths, ";") .. [[</AdditionalLibraryDirectories><AdditionalDependencies>]] .. table.concat(libs, ";") .. [[</AdditionalDependencies></Link>]], {plain = true})
  94. -- Allow build shared lib
  95. io.replace("eXosip.vcxproj", "StaticLibrary", "DynamicLibrary", {plain = true})
  96. end
  97. -- Allow use another Win SDK
  98. io.replace("eXosip.vcxproj", "<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>", "", {plain = true})
  99. -- Use *source* dir
  100. io.replace("eXosip.vcxproj", [[<ClCompile Include="..\..\..\exosip\]], [[<ClCompile Include="..\..\..\source\]], {plain = true})
  101. io.replace("eXosip.vcxproj", [[<ClInclude Include="..\..\..\exosip\]], [[<ClInclude Include="..\..\..\source\]], {plain = true})
  102. -- Do not use ProjectReference
  103. io.replace("eXosip.vcxproj", "<ProjectReference.-</ProjectReference>", "")
  104. msbuild.build(package, configs)
  105. os.cp("**.lib", package:installdir("lib"))
  106. if package:config("shared") then
  107. os.cp("**.dll", package:installdir("bin"))
  108. end
  109. end)
  110. on_install("linux", "macosx", "android@linux,macosx", "cross", "wasm", function (package)
  111. if package:is_plat("macosx") then
  112. io.replace("src/Makefile.am",
  113. "libeXosip2_la_LDFLAGS = -version-info $(LIBEXOSIP_SO_VERSION) -no-undefined",
  114. "libeXosip2_la_LDFLAGS = -version-info $(LIBEXOSIP_SO_VERSION) -no-undefined\nlibeXosip2_la_LDFLAGS += -framework CoreFoundation -framework CoreServices -framework Security", {plain = true})
  115. end
  116. if package:is_plat("android") then
  117. local ndkver = tonumber(package:toolchain("ndk"):config("ndkver"))
  118. if ndkver > 22 then
  119. io.replace("src/eXutils.c", [[#elif (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || __APPLE__ || defined(ANDROID)) && !_GNU_SOURCE]],
  120. [[#elif 1]], {plain = true})
  121. end
  122. end
  123. local configs = {"--disable-trace", "--enable-pthread=force", "--enable-tools=no"}
  124. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  125. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  126. if not package:debug() then
  127. table.insert(configs, "--disable-debug")
  128. end
  129. import("package.tools.autoconf").install(package, configs)
  130. end)
  131. on_test(function (package)
  132. assert(package:has_cfuncs("eXosip_lock", {includes = "eXosip2/eXosip.h", "eXosip2.h"}))
  133. end)