xmake.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package("freerdp")
  2. set_homepage("https://www.freerdp.com/")
  3. set_description("FreeRDP is a free remote desktop protocol library and clients ")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/FreeRDP/FreeRDP/releases/download/$(version)/freerdp-$(version).tar.gz",
  6. "https://github.com/FreeRDP/FreeRDP.git")
  7. add_versions("3.22.0", "656670f3aac2c995cb4b1ba181549cc122cc9c95ec31be68a582c1182f474376")
  8. add_versions("3.21.0", "ec1409ce88020eeebc54e20cc0766cbe7d2e2f4bd382c7061c86f89231a9f44d")
  9. add_versions("3.20.0", "96631873b00c8a872c9fe4e668957c3e4e0808f81ccb71f6ac028096a2682806")
  10. add_versions("3.19.1", "0886818968884464d72f8c363b633e97561bd438d84fce7331cb0df07b088919")
  11. add_versions("3.18.0", "70e89fdc92e3c2a429a7e61015ffd55bda4f6fefd76bb2978a91134d94869462")
  12. add_versions("3.17.2", "c42c712ad879bf06607b78b8c3fad98e08c82f73f4e0bc1693552900041e692a")
  13. add_versions("3.16.0", "385af54245560493698730b688b5e6e5d56d5c7ecf2fa7c1d7cedfde8a4ba456")
  14. add_versions("3.15.0", "e8cd58decef4c970faea2fbea675970eea60e440ebe8033c54889acb83787371")
  15. if is_plat("mingw") then
  16. add_patches(">=3.19.1", "patches/3.19.1/mingw-c11.patch", "84083315e41f8e2800c838ef9d36a7db3ea6470ae86c30ed691af30a017b5870")
  17. end
  18. add_configs("client", {description = "Build client", default = false, type = "boolean"})
  19. add_configs("client_channels", {description = "Build virtual channel plugins", default = false, type = "boolean"})
  20. add_configs("server", {description = "Build server", default = false, type = "boolean"})
  21. add_configs("server_channels", {description = "Build virtual channel plugins", default = false, type = "boolean"})
  22. add_configs("rdtk", {description = "Build rdtk toolkit", default = false, type = "boolean"})
  23. add_configs("shadow", {description = "Compile with shadow server", default = false, type = "boolean"})
  24. add_configs("proxy", {description = "Compile with proxy server", default = false, type = "boolean"})
  25. add_configs("platform_server", {description = "Compile with platform server", default = false, type = "boolean"})
  26. add_configs("x11", {description = "Build X11 client/server", default = false, type = "boolean"})
  27. add_configs("wayland", {description = "Build with wayland", default = false, type = "boolean"})
  28. add_configs("fuse", {description = "Build clipboard with FUSE file copy support", default = false, type = "boolean"})
  29. add_configs("json", {description = "Build with any JSON support", default = nil, type = "string", values = {"cjson", "json-c"}})
  30. add_configs("uriparser", {description = "use uriparser library to handle URIs", default = false, type = "boolean"})
  31. add_configs("ffmpeg", {description = "Enable FFMPEG for audio/video encoding/decoding", default = false, type = "boolean"})
  32. add_configs("cairo", {description = "Use CAIRO image library for screen resizing", default = false, type = "boolean"})
  33. add_configs("swscale", {description = "Use SWScale image library for screen resizing", default = false, type = "boolean"})
  34. add_configs("openh264", {description = "Build openh264", default = false, type = "boolean"})
  35. add_configs("krb5", {description = "Compile support for kerberos authentication.", default = false, type = "boolean"})
  36. -- Try resolve emmintrin.h:740:1: error: inlining failed in call to 'always_inline' '_mm_storeu_si128': target specific option mismatch
  37. add_configs("simd", {description = "Build with simd", default = not is_plat("wasm") and not (is_arch("i386") and is_plat("mingw") and is_subhost("macosx")), type = "boolean"})
  38. -- winpr
  39. add_configs("unicode_builtin", {description = "Build builtin unicode", default = true, type = "boolean"})
  40. add_configs("timezone_icu", {description = "Use ICU for improved timezone mapping", default = false, type = "boolean"})
  41. add_configs("winpr_tools", {description = "Build WinPR helper binaries", default = false, type = "boolean"})
  42. if is_plat("windows", "mingw") then
  43. add_configs("winmm", {description = "Use Windows Multimedia", default = true, type = "boolean"})
  44. end
  45. if is_plat("linux", "bsd") then
  46. add_syslinks("pthread")
  47. elseif is_plat("windows", "mingw") then
  48. add_syslinks("rpcrt4", "ncrypt", "shell32", "ole32", "dbghelp", "shlwapi", "ntdll")
  49. if is_plat("mingw") then
  50. add_syslinks("uuid")
  51. end
  52. elseif is_plat("macosx") then
  53. add_frameworks("CoreFoundation", "Carbon")
  54. end
  55. add_deps("cmake")
  56. add_deps("zlib", "openssl3")
  57. add_includedirs("include", "include/freerdp3", "include/winpr3")
  58. add_links("freerdp-server3", "freerdp-server-proxy3", "freerdp-client3", "freerdp3", "rdtk0", "winpr3")
  59. on_load(function (package)
  60. if package:config("shadow") or package:config("proxy") or package:config("platform_server") then
  61. package:config_set("server", true)
  62. end
  63. if package:config("proxy") then
  64. package:config_set("client", true)
  65. end
  66. local configs_map_to_deps = {
  67. client = "libusb",
  68. wayland = "wayland",
  69. fuse = "libfuse",
  70. json = package:config("json"),
  71. uriparser = "uriparser",
  72. cairo = "cairo",
  73. openh264 = "openh264",
  74. ffmpeg = "ffmpeg",
  75. swscale = "ffmpeg",
  76. krb5 = "krb5",
  77. }
  78. for config, dep in pairs(configs_map_to_deps) do
  79. if package:config(config) then
  80. package:add("deps", dep)
  81. end
  82. end
  83. if package:config("x11") or package:config("shadow") then
  84. package:add("deps", "libx11", "libxext", "libxcursor")
  85. end
  86. if not package:config("unicode_builtin") or package:config("timezone_icu") then
  87. package:add("deps", "icu4c")
  88. end
  89. if package:dep("libusb") then
  90. if is_subhost("windows") then
  91. package:add("deps", "pkgconf")
  92. else
  93. package:add("deps", "pkg-config")
  94. end
  95. end
  96. -- https://github.com/libfuse/libfuse/issues/383
  97. if package:config("fuse") then
  98. package:add("deps", "libfuse", {configs = {shared = true}})
  99. end
  100. if package:is_plat("windows", "mingw") and not package:config("shared") then
  101. package:add("defines", "FREERDP_EXPORTS")
  102. end
  103. if package:config("winmm") and package:is_plat("windows", "mingw") then
  104. package:add("syslinks", "winmm")
  105. end
  106. end)
  107. on_install("!bsd and !iphoneos", function (package)
  108. if package:is_plat("mingw") then
  109. io.replace("winpr/include/winpr/wtypes.h", "typedef ssize_t SSIZE_T;", "#ifndef _SSIZE_T_DEFINED\ntypedef ssize_t SSIZE_T;\n#endif", {plain = true})
  110. end
  111. io.replace("CMakeLists.txt", "include(${CMAKE_CPACK_INCLUDE_FILE})", "", {plain = true})
  112. io.replace("cmake/MSVCRuntime.cmake", "if(BUILD_SHARED_LIBS)", "if(0)", {plain = true})
  113. if package:config("fuse") then
  114. io.replace("client/common/CMakeLists.txt", "pkg_check_modules(FUSE3 REQUIRED fuse3)", "pkg_check_modules(FUSE3 REQUIRED IMPORTED_TARGET fuse3)", {plain = true})
  115. io.replace("client/common/CMakeLists.txt", "${FUSE3_LIBRARIES}", "PkgConfig::FUSE3", {plain = true})
  116. end
  117. local libusb = package:dep("libusb")
  118. if libusb and not libusb:is_system() and not libusb:config("shared") and package:is_plat("linux", "cross") then
  119. io.replace("cmake/Findlibusb-1.0.cmake", "set(LIBUSB_1_LIBRARIES ${LIBUSB_1_LIBRARY})",
  120. [[find_package(PkgConfig)
  121. pkg_check_modules(PC_LIBUDEV QUIET libudev)
  122. find_library(UDEV_LIBRARY NAMES udev PATHS ${PC_LIBUDEV_LIBRARY_DIRS} ${PC_LIBUDEV_LIBDIR} PATH_SUFFIXES lib)
  123. set(LIBUSB_1_LIBRARIES ${LIBUSB_1_LIBRARY} ${UDEV_LIBRARY})]], {plain = true})
  124. end
  125. local configs = {
  126. "-DWITH_SAMPLE=OFF",
  127. "-DWITH_MANPAGES=OFF",
  128. "-DBUILD_TESTING=OFF",
  129. "-DWITH_CCACHE=OFF",
  130. "-DWITH_CLANG_FORMAT=OFF",
  131. "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF",
  132. -- build bundle winpr
  133. "-DFREERDP_UNIFIED_BUILD=ON",
  134. "-DWITH_CUPS=OFF",
  135. }
  136. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  137. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  138. local dep = package:config("json")
  139. table.insert(configs, "-DWITH_JSON_DISABLED=" .. (dep and "OFF" or "ON"))
  140. table.insert(configs, "-DWITH_CJSON_REQUIRED=" .. (dep == "cjson" and "ON" or "OFF"))
  141. table.insert(configs, "-DWITH_JSONC_REQUIRED=" .. (dep == "json-c" and "ON" or "OFF"))
  142. if package:is_plat("mingw") then
  143. -- winpr/libwinpr/utils/unwind/debug.c require dlfcn.h, try `dlfcn-win32`?
  144. table.insert(configs, "-DUSE_UNWIND=OFF")
  145. -- fatal error: bits/libc-header-start.h: No such file or directory
  146. table.insert(configs, "-DWITH_SMARTCARD_EMULATE=OFF")
  147. end
  148. table.insert(configs, "-DWITH_CLIENT_COMMON=" .. (package:config("client") and "ON" or "OFF"))
  149. for name, enabled in table.orderpairs(package:configs()) do
  150. if not package:extraconf("configs", name, "builtin") then
  151. table.insert(configs, format("-DWITH_%s=%s", name:upper(), (enabled and "ON" or "OFF")))
  152. end
  153. end
  154. local opt = {}
  155. if package:is_plat("mingw") and package:has_tool("cc", "gcc") then
  156. opt.cxflags = "-Wno-error=incompatible-pointer-types"
  157. end
  158. if package:dep("libx11") then
  159. opt.packagedeps = {"libx11", "xorgproto", "libxext", "libxcursor"}
  160. end
  161. if package:dep("ffmpeg") and not package:has_tool("ld", "link") then
  162. -- https://stackoverflow.com/questions/44379426/building-shared-library-with-ffmpeg-results-in-relocation-error
  163. opt.ldflags = "-Wl,-Bsymbolic"
  164. opt.shflags = "-Wl,-Bsymbolic"
  165. end
  166. import("package.tools.cmake").install(package, configs, opt)
  167. end)
  168. on_test(function (package)
  169. assert(package:has_cfuncs("winpr_get_version", {includes = "winpr/winpr.h"}))
  170. assert(package:has_cfuncs("freerdp_get_version", {includes = "freerdp/freerdp.h"}))
  171. end)