xmake.lua 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package("proj")
  2. set_homepage("https://proj.org/index.html")
  3. set_description("PROJ is a generic coordinate transformation software that transforms geospatial coordinates from one coordinate reference system (CRS) to another.")
  4. set_license("MIT")
  5. add_urls("https://download.osgeo.org/proj/proj-$(version).tar.gz")
  6. add_versions("9.0.1", "737eaacbe7906d0d6ff43f0d9ebedc5c734cccc9e6b8d7beefdec3ab22d9a6a3")
  7. add_versions("8.2.1", "76ed3d0c3a348a6693dfae535e5658bbfd47f71cb7ff7eb96d9f12f7e068b1cf")
  8. add_configs("apps", {description = "Build PROJ applications.", default = false, type = "boolean"})
  9. add_configs("tiff", {description = "Enable TIFF support.", default = false, type = "boolean"})
  10. add_configs("curl", {description = "Enable Curl support.", default = false, type = "boolean"})
  11. add_deps("cmake", "sqlite3")
  12. add_deps("nlohmann_json", {configs = {cmake = true}})
  13. if is_plat("windows") then
  14. add_syslinks("shell32", "ole32")
  15. elseif is_plat("linux") then
  16. add_syslinks("pthread")
  17. end
  18. on_load("windows", "macosx", "linux", function (package)
  19. if package:config("tiff") then
  20. package:add("deps", "libtiff")
  21. end
  22. if package:config("curl") then
  23. package:add("deps", "libcurl")
  24. if package:is_plat("linux") then
  25. package:add("deps", "openssl")
  26. end
  27. end
  28. if package:config("apps") then
  29. package:addenv("PATH", "bin")
  30. end
  31. end)
  32. on_install("windows", "macosx", "linux", function (package)
  33. -- windows@arm64 cann't generate proj.db
  34. if package:is_plat("windows") and package:is_arch("arm64") then
  35. io.replace("CMakeLists.txt", "add_subdirectory(data)", "", {plain = true})
  36. end
  37. if package:config("curl") and package:is_plat("linux") then
  38. io.replace("src/lib_proj.cmake", "${CURL_LIBRARIES}", "CURL::libcurl ssl crypto", {plain = true})
  39. else
  40. io.replace("src/lib_proj.cmake", "${CURL_LIBRARIES}", "CURL::libcurl", {plain = true})
  41. end
  42. if package:is_plat("windows") and not package:config("shared") then
  43. io.replace("src/proj.h", "#ifndef PROJ_DLL", "#define PROJ_DLL\n#ifndef PROJ_DLL", {plain = true})
  44. end
  45. local configs = {"-DNLOHMANN_JSON_ORIGIN=external", "-DBUILD_TESTING=OFF"}
  46. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  47. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  48. table.insert(configs, "-DBUILD_APPS=" .. (package:config("apps") and "ON" or "OFF"))
  49. table.insert(configs, "-DENABLE_TIFF=" .. (package:config("tiff") and "ON" or "OFF"))
  50. table.insert(configs, "-DENABLE_CURL=" .. (package:config("curl") and "ON" or "OFF"))
  51. table.insert(configs, "-DBUILD_PROJSYNC=" .. (package:config("curl") and "ON" or "OFF"))
  52. if package:config("curl") and package:is_plat("linux") then
  53. import("package.tools.cmake").install(package, configs, {packagedeps = {"openssl"}})
  54. elseif package:config("curl") and package:is_plat("macosx") then
  55. local exflags = {"-framework", "CoreFoundation", "-framework", "Security", "-framework", "SystemConfiguration"}
  56. import("package.tools.cmake").install(package, configs, {shflags = exflags, ldflags = exflags})
  57. else
  58. import("package.tools.cmake").install(package, configs)
  59. end
  60. end)
  61. on_test(function (package)
  62. assert(package:has_cfuncs("proj_context_create", {includes = "proj.h"}))
  63. end)