xmake.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package("vc-ltl5")
  2. set_homepage("https://github.com/Chuyu-Team/VC-LTL5")
  3. set_description("Shared to msvcrt.dll or ucrtbase.dll and optimize the C/C++ application file size")
  4. set_license("EPL-2.0")
  5. add_urls("https://github.com/Chuyu-Team/VC-LTL5/releases/download/v$(version)/VC-LTL-$(version)-Binary.7z")
  6. add_versions("5.1.1", "71eb81ad7d5270cb2a247d6b1c5c01b8efb8f2c869d2e5222be8aafab2fc07de")
  7. add_versions("5.0.6", "e406f829f75d59c34ee1e34cb6e994eb7db0810123ae7196499f26df88bc0a6f")
  8. add_versions("5.0.7", "08555aca30b2f77a484534be0799cfed05bfdeb1d1e461d91576264d7123e687")
  9. add_versions("5.0.9", "71a3099978ff3dc83fe8e2ebddf104e2f916d13cd10fb01fe02317ebc7fb02d9")
  10. local default_min_version = "6.0.6000.0"
  11. if is_plat("windows") then
  12. if is_arch("x64", "x86") then
  13. default_min_version = "6.0.6000.0"
  14. elseif is_arch("arm") then
  15. default_min_version = "6.2.9200.0"
  16. elseif is_arch("arm64") then
  17. default_min_version = "10.0.10240.0"
  18. else
  19. raise("Unsupported architecture!")
  20. end
  21. end
  22. add_configs("min_version", {description = "Windows Target Platform Min Version", default = default_min_version, type = "string"})
  23. add_configs("subsystem", {description = "Windows xp subsystem", default = "windows", type = "string", values = {"console", "windows"}})
  24. add_configs("clean_import", {description = "Do not use ucrt apiset, such as api-ms-win-crt-time-l1-1-0.dll (for geeks)", default = false, type = "boolean"})
  25. add_configs("openmp", {description = "Use openmp library", default = false, type = "boolean", readonly = true})
  26. add_configs("shared", {description = "Use vs_runtime", default = true, type = "boolean", readonly = true})
  27. add_configs("debug", {description = "Use vs_runtime", default = true, type = "boolean", readonly = true})
  28. on_load("windows", function (package)
  29. import("core.tool.toolchain")
  30. -- check vs version
  31. local vs = toolchain.load("msvc"):config("vs")
  32. if vs and tonumber(vs) < 2015 then
  33. cprint("${color.warning}vc-ltl5 only supports vc14.0 or later versions")
  34. end
  35. -- is xp?
  36. if package:config("min_version"):startswith("5") then
  37. if package:config("vs_runtime"):startswith("MD") then
  38. package:add("cxflags", "/Zc:threadSafeInit-")
  39. end
  40. local arch
  41. if package:is_arch("x86") then
  42. arch = "5.01"
  43. elseif package:is_arch("x64") then
  44. arch = "5.02"
  45. end
  46. if arch then
  47. local flag = format("/subsystem:%s,%s", package:config("subsystem"), arch)
  48. package:add("ldflags", flag)
  49. end
  50. end
  51. end)
  52. on_install("windows", function (package)
  53. import("core.base.semver")
  54. -- Automatically adapt version
  55. local min_version = package:config("min_version")
  56. local semver_min_version = semver.match(min_version)
  57. if semver_min_version then
  58. if semver_min_version:ge("10.0.19041") then
  59. min_version = "10.0.19041.0"
  60. elseif semver_min_version:ge("10.0.10240") then
  61. min_version = "10.0.10240.0"
  62. elseif semver_min_version:ge("6.2.9200") then
  63. min_version = "6.2.9200.0"
  64. elseif semver_min_version:ge("6.0.6000") then
  65. min_version = "6.0.6000.0"
  66. else
  67. min_version = "5.1.2600.0"
  68. end
  69. else
  70. cprint("${color.warning}Invalid min_version, use default min_version")
  71. min_version = default_min_version
  72. end
  73. local platform
  74. if package:is_arch("x86") then
  75. platform = "Win32"
  76. elseif package:is_arch("x64") then
  77. platform = "x64"
  78. elseif package:is_arch("arm") then
  79. platform = "ARM"
  80. elseif package:is_arch("arm64") then
  81. platform = "ARM64"
  82. else
  83. raise("Unsupported architecture!")
  84. end
  85. local bindir = "TargetPlatform/" .. min_version
  86. os.cp("TargetPlatform/header", package:installdir("include"), {rootdir = "TargetPlatform"})
  87. os.cp(bindir .. "/header", package:installdir("include"), {rootdir = "TargetPlatform"})
  88. package:add("includedirs", path.join("include", "header"))
  89. package:add("includedirs", path.join("include", min_version, "header"))
  90. local libdir = path.join(bindir, "lib", platform)
  91. assert(os.isdir(libdir), "The architecture is not supported in this version")
  92. os.cp(libdir .. "/*.*", package:installdir("lib"))
  93. -- We do not need links, but xmake needs at least one links to add linkdirs
  94. package:add("links", "vc-ltl5")
  95. io.writefile("lib.cpp", "")
  96. io.writefile("xmake.lua", [[
  97. target("vc-ltl5")
  98. set_kind("static")
  99. add_files("lib.cpp")
  100. ]])
  101. import("package.tools.xmake").install(package)
  102. local clean_import_dir = libdir .. "/CleanImport"
  103. if package:config("clean_import") and os.isdir(clean_import_dir) then
  104. os.cp(clean_import_dir, package:installdir("lib"))
  105. package:add("linkdirs", "lib/CleanImport")
  106. package:add("linkdirs", "lib")
  107. -- We need at least one links in CleanImport dir
  108. package:add("links", "vc-ltl5-CleanImport")
  109. local old = os.cd(package:installdir("lib"))
  110. os.cp("vc-ltl5.lib", "CleanImport")
  111. os.mv("CleanImport/vc-ltl5.lib", "CleanImport/vc-ltl5-CleanImport.lib")
  112. os.cd(old)
  113. end
  114. end)
  115. on_test(function (package)
  116. assert(package:check_cxxsnippets({test = [[
  117. #include <iostream>
  118. extern "C" extern int __LTL_vcruntime_module_type;
  119. void test() {
  120. std::cout << "Hello World! LTL_vcruntime=" << __LTL_vcruntime_module_type;
  121. }
  122. ]]}))
  123. end)