xmake.lua 9.6 KB

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