Kaynağa Gözat

improve libigl+imgui workflow (#554)

* improve libigl+imgui workflow

* add missing definition
Hoildkv 4 yıl önce
ebeveyn
işleme
8efc8b1b0a
2 değiştirilmiş dosya ile 51 ekleme ve 9 silme
  1. 34 6
      packages/i/imgui/xmake.lua
  2. 17 3
      packages/l/libigl/xmake.lua

+ 34 - 6
packages/i/imgui/xmake.lua

@@ -14,18 +14,46 @@ package("imgui")
     add_versions("v1.75", "1023227fae4cf9c8032f56afcaea8902e9bfaad6d9094d6e48fb8f3903c7b866")
     
     add_configs("user_config", {description = "Use user config (disables test!)", default = nil, type = "string"})
+    add_configs("glfw_opengl3", {description = "Use glfw+opengl3 as backend", default = false, type = "boolean"})
+
+    add_includedirs("include", "include/imgui")
 
     if is_plat("windows", "mingw") then
         add_syslinks("Imm32")
     end
 
+    on_load("macosx", "linux", "windows", "mingw", "android", "iphoneos", function (package)
+        if package:config("glfw_opengl3") then
+            package:add("deps", "glad")
+            package:add("deps", "glfw")
+            package:add("defines", "IMGUI_IMPL_OPENGL_LOADER_GLAD")
+        end
+    end)
+
     on_install("macosx", "linux", "windows", "mingw", "android", "iphoneos", function (package)
-        local xmake_lua = [[
-            target("imgui")
-                set_kind("static")
-                add_files("*.cpp")
-                add_headerfiles("imgui.h", "imconfig.h")
-        ]]
+        local xmake_lua
+        if package:config("glfw_opengl3") then
+            xmake_lua = [[
+                add_rules("mode.debug", "mode.release")
+                add_requires("glfw", "glad")
+                target("imgui")
+                    set_kind("static")
+                    add_files("*.cpp", "backends/imgui_impl_glfw.cpp", "backends/imgui_impl_opengl3.cpp")
+                    add_defines("IMGUI_IMPL_OPENGL_LOADER_GLAD")
+                    add_packages("glfw", "glad")
+                    add_includedirs(".")
+                    add_headerfiles("*.h", {prefixdir = "imgui"})
+                    add_headerfiles("backends/imgui_impl_glfw.h", "backends/imgui_impl_opengl3.h")
+            ]]
+        else
+            xmake_lua = [[
+                add_rules("mode.debug", "mode.release")
+                target("imgui")
+                    set_kind("static")
+                    add_files("*.cpp")
+                    add_headerfiles("imgui.h", "imconfig.h")
+            ]]
+        end
         
         local user_config = package:config("user_config")
         if user_config ~= nil then

+ 17 - 3
packages/l/libigl/xmake.lua

@@ -8,22 +8,36 @@ package("libigl")
     add_versions("v2.2.0", "b336e548d718536956e2d6958a0624bc76d50be99039454072ecdc5cf1b2ede5")
     add_versions("v2.3.0", "9d6de3bdb9c1cfc61a0a0616fd96d14ef8465995600328c196fa672ee4579b70")
 
+    add_resources("2.x", "libigl_imgui", "https://github.com/libigl/libigl-imgui.git", "7e1053e750b0f4c129b046f4e455243cb7f804f3")
+
     add_configs("header_only", {description = "Use header only version.", default = true, type = "boolean"})
-    add_configs("use_cgal", {description = "Use CGAL library.", default = false, type = "boolean"})
+    add_configs("cgal", {description = "Use CGAL library.", default = false, type = "boolean"})
+    add_configs("imgui", {description = "Use imgui with libigl.", default = false, type = "boolean"})
+
+    if is_plat("windows") then
+        add_syslinks("comdlg32")
+    end
 
     add_deps("cmake", "eigen")
     on_load("macosx", "linux", "windows", function (package)
         if not package:config("header_only") then
             raise("Non-header-only version is not supported yet!")
         end
-        if package:config("use_cgal") then
+        if package:config("cgal") then
             package:add("deps", "cgal")
         end
+        if package:config("imgui") then
+            package:add("deps", "imgui", {configs = {glfw_opengl3 = true}})
+        end
     end)
 
     on_install("macosx", "linux", "windows", function (package)
+        if package:config("imgui") then
+            local igl_imgui_dir = package:resourcefile("libigl_imgui")
+            os.cp(path.join(igl_imgui_dir, "imgui_fonts_droid_sans.h"), package:installdir("include"))
+        end
         if package:config("header_only") then
-            os.mv("include", package:installdir())
+            os.mv("include/igl", package:installdir("include"))
             return
         end
         local configs = {"-DLIBIGL_BUILD_TESTS=OFF", "-DLIBIGL_BUILD_TUTORIALS=OFF", "-DLIBIGL_SKIP_DOWNLOAD=ON"}