Browse Source

cimgui: add package (#2477)

* cimgui: add package

* fix luajit

* disable plat

* use submodule

* support backend
star9029 2 years ago
parent
commit
861c666c1d
2 changed files with 215 additions and 0 deletions
  1. 94 0
      packages/c/cimgui/port/xmake.lua
  2. 121 0
      packages/c/cimgui/xmake.lua

+ 94 - 0
packages/c/cimgui/port/xmake.lua

@@ -0,0 +1,94 @@
+add_rules("mode.debug", "mode.release")
+set_languages("cxx11")
+
+option("glfw",             {showmenu = true,  default = false})
+option("opengl2",          {showmenu = true,  default = false})
+option("opengl3",          {showmenu = true,  default = false})
+option("sdl2",             {showmenu = true,  default = false})
+option("vulkan",           {showmenu = true,  default = false})
+option("freetype",         {showmenu = true,  default = false})
+option("wchar32",          {showmenu = true,  default = false})
+
+if has_config("glfw") then
+    add_requires("glfw")
+end
+
+if has_config("sdl2") then
+    add_requires("libsdl")
+end
+
+if has_config("vulkan") then
+    add_requires("vulkansdk")
+end
+
+if has_config("freetype") then
+    add_requires("freetype")
+end
+
+target("cimgui")
+    set_kind("$(kind)")
+    add_files("cimgui.cpp", "imgui/*.cpp")
+    add_includedirs("imgui")
+    add_headerfiles("cimgui.h", "generator/output/cimgui_impl.h")
+
+    add_defines("IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1")
+    if is_kind("static") then
+        add_defines("IMGUI_IMPL_API=extern \"C\" ")
+    else
+        add_defines("IMGUI_IMPL_API=extern \"C\" __declspec(dllexport)")
+    end
+
+    if has_config("glfw") then
+        add_files("imgui/backends/imgui_impl_glfw.cpp")
+        add_headerfiles("imgui/(backends/imgui_impl_glfw.h)")
+        add_packages("glfw")
+    end
+
+    if has_config("opengl2") then
+        add_files("imgui/backends/imgui_impl_opengl2.cpp")
+        add_headerfiles("imgui/(backends/imgui_impl_opengl2.h)")
+    end
+
+    if has_config("opengl3") then
+        add_files("imgui/backends/imgui_impl_opengl3.cpp")
+        add_headerfiles("imgui/(backends/imgui_impl_opengl3.h)")
+        add_headerfiles("imgui/(backends/imgui_impl_opengl3_loader.h)")
+    end
+
+    if has_config("sdl2") then
+        if os.exists("imgui/backends/imgui_impl_sdl2.cpp") then
+            add_files("imgui/backends/imgui_impl_sdl2.cpp")
+            add_headerfiles("imgui/(backends/imgui_impl_sdl2.h)")
+        else
+            add_files("imgui/backends/imgui_impl_sdl.cpp")
+            add_headerfiles("imgui/(backends/imgui_impl_sdl.h)")
+        end
+        add_packages("libsdl")
+    end
+
+    if has_config("vulkan") then
+        add_files("imgui/backends/imgui_impl_vulkan.cpp")
+        add_headerfiles("imgui/(backends/imgui_impl_vulkan.h)")
+        add_packages("vulkansdk")
+    end
+
+    if has_config("freetype") then
+        add_files("imgui/misc/freetype/imgui_freetype.cpp")
+        add_headerfiles("imgui/misc/freetype/imgui_freetype.h")
+        add_packages("freetype")
+        add_defines("IMGUI_ENABLE_FREETYPE")
+    end
+
+    if has_config("wchar32") then
+        add_defines("IMGUI_USE_WCHAR32")
+    end
+
+    after_install(function (target)
+        local config_file = path.join(target:installdir(), "include/imconfig.h")
+        if has_config("wchar32") then
+            io.gsub(config_file, "//#define IMGUI_USE_WCHAR32", "#define IMGUI_USE_WCHAR32")
+        end
+        if has_config("freetype") then
+            io.gsub(config_file, "//#define IMGUI_ENABLE_FREETYPE", "#define IMGUI_ENABLE_FREETYPE")
+        end
+    end)

+ 121 - 0
packages/c/cimgui/xmake.lua

@@ -0,0 +1,121 @@
+package("cimgui")
+    set_homepage("https://github.com/cimgui/cimgui")
+    set_description("c-api for imgui (https://github.com/ocornut/imgui) Look at: https://github.com/cimgui for other widgets")
+    set_license("MIT")
+
+    add_urls("https://github.com/cimgui/cimgui.git")
+    add_versions("2023.08.02", "a21e28e74027796d983f8c8d4a639a4e304251f2")
+
+    add_configs("imgui", {description = "imgui version", default = "v1.89", type = "string"})
+    add_configs("target", {description = "options as words in one string: internal for imgui_internal generation, freetype for freetype generation, comments for comments generation, nochar to skip char* function version, noimstrv to skip imstrv", default = "internal noimstrv", type = "string"})
+
+    add_configs("glfw",             {description = "Enable the glfw backend", default = false, type = "boolean"})
+    add_configs("opengl2",          {description = "Enable the opengl2 backend", default = false, type = "boolean"})
+    add_configs("opengl3",          {description = "Enable the opengl3 backend", default = false, type = "boolean"})
+    add_configs("sdl2",             {description = "Enable the sdl2 backend", default = false, type = "boolean"})
+    add_configs("vulkan",           {description = "Enable the vulkan backend", default = false, type = "boolean"})
+    add_configs("freetype",         {description = "Use FreeType to build and rasterize the font atlas", default = false, type = "boolean"})
+    add_configs("wchar32",          {description = "Use 32-bit for ImWchar (default is 16-bit)", default = false, type = "boolean"})
+
+    if is_plat("windows") then
+        add_syslinks("imm32")
+    end
+
+    add_defines("IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1")
+
+    add_deps("luajit")
+
+    on_load(function (package)
+        if package:config("sdl2") then
+            package:add("deps", "libsdl")
+            package:add("defines", "CIMGUI_USE_SDL2")
+        end
+        if package:config("opengl2") then
+            package:add("defines", "CIMGUI_USE_OPENGL2")
+        end
+        if package:config("opengl3") then
+            package:add("defines", "CIMGUI_USE_OPENGL3")
+        end
+        if package:config("glfw") then
+            package:add("deps", "glfw")
+            package:add("defines", "CIMGUI_USE_GLFW")
+        end
+        if package:config("vulkan") then
+            package:add("deps", "vulkansdk")
+        end
+        if package:config("freetype") then
+            package:add("deps", "freetype")
+            package:add("defines", "CIMGUI_FREETYPE=1")
+        end
+    end)
+
+    on_install("windows|x64", "windows|x86", "linux", "macosx", function (package)
+        os.vrun("git -c core.fsmonitor=false submodule foreach --recursive git checkout " .. package:config("imgui"))
+
+        local envs = {}
+        local args = {"generator.lua"}
+
+        if package:is_plat("windows") then
+            import("package.tools.msbuild")
+
+            table.insert(args, "cl")
+            table.join2(envs, msbuild.buildenvs(package))
+        else
+            if package:has_tool("cc", "gcc", "gxx") then
+                table.insert(args, "gcc")
+            elseif package:has_tool("cc", "clang", "clangxx") then
+                table.insert(args, "clang")
+            else
+                raise("Compiler not found")
+            end
+        end
+
+        table.insert(args, package:config("target"))
+
+        table.join2(args, table.wrap(package:config("cflags")))
+        table.join2(args, table.wrap(package:config("cxflags")))
+        for _, define in ipairs(table.wrap(package:config("defines"))) do
+            table.insert(args, "-D" .. define)
+        end
+
+        local configs = {
+            glfw     = package:config("glfw"),
+            opengl2  = package:config("opengl2"),
+            opengl3  = package:config("opengl3"),
+            sdl2     = package:config("sdl2"),
+            vulkan   = package:config("vulkan"),
+            freetype = package:config("freetype"),
+            wchar32  = package:config("wchar32")
+        }
+
+        if configs.sdl2 then
+            table.insert(args, "sdl")
+        end
+        if configs.glfw then
+            table.insert(args, "glfw")
+        end
+        if configs.vulkan then
+            table.insert(args, "vulkan")
+        end
+        if configs.opengl2 then
+            table.insert(args, "opengl2")
+        end
+        if configs.opengl3 then
+            table.insert(args, "opengl3")
+        end
+
+        os.vrunv("luajit", args, {envs = envs, curdir = "generator"})
+
+        os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
+        import("package.tools.xmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:check_csnippets({test = [[
+            #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
+            #include <cimgui.h>
+            void test() {
+                igCreateContext(NULL);
+            }
+        ]]}, {configs = {languages = "c99"}}))
+    end)