xmake.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package("cjson")
  2. set_homepage("https://github.com/DaveGamble/cJSON")
  3. set_description("Ultralightweight JSON parser in ANSI C.")
  4. set_license("MIT")
  5. set_urls("https://github.com/DaveGamble/cJSON/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/DaveGamble/cJSON.git")
  7. add_versions("v1.7.19", "7fa616e3046edfa7a28a32d5f9eacfd23f92900fe1f8ccd988c1662f30454562")
  8. add_versions("v1.7.18", "3aa806844a03442c00769b83e99970be70fbef03735ff898f4811dd03b9f5ee5")
  9. add_versions("v1.7.15", "5308fd4bd90cef7aa060558514de6a1a4a0819974a26e6ed13973c5f624c24b2")
  10. add_deps("cmake")
  11. on_install(function (package)
  12. if package:is_plat("windows") then
  13. if package:config("shared") then
  14. package:add("defines", "CJSON_IMPORT_SYMBOLS")
  15. else
  16. package:add("defines", "CJSON_HIDE_SYMBOLS")
  17. end
  18. end
  19. io.replace("CMakeLists.txt", "-Werror", "", {plain = true})
  20. local configs = {"-DENABLE_CJSON_TEST=OFF", "-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"}
  21. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  22. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  23. import("package.tools.cmake").install(package, configs)
  24. if package:is_plat("windows") and package:is_debug() then
  25. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  26. os.trycp(path.join(package:buildir(), "cjson.pdb"), dir)
  27. end
  28. end)
  29. on_test(function (package)
  30. assert(package:has_cfuncs("cJSON_malloc", {includes = "cjson/cJSON.h"}))
  31. end)