xmake.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. end
  44. end
  45. set_configvar("TARGET", targetarch)
  46. includes("check_cfuncs.lua")
  47. includes("check_cincludes.lua")
  48. includes("check_csnippets.lua")
  49. set_configvar("STDC_HEADERS", 1)
  50. set_configvar("LT_OBJDIR", ".libs/")
  51. configvar_check_cincludes("HAVE_INTTYPES_H", "inttypes.h")
  52. configvar_check_cincludes("HAVE_MEMORY_H", "memory.h")
  53. configvar_check_cincludes("HAVE_STDINT_H", "stdint.h")
  54. configvar_check_cincludes("HAVE_STDLIB_H", "stdlib.h")
  55. configvar_check_cincludes("HAVE_STRINGS_H", "strings.h")
  56. configvar_check_cincludes("HAVE_STRING_H", "string.h")
  57. configvar_check_cincludes("HAVE_SYS_STAT_H", "sys/stat.h")
  58. configvar_check_cincludes("HAVE_SYS_TYPES_H", "sys/types.h")
  59. configvar_check_cincludes("HAVE_ALLOCA_H", "alloca.h")
  60. configvar_check_cfuncs("HAVE_ALLOCA", "alloca", {includes = "alloca.h"})
  61. configvar_check_csnippets("HAVE_LONG_DOUBLE", [[assert(sizeof(long double) > sizeof(double));]], {includes = "assert.h", tryrun = true, default = 0})
  62. configvar_check_csnippets("SIZEOF_DOUBLE", [[printf("%d", sizeof(double));]], {tryrun = true, output = true, number = true})
  63. configvar_check_csnippets("SIZEOF_LONG_DOUBLE", [[printf("%d", sizeof(long double));]], {tryrun = true, output = true, number = true})
  64. configvar_check_csnippets("SIZEOF_SIZE_T", [[printf("%d", sizeof(size_t));]], {tryrun = true, output = true, number = true})
  65. if not is_plat("windows") then
  66. set_configvar("HAVE_AS_X86_PCREL", 1)
  67. end
  68. if is_plat("macosx") then
  69. set_configvar("SYMBOL_UNDERSCORE", 1)
  70. end
  71. if is_plat("linux") then
  72. set_configvar("HAVE_HIDDEN_VISIBILITY_ATTRIBUTE", 1)
  73. set_configvar("EH_FRAME_FLAGS", "a")
  74. end
  75. if is_plat("macosx") and is_arch("arm64") then
  76. set_configvar("FFI_EXEC_TRAMPOLINE_TABLE", 1)
  77. else
  78. set_configvar("FFI_EXEC_TRAMPOLINE_TABLE", 0)
  79. end
  80. rule("asm.preprocess")
  81. set_extensions(".S")
  82. on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
  83. import("core.tool.toolchain")
  84. import("lib.detect.find_tool")
  85. local rootdir = path.join(target:autogendir(), "rules", "asm.preprocess")
  86. local filename = path.basename(sourcefile) .. ".asm"
  87. local sourcefile_or = path.absolute(sourcefile)
  88. local sourcefile_cx = target:autogenfile(sourcefile, {rootdir = rootdir, filename = filename})
  89. -- preprocessing
  90. local envs = toolchain.load("msvc"):runenvs()
  91. local cl = find_tool("cl", {envs = envs})
  92. batchcmds:execv(cl.program, {"/nologo", "/EP", "/Iinclude", "/I" .. path.directory(sourcefile_or), sourcefile_or}, {stdout = sourcefile_cx})
  93. local objectfile = target:objectfile(sourcefile_cx)
  94. table.insert(target:objectfiles(), objectfile)
  95. batchcmds:show_progress(opt.progress, "${color.build.object}compiling.%s %s", get_config("mode"), sourcefile_cx)
  96. batchcmds:compile(sourcefile_cx, objectfile)
  97. batchcmds:add_depfiles(sourcefile)
  98. batchcmds:set_depmtime(os.mtime(objectfile))
  99. batchcmds:set_depcache(target:dependfile(objectfile))
  100. end)
  101. rule_end()
  102. if is_plat("windows") then
  103. add_rules("asm.preprocess", {override = true})
  104. end
  105. target("ffi")
  106. set_kind("$(kind)")
  107. if is_plat("windows") and is_kind("shared") then
  108. add_defines("FFI_BUILDING_DLL")
  109. end
  110. set_configdir("include")
  111. add_configfiles("fficonfig.h.in")
  112. add_configfiles("include/ffi.h.in", {pattern = "@(.-)@"})
  113. add_includedirs("include")
  114. add_headerfiles("include/ffi.h")
  115. add_files("src/prep_cif.c", "src/types.c", "src/closures.c", "src/tramp.c")
  116. if not is_arch("arm") and not is_arch("arm64") then
  117. add_files("src/raw_api.c", "src/java_raw_api.c")
  118. end
  119. if is_plat("windows") and is_arch("x86") then
  120. add_asflags("/GZ")
  121. end
  122. if is_arch("i386", "x86") then
  123. add_files("src/x86/ffi.c")
  124. add_files(is_plat("windows") and "src/x86/sysv_intel.S" or "src/x86/sysv.S")
  125. add_includedirs("src/x86")
  126. add_headerfiles("src/x86/ffitarget.h")
  127. elseif is_arch("x86_64") then
  128. add_files("src/x86/ffi64.c", "src/x86/unix64.S", "src/x86/ffiw64.c", "src/x86/win64.S")
  129. add_includedirs("src/x86")
  130. add_headerfiles("src/x86/ffitarget.h")
  131. elseif is_arch("x64") then
  132. add_files("src/x86/ffi64.c", "src/x86/ffiw64.c", "src/x86/win64_intel.S")
  133. add_includedirs("src/x86")
  134. add_headerfiles("src/x86/ffitarget.h")
  135. elseif is_arch("arm") then
  136. add_files("src/arm/ffi.c", "src/arm/sysv.S")
  137. add_includedirs("src/arm")
  138. add_headerfiles("src/arm/ffitarget.h")
  139. elseif is_arch("arm64") then
  140. add_files("src/aarch64/ffi.c", "src/aarch64/sysv.S")
  141. add_includedirs("src/aarch64")
  142. add_headerfiles("src/aarch64/ffitarget.h")
  143. end
  144. before_build(function (target)
  145. io.replace("include/ffi.h", "!defined FFI_BUILDING", target:is_static() and "0" or "1", {plain = true})
  146. end)