From fc677cb84928926d502b23044a05e864bf169c8e Mon Sep 17 00:00:00 2001 From: Micon Frink Date: Wed, 28 Oct 2020 05:44:57 +0000 Subject: [PATCH 1/6] adding flags to generator.lua --- generator/generator.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/generator/generator.lua b/generator/generator.lua index fbcd309..f277c36 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -8,6 +8,7 @@ local script_args = {...} local COMPILER = script_args[1] local INTERNAL_GENERATION = script_args[2]:match("internal") and true or false local FREETYPE_GENERATION = script_args[2]:match("freetype") and true or false +local CFLAGS = "" local CPRE,CTEST if COMPILER == "gcc" or COMPILER == "clang" then CPRE = COMPILER..[[ -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] @@ -44,7 +45,18 @@ print("INTERNAL_GENERATION",INTERNAL_GENERATION) print("FREETYPE_GENERATION",FREETYPE_GENERATION) --get implementations local implementations = {} -for i=3,#script_args do table.insert(implementations,script_args[i]) end +for i=3,#script_args do + if script_args[i]:match("^%-") then + local key, value = script_args[i]:match("^(.+)=(.+)$") + if key and value then + CFLAGS = CFLAGS .. " " .. key .. "=\"" .. value:gsub("\"", "\\\"") .. "\""; + else + CFLAGS = CFLAGS .. " " .. script_args[i] + end + else + table.insert(implementations,script_args[i]) + end +end -------------------------------------------------------------------------- --this table has the functions to be skipped in generation @@ -335,7 +347,6 @@ end print("IMGUI_VERSION",imgui_version) --get some defines---------------------------- gdefines = get_defines{"IMGUI_VERSION","FLT_MAX"} - --funtion for parsing imgui headers local function parseImGuiHeader(header,names) From be7bb9a72ed18d9ec29bfda78df99c9668b57005 Mon Sep 17 00:00:00 2001 From: Micon Frink Date: Wed, 28 Oct 2020 06:19:41 +0000 Subject: [PATCH 2/6] forgot to add the CFLAGS to to the actual calls. Also realized that we really should process the cl calls so fixed that too. --- generator/generator.lua | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/generator/generator.lua b/generator/generator.lua index f277c36..e68498f 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -10,11 +10,26 @@ local INTERNAL_GENERATION = script_args[2]:match("internal") and true or false local FREETYPE_GENERATION = script_args[2]:match("freetype") and true or false local CFLAGS = "" local CPRE,CTEST +--get implementations +local implementations = {} +for i=3,#script_args do + if script_args[i]:match("^[-/]") then + local key, value = script_args[i]:match("^(.+)=(.+)$") + if key and value then + CFLAGS = CFLAGS .. " " .. key .. "=\"" .. value:gsub("\"", "\\\"") .. "\""; + else + CFLAGS = CFLAGS .. " " .. script_args[i] + end + else + table.insert(implementations,script_args[i]) + end +end + if COMPILER == "gcc" or COMPILER == "clang" then - CPRE = COMPILER..[[ -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] + CPRE = COMPILER..[[ -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] .. CFLAGS CTEST = COMPILER.." --version" elseif COMPILER == "cl" then - CPRE = COMPILER..[[ /E /DIMGUI_DISABLE_OBSOLETE_FUNCTIONS /DIMGUI_API="" /DIMGUI_IMPL_API="" ]] + CPRE = COMPILER..[[ /E /DIMGUI_DISABLE_OBSOLETE_FUNCTIONS /DIMGUI_API="" /DIMGUI_IMPL_API="" ]] .. CFLAGS CTEST = COMPILER else print("Working without compiler ") @@ -43,21 +58,6 @@ assert(HAVE_COMPILER,"gcc, clang or cl needed to run script") print("HAVE_COMPILER",HAVE_COMPILER) print("INTERNAL_GENERATION",INTERNAL_GENERATION) print("FREETYPE_GENERATION",FREETYPE_GENERATION) ---get implementations -local implementations = {} -for i=3,#script_args do - if script_args[i]:match("^%-") then - local key, value = script_args[i]:match("^(.+)=(.+)$") - if key and value then - CFLAGS = CFLAGS .. " " .. key .. "=\"" .. value:gsub("\"", "\\\"") .. "\""; - else - CFLAGS = CFLAGS .. " " .. script_args[i] - end - else - table.insert(implementations,script_args[i]) - end -end - -------------------------------------------------------------------------- --this table has the functions to be skipped in generation -------------------------------------------------------------------------- @@ -136,7 +136,8 @@ local func_implementation = cpp2ffi.func_implementation -------------------functions for getting and setting defines local function get_defines(t) if COMPILER == "cl" then print"can't get defines with cl compiler"; return {} end - local pipe,err = io.popen(COMPILER..[[ -E -dM -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r") + print(COMPILER..[[ -E -dM -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]] .. CFLAGS) + local pipe,err = io.popen(COMPILER..[[ -E -dM -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]] .. CFLAGS,"r") local defines = {} while true do local line = pipe:read"*l" From 3f2e6f40df41a0c489f7416e5076db59c8371e24 Mon Sep 17 00:00:00 2001 From: Micon Frink Date: Wed, 28 Oct 2020 06:31:32 +0000 Subject: [PATCH 3/6] added a ternary to check for cl so that we don't have problems with Linux absolute paths... --- generator/generator.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/generator.lua b/generator/generator.lua index e68498f..2796776 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -13,7 +13,7 @@ local CPRE,CTEST --get implementations local implementations = {} for i=3,#script_args do - if script_args[i]:match("^[-/]") then + if script_args[i]:match(COMPILER == cl and "^/" or "^%-") then local key, value = script_args[i]:match("^(.+)=(.+)$") if key and value then CFLAGS = CFLAGS .. " " .. key .. "=\"" .. value:gsub("\"", "\\\"") .. "\""; From 507e19bc7e481910e56320ed01ae4449b9d52769 Mon Sep 17 00:00:00 2001 From: Micon Frink Date: Thu, 29 Oct 2020 16:31:38 +0000 Subject: [PATCH 4/6] adding documentation --- README.md | 2 ++ generator/generator.bat | 2 +- generator/generator.sh | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d3c6297..507b24f 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Notes: # using generator +``` * this is only needed (before compilation) if you want an imgui version different from the one provided, otherwise generation is already done. * you will need LuaJIT (https://github.com/LuaJIT/LuaJIT.git better 2.1 branch) or precompiled for linux/macOS/windows in https://luapower.com/luajit/download * you need to use also a C++ compiler for doing preprocessing: gcc (In windows MinGW-W64-builds for example), clang or cl (MSVC). (this repo was done with gcc) @@ -40,6 +41,7 @@ Notes: * edit config_generator.lua for adding includes needed by your chosen backends (vulkan needs that). * Run generator.bat or generator.sh with gcc, clang or cl and LuaJIT on your PATH. * as a result some files are generated: `cimgui.cpp`, `cimgui.h` and `cimgui_impl.h` for compiling and some lua/json files with information about the binding: `definitions.json` with function info, `structs_and_enums.json` with struct and enum info, `impl_definitions.json` with functions from the backends info. +* You can pass compiler flags to generator.sh or generator.bat at the end ofthe call to further specify the compiler behavior. (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) # generate binding * C interface is exposed by cimgui.h when you define CIMGUI_DEFINE_ENUMS_AND_STRUCTS diff --git a/generator/generator.bat b/generator/generator.bat index b439743..fad64a1 100644 --- a/generator/generator.bat +++ b/generator/generator.bat @@ -17,7 +17,7 @@ set PATH=%PATH%;C:\anima;C:\mingws\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\min :: arg[1] compiler name gcc, clang or cl :: arg[2] options as words in one string: internal for imgui_internal generation, freetype for freetype generation :: examples: "" "internal" "internal freetype" -:: arg[3..n] name of implementations to generate +:: arg[3..n] name of implementations to generate and/or CLFLAGS (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) luajit ./generator.lua gcc "internal" glfw opengl3 opengl2 sdl ::leave console open diff --git a/generator/generator.sh b/generator/generator.sh index efb48b3..2fb7a4d 100755 --- a/generator/generator.sh +++ b/generator/generator.sh @@ -15,5 +15,5 @@ # arg[1] compiler name gcc, clang, or cl # arg[2] options as words in one string: internal for imgui_internal generation, freetype for freetype generation # examples: "" "internal" "internal freetype" -# arg[3..n] name of implementations to generate +# arg[3..n] name of implementations to generate and/or CLFLAGS (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) luajit ./generator.lua gcc "internal" glfw opengl3 opengl2 sdl From 2a6970b50b143bebde5839b8ea5c7279352e79b6 Mon Sep 17 00:00:00 2001 From: "M. Frink ~ Lemur" Date: Thu, 29 Oct 2020 12:26:36 -0500 Subject: [PATCH 5/6] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 507b24f..24eca12 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Notes: * edit config_generator.lua for adding includes needed by your chosen backends (vulkan needs that). * Run generator.bat or generator.sh with gcc, clang or cl and LuaJIT on your PATH. * as a result some files are generated: `cimgui.cpp`, `cimgui.h` and `cimgui_impl.h` for compiling and some lua/json files with information about the binding: `definitions.json` with function info, `structs_and_enums.json` with struct and enum info, `impl_definitions.json` with functions from the backends info. -* You can pass compiler flags to generator.sh or generator.bat at the end ofthe call to further specify the compiler behavior. (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) +* You can pass compiler flags to generator.sh or generator.bat at the end of the call to further specify the compiler behavior. (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) # generate binding * C interface is exposed by cimgui.h when you define CIMGUI_DEFINE_ENUMS_AND_STRUCTS From 43bfbe227d6000283a6cba8c0550412f75464b0d Mon Sep 17 00:00:00 2001 From: "M. Frink ~ Lemur" Date: Thu, 29 Oct 2020 12:28:40 -0500 Subject: [PATCH 6/6] Fixed typo --- generator/generator.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/generator.bat b/generator/generator.bat index fad64a1..1c8206b 100644 --- a/generator/generator.bat +++ b/generator/generator.bat @@ -17,7 +17,7 @@ set PATH=%PATH%;C:\anima;C:\mingws\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\min :: arg[1] compiler name gcc, clang or cl :: arg[2] options as words in one string: internal for imgui_internal generation, freetype for freetype generation :: examples: "" "internal" "internal freetype" -:: arg[3..n] name of implementations to generate and/or CLFLAGS (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) +:: arg[3..n] name of implementations to generate and/or CFLAGS (e.g. -DIMGUI_USER_CONFIG or -DIMGUI_USE_WCHAR32) luajit ./generator.lua gcc "internal" glfw opengl3 opengl2 sdl ::leave console open