xmake.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. set_project("libffi")
  2. add_rules("mode.debug", "mode.release")
  3. add_rules("utils.install.cmake_importfiles")
  4. set_configvar("PACKAGE", "libffi")
  5. set_configvar("PACKAGE_NAME", "libffi")
  6. set_configvar("PACKAGE_TARNAME", "libffi")
  7. set_configvar("PACKAGE_BUGREPORT", "")
  8. set_configvar("PACKAGE_URL", "")
  9. option("vers")
  10. set_default("3.4.2")
  11. set_showmenu(true)
  12. option_end()
  13. if has_config("vers") then
  14. set_version(get_config("vers"))
  15. set_configvar("VERSION", get_config("vers"))
  16. set_configvar("PACKAGE_VERSION", get_config("vers"))
  17. set_configvar("PACKAGE_STRING", "libffi " .. get_config("vers"))
  18. end
  19. local targetarch = is_plat("windows") and "X86_WIN64" or "X86_64"
  20. if is_plat("windows") then
  21. if is_arch("x86") then
  22. targetarch = "X86_WIN32"
  23. elseif is_arch("x64") then
  24. targetarch = "X86_WIN64"
  25. elseif is_arch("arm") then
  26. targetarch = "ARM_WIN32"
  27. elseif is_arch("arm64") then
  28. targetarch = "ARM_WIN64"
  29. end
  30. elseif is_plat("macosx") and is_arch("i386", "x86") then
  31. targetarch = "X86_DARWIN"
  32. elseif is_plat("bsd") and is_arch("i386", "x86") then
  33. targetarch = "X86_FREEBSD"
  34. else
  35. if is_arch("i386", "x86") then
  36. targetarch = "X86"
  37. elseif is_arch("x64") then
  38. targetarch = "X86_64"
  39. elseif is_arch("arm") then
  40. targetarch = "ARM"
  41. elseif is_arch("arm64") then
  42. targetarch = "ARM64"
  43. elseif is_arch("mips64") then
  44. targetarch = "MIPS64"
  45. elseif is_arch("riscv") then
  46. targetarch = "RISCV"
  47. end
  48. end
  49. set_configvar("TARGET", targetarch)
  50. includes("check_cfuncs.lua")
  51. includes("check_cincludes.lua")
  52. includes("check_csnippets.lua")
  53. set_configvar("STDC_HEADERS", 1)
  54. set_configvar("LT_OBJDIR", ".libs/")
  55. configvar_check_cincludes("HAVE_INTTYPES_H", "inttypes.h")
  56. configvar_check_cincludes("HAVE_MEMORY_H", "memory.h")
  57. configvar_check_cincludes("HAVE_STDINT_H", "stdint.h")
  58. configvar_check_cincludes("HAVE_STDLIB_H", "stdlib.h")
  59. configvar_check_cincludes("HAVE_STRINGS_H", "strings.h")
  60. configvar_check_cincludes("HAVE_STRING_H", "string.h")
  61. configvar_check_cincludes("HAVE_SYS_STAT_H", "sys/stat.h")
  62. configvar_check_cincludes("HAVE_SYS_TYPES_H", "sys/types.h")
  63. configvar_check_cincludes("HAVE_ALLOCA_H", "alloca.h")
  64. configvar_check_cfuncs("HAVE_ALLOCA", "alloca", {includes = "alloca.h"})
  65. configvar_check_csnippets("HAVE_LONG_DOUBLE", [[assert(sizeof(long double) > sizeof(double));]], {includes = "assert.h", tryrun = true, default = 0})
  66. configvar_check_csnippets("SIZEOF_DOUBLE", [[printf("%d", sizeof(double));]], {tryrun = true, output = true, number = true})
  67. configvar_check_csnippets("SIZEOF_LONG_DOUBLE", [[printf("%d", sizeof(long double));]], {tryrun = true, output = true, number = true})
  68. configvar_check_csnippets("SIZEOF_SIZE_T", [[printf("%d", sizeof(size_t));]], {tryrun = true, output = true, number = true})
  69. if not is_plat("windows") then
  70. set_configvar("HAVE_AS_X86_PCREL", 1)
  71. end
  72. if is_plat("macosx") then
  73. set_configvar("SYMBOL_UNDERSCORE", 1)
  74. end
  75. if is_plat("linux") then
  76. set_configvar("HAVE_HIDDEN_VISIBILITY_ATTRIBUTE", 1)
  77. set_configvar("EH_FRAME_FLAGS", "a")
  78. end
  79. if is_plat("macosx") and is_arch("arm64") then
  80. set_configvar("FFI_EXEC_TRAMPOLINE_TABLE", 1)
  81. else
  82. set_configvar("FFI_EXEC_TRAMPOLINE_TABLE", 0)
  83. end
  84. rule("asm.preprocess")
  85. set_extensions(".S")
  86. on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
  87. import("lib.detect.find_tool")
  88. local rootdir = path.join(target:autogendir(), "rules", "asm.preprocess")
  89. local filename = path.basename(sourcefile) .. ".asm"
  90. local sourcefile_or = path.absolute(sourcefile)
  91. local sourcefile_cx = target:autogenfile(sourcefile, {rootdir = rootdir, filename = filename})
  92. -- preprocessing
  93. local envs = target:toolchain("msvc"):runenvs()
  94. local cl = find_tool("cl", {envs = envs})
  95. batchcmds:execv(cl.program, {"/nologo", "/EP", "/Iinclude",
  96. "/I" .. path.directory(sourcefile_or), sourcefile_or}, {envs = envs, stdout = sourcefile_cx})
  97. local objectfile = target:objectfile(sourcefile_cx)
  98. table.insert(target:objectfiles(), objectfile)
  99. batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", sourcefile_cx)
  100. batchcmds:compile(sourcefile_cx, objectfile)
  101. batchcmds:add_depfiles(sourcefile)
  102. batchcmds:set_depmtime(os.mtime(objectfile))
  103. batchcmds:set_depcache(target:dependfile(objectfile))
  104. end)
  105. rule_end()
  106. if is_plat("windows") then
  107. add_rules("asm.preprocess", {override = true})
  108. end
  109. target("ffi")
  110. set_kind("$(kind)")
  111. if is_plat("windows") and is_kind("shared") then
  112. add_defines("FFI_BUILDING_DLL")
  113. end
  114. set_configdir("include")
  115. add_configfiles("fficonfig.h.in")
  116. add_configfiles("include/ffi.h.in", {pattern = "@(.-)@"})
  117. add_includedirs("include")
  118. add_headerfiles("include/ffi.h")
  119. add_files("src/prep_cif.c", "src/types.c", "src/closures.c", "src/tramp.c")
  120. if not is_arch("arm") and not is_arch("arm64") then
  121. add_files("src/raw_api.c", "src/java_raw_api.c")
  122. end
  123. if is_plat("windows") and is_arch("x86") then
  124. add_asflags("/GZ")
  125. end
  126. if is_arch("i386", "x86") then
  127. add_files("src/x86/ffi.c")
  128. add_files(is_plat("windows") and "src/x86/sysv_intel.S" or "src/x86/sysv.S")
  129. add_includedirs("src/x86")
  130. add_headerfiles("src/x86/ffitarget.h")
  131. elseif is_arch("x86_64") then
  132. add_files("src/x86/ffi64.c", "src/x86/unix64.S", "src/x86/ffiw64.c", "src/x86/win64.S")
  133. add_includedirs("src/x86")
  134. add_headerfiles("src/x86/ffitarget.h")
  135. elseif is_arch("x64") then
  136. add_files("src/x86/ffi64.c", "src/x86/ffiw64.c", "src/x86/win64_intel.S")
  137. add_includedirs("src/x86")
  138. add_headerfiles("src/x86/ffitarget.h")
  139. elseif is_arch("arm") then
  140. add_files("src/arm/ffi.c")
  141. add_files(is_plat("windows") and "src/arm/sysv_msvc_arm32.S" or "src/arm/sysv.S")
  142. add_includedirs("src/arm")
  143. add_headerfiles("src/arm/ffitarget.h")
  144. elseif is_arch("arm64") then
  145. add_files("src/aarch64/ffi.c")
  146. add_files(is_plat("windows") and "src/aarch64/win64_armasm.S" or "src/aarch64/sysv.S")
  147. add_includedirs("src/aarch64")
  148. add_headerfiles("src/aarch64/ffitarget.h")
  149. elseif is_arch("mips64") then
  150. add_files("src/mips/ffi.c", "src/mips/n32.S")
  151. add_headerfiles("src/mips/ffitarget.h")
  152. elseif is_arch("riscv") then
  153. add_files("src/riscv/ffi.c", "src/riscv/sysv.S")
  154. add_headerfiles("src/riscv/ffitarget.h")
  155. end
  156. before_build(function (target)
  157. io.replace("include/ffi.h", "!defined FFI_BUILDING", target:is_static() and "0" or "1", {plain = true})
  158. end)