xmake.lua 5.8 KB

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