Browse Source

add drogon

xq114 4 years ago
parent
commit
5a5cda6b79

+ 13 - 0
packages/d/drogon/patches/1.4.1/resolv.patch

@@ -0,0 +1,13 @@
+diff --git a/drogon_ctl/CMakeLists.txt b/drogon_ctl/CMakeLists.txt
+--- a/drogon_ctl/CMakeLists.txt
++++ b/drogon_ctl/CMakeLists.txt
+@@ -39,6 +39,9 @@
+ if(WIN32)
+   target_link_libraries(drogon_ctl PRIVATE ws2_32 Rpcrt4)
+ endif(WIN32)
++if(APPLE)
++  target_link_libraries(drogon_ctl PRIVATE resolv)
++endif()
+ message(STATUS "bin:" ${INSTALL_BIN_DIR})
+ install(TARGETS drogon_ctl RUNTIME DESTINATION ${INSTALL_BIN_DIR})
+ if(WIN32)

+ 16 - 0
packages/d/drogon/patches/1.4.1/trantor.patch

@@ -0,0 +1,16 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 1efecf8..198f429 100755
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -87,9 +85,9 @@ if(WIN32)
+     PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third_party/mman-win32>)
+ endif(WIN32)
+ 
+-add_subdirectory(trantor)
++find_package(Trantor CONFIG REQUIRED)
+ 
+-target_link_libraries(${PROJECT_NAME} PUBLIC trantor)
++target_link_libraries(${PROJECT_NAME} PUBLIC Trantor::Trantor)
+ 
+ if(NOT WIN32)
+   if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD")

+ 41 - 0
packages/d/drogon/xmake.lua

@@ -0,0 +1,41 @@
+package("drogon")
+
+    set_homepage("https://github.com/an-tao/drogon/")
+    set_description("Drogon: A C++14/17 based HTTP web application framework running on Linux/macOS/Unix/Windows")
+    set_license("MIT")
+
+    add_urls("https://github.com/an-tao/drogon/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/an-tao/drogon.git")
+    add_versions("v1.4.1", "ad794d7744b600240178348c15e216c919fe7a2bc196cf1239f129aee2af19c7")
+
+    add_patches("1.4.1", path.join(os.scriptdir(), "patches", "1.4.1", "trantor.patch"), "7f9034a27bb63de8dedb80dd9f246ea7aa7724c87f2c0d0054f4b6097ea2a862")
+    add_patches("1.4.1", path.join(os.scriptdir(), "patches", "1.4.1", "resolv.patch"), "84bff60e9ad632f585fadc2384eccb193aec95ccc14ec9c18196cd40a527538c")
+
+    add_deps("cmake")
+    add_deps("trantor", "jsoncpp", "brotli", "zlib")
+    add_deps("c-ares", "sqlite3", "openssl", {optional = true})
+    add_deps("postgresql", {optional = true, system = true})
+    if is_plat("windows") then
+        add_syslinks("ws2_32", "rpcrt4", "crypt32", "advapi32")
+    else
+        add_deps("libuuid")
+        if is_plat("linux") then
+            add_syslinks("pthread")
+        end
+    end
+
+    on_install("windows", "macosx", "linux", function (package)
+        io.replace("cmake/templates/config.h.in", "\"@COMPILATION_FLAGS@@DROGON_CXX_STANDARD@\"", "R\"(@COMPILATION_FLAGS@@DROGON_CXX_STANDARD@)\"", {plain = true})
+        io.replace("CMakeLists.txt", "else(BUILD_DROGON_SHARED)\n", "if(APPLE)\ntarget_link_libraries(${PROJECT_NAME} PUBLIC resolv)\nendif(APPLE)\nelse(BUILD_DROGON_SHARED)\n", {plain = true})
+        local configs = {"-DBUILD_EXAMPLES=OFF"}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_DROGON_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
+        if package:config("pic") ~= false then
+            table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
+        end
+        import("package.tools.cmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:has_cxxfuncs("drogon::getVersion()", {configs = {languages = "c++17"}, includes = "drogon/drogon.h"}))
+    end)

+ 69 - 0
packages/p/postgresql/xmake.lua

@@ -0,0 +1,69 @@
+package("postgresql")
+
+    set_homepage("https://www.postgresql.org/")
+    set_description("PostgreSQL Database Management System")
+
+    on_fetch(function (package, opt)
+        if opt.system then
+            import("lib.detect.find_path")
+            import("lib.detect.find_program")
+            import("lib.detect.find_library")
+
+            -- init search paths
+            local paths = {}
+            if package:is_plat("windows") then
+                local regs = winos.registry_keys("HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations\\postgresql-x64-*")
+                for _, reg in ipairs(regs) do
+                    table.insert(paths, winos.registry_query(reg .. ";Base Directory"))
+                end
+            elseif package:is_plat("macosx") then
+                for _, path in ipairs(os.dirs("/Library/PostgreSQL/*")) do
+                    table.insert(paths, path)
+                end
+            elseif package:is_plat("linux") then
+                for _, path in ipairs(os.dirs("/usr/lib/postgresql/*")) do
+                    table.insert(paths, path)
+                end
+            end
+
+            -- find programs
+            local binfile = find_program("postgres", {pathes = {"$(env PATH)"}})
+            if binfile then
+                local packagedir = path.directory(path.directory(binfile))
+                table.insert(paths, packagedir)
+                package:addenv("PATH", path.join(packagedir, "bin"))
+            end
+
+            local result = {links = {}, linkdirs = {}, includedirs = {}, libfiles = {}}
+            
+            -- find library
+            local libname = (package:is_plat("windows") and "libpq" or "pq")
+            local linkinfo = find_library(libname, paths, {suffixes = "lib"})
+            print(linkinfo)
+            if linkinfo then
+                table.insert(result.linkdirs, linkinfo.linkdir)
+                table.insert(result.links, libname)
+                if package:is_plat("windows") then
+                    table.insert(result.libfiles, path.join(linkinfo.linkdir, "libpq.lib"))
+                    table.insert(result.libfiles, path.join(linkinfo.linkdir, "libpq.dll"))
+                end
+            end
+
+            -- find headers
+            local path = find_path("libpq-fe.h", paths, {suffixes = "include"})
+            if path then
+                table.insert(result.includedirs, path)
+            end
+            path = find_path("postgres.h", paths, {suffixes = "include/server"})
+            if path then
+                table.insert(result.includedirs, path)
+            end
+
+            print(result)
+
+            -- ok?
+            if #result.includedirs > 0 and #result.linkdirs > 0 then
+                return result
+            end
+        end
+    end)