xmake.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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/$(version)", {version = function (version)
  6. if version:ge("5.2.1") then
  7. return "v" .. version .. "/VC-LTL-Binary.7z"
  8. else
  9. return "v" .. version .. "/VC-LTL-" .. version .. "-Binary.7z"
  10. end
  11. end})
  12. add_versions("5.2.2", "04aa46a7d2af655bcf42c4937504525eb7e66a75910ed42fd25a1cdcec587df0")
  13. add_versions("5.2.1", "0b0b17b7a4ed993701208b2eaeba91f3acf2f1b5402430b52ac7bfbca2519464")
  14. add_versions("5.1.1", "71eb81ad7d5270cb2a247d6b1c5c01b8efb8f2c869d2e5222be8aafab2fc07de")
  15. add_versions("5.0.6", "e406f829f75d59c34ee1e34cb6e994eb7db0810123ae7196499f26df88bc0a6f")
  16. add_versions("5.0.7", "08555aca30b2f77a484534be0799cfed05bfdeb1d1e461d91576264d7123e687")
  17. add_versions("5.0.9", "71a3099978ff3dc83fe8e2ebddf104e2f916d13cd10fb01fe02317ebc7fb02d9")
  18. local default_min_version = "6.0.6000.0"
  19. if is_plat("windows") then
  20. if is_arch("x64", "x86") then
  21. default_min_version = "6.0.6000.0"
  22. elseif is_arch("arm") then
  23. default_min_version = "6.2.9200.0"
  24. elseif is_arch("arm64") then
  25. default_min_version = "10.0.10240.0"
  26. else
  27. raise("Unsupported architecture!")
  28. end
  29. end
  30. add_configs("min_version", {description = "Windows Target Platform Min Version", default = default_min_version, type = "string"})
  31. add_configs("subsystem", {description = "Windows xp subsystem", default = "windows", type = "string", values = {"console", "windows"}})
  32. add_configs("clean_import", {description = "Do not use ucrt apiset, such as api-ms-win-crt-time-l1-1-0.dll (for geeks) (Duplicated after vc-ltl 5.1 version)", default = false, type = "boolean"})
  33. add_configs("openmp", {description = "Use openmp library", default = false, type = "boolean", readonly = true})
  34. add_configs("shared", {description = "Use runtimes configs", default = true, type = "boolean", readonly = true})
  35. add_configs("debug", {description = "Use runtimes configs", default = false, type = "boolean", readonly = true})
  36. set_policy("package.precompiled", false)
  37. on_load(function (package)
  38. -- check vs version
  39. local vs = package:toolchain("msvc"):config("vs")
  40. if vs and tonumber(vs) < 2015 then
  41. wprint("vc-ltl5 only supports vc14.0 or later versions")
  42. end
  43. -- is xp?
  44. local version = package:version()
  45. if package:config("min_version"):startswith("5") then
  46. if version:ge("5.1.0") then
  47. package:add("deps", "yy-thunks")
  48. wprint([[package(vc-ltl5 >=5.1) require yy-thunks, you need to use `add_rules("yy-thunks@xp")` for windows xp target]])
  49. end
  50. if package:has_runtime("MD") then
  51. package:add("cxflags", "/Zc:threadSafeInit-")
  52. end
  53. local arch
  54. if package:is_arch("x86") then
  55. arch = "5.01"
  56. elseif package:is_arch("x64") then
  57. arch = "5.02"
  58. end
  59. if arch then
  60. local flag = format("/subsystem:%s,%s", package:config("subsystem"), arch)
  61. package:add("ldflags", flag)
  62. end
  63. if version:ge("5.2.1") and package:has_runtime("MD", "MDd") and package:is_arch("x64", "x86") then
  64. local url = format("https://github.com/Chuyu-Team/VC-LTL5/releases/download/v%s/VC-LTL.Redist.Dlls.zip", package:version_str())
  65. package:add("resources", package:version_str(), "dlls", url, "99d99d7df5ce1643c0e8f0aadb457ab177199db8255d7ae5e68ff9c16492cfcd")
  66. end
  67. end
  68. end)
  69. on_install("windows", function (package)
  70. import("core.base.semver")
  71. -- Automatically adapt version
  72. local min_version = package:config("min_version")
  73. local semver_min_version = semver.match(min_version)
  74. if semver_min_version then
  75. if semver_min_version:ge("10.0.19041") then
  76. min_version = "10.0.19041.0"
  77. elseif semver_min_version:ge("10.0.10240") then
  78. min_version = "10.0.10240.0"
  79. elseif semver_min_version:ge("6.2.9200") then
  80. min_version = "6.2.9200.0"
  81. elseif semver_min_version:ge("6.0.6000") then
  82. min_version = "6.0.6000.0"
  83. else
  84. if package:is_arch("x86") then
  85. min_version = "5.1.2600.0"
  86. elseif package:is_arch("x64") then
  87. min_version = "5.2.3790.0"
  88. end
  89. end
  90. else
  91. wprint("Invalid min_version, use default min_version")
  92. min_version = default_min_version
  93. end
  94. local platform
  95. if package:is_arch("x86") then
  96. platform = "Win32"
  97. elseif package:is_arch("x64") then
  98. platform = "x64"
  99. elseif package:is_arch("arm") then
  100. platform = "ARM"
  101. elseif package:is_arch("arm64") then
  102. platform = "ARM64"
  103. else
  104. raise("Unsupported architecture!")
  105. end
  106. local bindir = "TargetPlatform/" .. min_version
  107. os.cp("TargetPlatform/header", package:installdir("include"), {rootdir = "TargetPlatform"})
  108. os.cp(bindir .. "/header", package:installdir("include"), {rootdir = "TargetPlatform"})
  109. package:add("includedirs", path.join("include", "header"))
  110. package:add("includedirs", path.join("include", min_version, "header"))
  111. local libdir = path.join(bindir, "lib", platform)
  112. assert(os.isdir(libdir), "The architecture is not supported in this version")
  113. os.cp(libdir .. "/*.*", package:installdir("lib"))
  114. -- We do not need links, but xmake needs at least one links to add linkdirs
  115. package:add("links", "vc-ltl5")
  116. io.writefile("lib.cpp", "")
  117. io.writefile("xmake.lua", [[
  118. target("vc-ltl5")
  119. set_kind("static")
  120. add_files("lib.cpp")
  121. ]])
  122. import("package.tools.xmake").install(package)
  123. local dlls = package:resourcedir("dlls")
  124. if dlls then
  125. os.vcp(path.join(dlls, "Dlls", package:arch()), package:installdir("bin"))
  126. end
  127. -- deprecated after vc-ltl 5.1 version
  128. local clean_import_dir = libdir .. "/CleanImport"
  129. if package:config("clean_import") and os.isdir(clean_import_dir) then
  130. os.cp(clean_import_dir, package:installdir("lib"))
  131. package:add("linkdirs", "lib/CleanImport")
  132. package:add("linkdirs", "lib")
  133. -- We need at least one links in CleanImport dir
  134. package:add("links", "vc-ltl5-CleanImport")
  135. local old = os.cd(package:installdir("lib"))
  136. os.cp("vc-ltl5.lib", "CleanImport")
  137. os.mv("CleanImport/vc-ltl5.lib", "CleanImport/vc-ltl5-CleanImport.lib")
  138. os.cd(old)
  139. end
  140. end)
  141. on_test(function (package)
  142. assert(package:check_cxxsnippets({test = [[
  143. #include <iostream>
  144. extern "C" extern int __LTL_vcruntime_module_type;
  145. void test() {
  146. std::cout << "Hello World! LTL_vcruntime=" << __LTL_vcruntime_module_type;
  147. }
  148. ]]}))
  149. end)