Compare commits

..

13 Commits

Author SHA1 Message Date
sonoro1234
3efb1001aa explain this repo option for generating 2018-10-10 11:16:01 +02:00
Victor Bombi
a91c611bca Merge pull request #70 from sonoro1234/noprepro_master
be able to generate without precompiler
2018-10-10 11:04:29 +02:00
sonoro1234
5b7abe8b4d be able to generate without precompiler 2018-10-10 10:59:51 +02:00
sonoro1234
812af400f1 allow cl compiler (MSVC) to work as preprocessor 2018-10-09 20:13:56 +02:00
sonoro1234
2d3cf59b21 clang information in README.md 2018-10-09 15:09:52 +02:00
sonoro1234
e7eb9c511b nopreprocess version without comments to enable easy comparation 2018-10-09 13:58:46 +02:00
sonoro1234
2759a8ed4d allow gcc or clang compiler 2018-10-09 11:03:49 +02:00
sonoro1234
073f438467 dont warn not const reference argument if it is manual 2018-10-09 10:39:49 +02:00
Victor Bombi
f7856b27b0 Merge pull request #69 from mellinoe/no-lib-prefix
Remove the "lib" prefix in CMakeLists.txt.
2018-10-09 10:14:55 +02:00
Eric Mellino
99c7d7cfdf Remove the "lib" prefix in CMakeLists.txt. 2018-10-09 00:48:03 -07:00
sonoro1234
31871f9975 still more README.md updates 2018-10-08 13:54:58 +02:00
sonoro1234
c487b0266e more README.md updates 2018-10-08 13:44:43 +02:00
sonoro1234
3b386799e4 add mellinoe autogeneration 2018-10-08 13:28:50 +02:00
8 changed files with 115 additions and 3827 deletions

View File

@@ -20,10 +20,11 @@ endif(WIN32)
#add library and link
add_library(cimgui SHARED ${IMGUI_SOURCES})
target_link_libraries(cimgui ${IMGUI_LIBRARIES})
set_target_properties(cimgui PROPERTIES PREFIX "")
#install
install(TARGETS cimgui
RUNTIME DESTINATION .
LIBRARY DESTINATION .
#ARCHIVE DESTINATION lib
)
)

View File

@@ -20,17 +20,22 @@ Notes:
* clone
* git clone --recursive https://github.com/cimgui/cimgui.git
* git submodule update
* make using makefile on linux/macOS/mingw (Or use CMake to generate project)
* compile
* using makefile on linux/macOS/mingw (Or use CMake to generate project)
* or as in https://github.com/sonoro1234/LuaJIT-ImGui/tree/master_auto_implementations/build
# auto binding generation
# using generator
* 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
* need also gcc compiler for doing preprocessing (In windows MinGW-W64-builds for example)
* you can use also a C++ compiler for doing preprocessing: gcc (In windows MinGW-W64-builds for example), clang or cl (MSVC) or not use a compiler (experimental nocompiler option) at all. (this repo was done with gcc)
* update `imgui` folder to the version you desire.
* run `generator/generator.bat` (or make a .sh version and please PR) with gcc and LuaJIT on your PATH.
* as a result some files are generated: `cimgui.cpp` and `cimgui.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 implementations info.
* build as shown in https://github.com/sonoro1234/LuaJIT-ImGui/tree/master_auto_implementations/build
* generate binding as done in https://github.com/sonoro1234/LuaJIT-ImGui/blob/master_auto_implementations/lua/build.bat
* edit `generator/generator.bat` (or make a .sh version and please PR) to choose between gcc, clang, cl or nocompiler. Run it with gcc, clang or cl and LuaJIT on your PATH.
* as a result some files are generated: `cimgui.cpp` and `cimgui.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 implementations info.
# generate binding
* with your prefered languaje from lua or json files as in:
* https://github.com/sonoro1234/LuaJIT-ImGui/blob/master_auto_implementations/lua/build.bat (with lua code generation in https://github.com/sonoro1234/LuaJIT-ImGui/blob/master_auto_implementations/lua/class_gen.lua)
* https://github.com/mellinoe/ImGui.NET/tree/autogen/src/CodeGenerator
# usage

View File

@@ -40,7 +40,7 @@ typedef struct ImColor_Simple { ImVec4_Simple Value;} ImColor_Simple;
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
struct ImDrawChannel;
typedef struct CustomRect CustomRect;
typedef struct GlyphRangesBuilder GlyphRangesBuilder;
typedef struct ImFontGlyph ImFontGlyph;
@@ -69,7 +69,6 @@ typedef struct ImDrawList ImDrawList;
typedef struct ImDrawData ImDrawData;
typedef struct ImDrawCmd ImDrawCmd;
typedef struct ImDrawChannel ImDrawChannel;
struct ImDrawChannel;
struct ImDrawCmd;
struct ImDrawData;
struct ImDrawList;

View File

@@ -14,8 +14,9 @@
:: set PATH=%PATH%;C:\luaGL;C:\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\mingw32\bin;
:: set PATH=%PATH%;C:\luaGL\sources\luajit-master\luajit-master\bin\mingw32;C:\mingw32\bin;
::process files
:: arg[1..n] name of implementations to generate
luajit ./generator.lua glfw opengl3 opengl2 sdl
:: arg[1] compiler name gcc, clang, cl or nocompiler
:: arg[2..n] name of implementations to generate
luajit ./generator.lua gcc glfw opengl3 opengl2 sdl
::leave console open
cmd /k

View File

@@ -5,27 +5,41 @@
assert(_VERSION=='Lua 5.1',"Must use LuaJIT")
assert(bit,"Must use LuaJIT")
local script_args = {...}
--test gcc present
local HAVE_GCC
local pipe,err = io.popen("gcc --version","r")
if pipe then
local str = pipe:read"*a"
print(str)
pipe:close()
if str=="" then
HAVE_GCC = false
else
HAVE_GCC = true
end
local COMPILER = script_args[1]
local CPRE,CTEST
if COMPILER == "gcc" or COMPILER == "clang" then
CPRE = COMPILER..[[ -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]]
CTEST = COMPILER.." --version"
elseif COMPILER == "cl" then
CPRE = COMPILER..[[ /E /DIMGUI_DISABLE_OBSOLETE_FUNCTIONS /DIMGUI_API="" /DIMGUI_IMPL_API="" ]]
CTEST = COMPILER
else
HAVE_GCC = false
print(err)
print("Working without compiler ")
end
print("HAVE_GCC",HAVE_GCC)
--test compiler present
local HAVE_COMPILER = false
if CTEST then
local pipe,err = io.popen(CTEST,"r")
if pipe then
local str = pipe:read"*a"
print(str)
pipe:close()
if str=="" then
HAVE_COMPILER = false
else
HAVE_COMPILER = true
end
else
HAVE_COMPILER = false
print(err)
end
assert(HAVE_COMPILER,"gcc, clang or cl needed to run script")
end --CTEST
print("HAVE_COMPILER",HAVE_COMPILER)
--get implementations
local implementations = {}
for i=1,#script_args do table.insert(implementations,script_args[i]) end
for i=2,#script_args do table.insert(implementations,script_args[i]) end
--------------------------------------------------------------------------
--this table has the functions to be skipped in generation
@@ -82,34 +96,48 @@ local gdefines = {} --for FLT_MAX and others
--------------------------------------------------------------------------
--helper functions
--------------------------------------------------------------------------
--iterates lines from a .h file and discards between #if.. and #endif
local function filelines(file)
--minimal preprocessor
local function filelines(file,locats)
local iflevels = {}
--only one case is true
local function prepro_boolif(line)
local ma = line:match("#ifndef%s+IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT") or line:match("#ifndef%s+ImTextureID")
return not (ma==nil)
end
local function location_it()
repeat
local line = file:read"*l"
if not line then return nil end
if line:sub(1,1) == "#" then
if line:match("#if") then
iflevels[#iflevels +1 ] = true
iflevels[#iflevels +1 ] = prepro_boolif(line)
elseif line:match("#endif") then
iflevels[#iflevels] = nil
elseif line:match("#elseif") then
iflevels[#iflevels] = false -- all false now
elseif line:match("#else") then
iflevels[#iflevels] = not iflevels[#iflevels]
end
-- skip
elseif #iflevels == 0 then
elseif #iflevels == 0 or iflevels[#iflevels] then
-- drop IMGUI_APIX
line = line:gsub("IMGUI_IMPL_API","")
-- drop IMGUI_API
line = line:gsub("IMGUI_API","")
return line
return line,locats[1]
end
until false
end
return location_it
end
--iterates lines from a gcc -E in a specific location
--iterates lines from a gcc/clang -E in a specific location
local function location(file,locpathT)
local location_re = '^# (%d+) "([^"]*)"'
local location_re
if COMPILER == "cl" then
location_re = '^#line (%d+) "([^"]*)"'
else --gcc, clang
location_re = '^# (%d+) "([^"]*)"'
end
local path_reT = {}
for i,locpath in ipairs(locpathT) do
table.insert(path_reT,'^(.*[\\/])('..locpath..')%.h$')
@@ -132,7 +160,9 @@ local function location(file,locpathT)
return nil
end
end
if line:sub(1,1) == "#" then
if #line==0 then --nothing on emptyline
elseif not line:match("%S") then --nothing if only spaces
elseif line:sub(1,1) == "#" then
-- Is this a location pragma?
local loc_num_t,location_match = line:match(location_re)
if location_match then
@@ -161,7 +191,7 @@ local function location(file,locpathT)
--return line,loc_num_real, which_location
end
end
until false
until false --forever
end
return location_it
end
@@ -266,7 +296,9 @@ local function clean_spaces(cad)
end
local function split_comment(line)
local comment = line:match("(%s*//.*)") or ""
return line:gsub("%s*//.*",""),comment
line = line:gsub("%s*//.*","")
line = line:gsub("%s*$","")
return line,comment
end
local function get_manuals(def)
return cimgui_manuals[def.ov_cimguiname] or cimgui_manuals[def.cimguiname]
@@ -288,7 +320,7 @@ end
local function struct_parser()
local function_re = "(%a*%w+%s*%b())" --"(%a*%w+%b())" --"(%a*%w+%s+%w+%b())"
local function_closing_re = "}"
local function_closed_re = "[;}]$"
local function_closed_re = "[;}]%s*$"
local operator_re = "operator.-%b()"
local functype_re = "(%(%*)[%w_]+(%)%([^%(%)]*%))"
local initial_comment_re = [[^%s*//.*]]
@@ -307,6 +339,7 @@ local function struct_parser()
--if in_function discard
if in_functionst then
--table.insert(structcdefs,"en function:"..line) --debug
if line:match(function_closing_re) then
in_functionst = false
--print("in function:",line)
@@ -314,16 +347,13 @@ local function struct_parser()
return
end
if (line:match(function_re) or line:match(operator_re)) and not line:match("typedef.*%b().*%b().*")
and not line:match(functype_re) then
--table.insert(structcdefs,"function test2:"..line) --debug
if not line:match(function_closed_re) then
--print("match:",line)
in_functionst = true
end
--else
--table.insert(structcdefs,linecommented)
elseif line:match("template") then
--nothing
elseif line:match("public:") then
@@ -332,7 +362,6 @@ local function struct_parser()
local linea = line:gsub("%S+",{class="struct",mutable=""})
linea = linea:gsub("(%b<>)","/*%1*/") --comment template parameters
table.insert(structcdefs,linea..comment)
end
return
end
@@ -563,7 +592,11 @@ local function func_parser()
end
table.insert(argsArr,{type=type,name=name,ret=retf,signature=sigf})
if arg:match("&") and not arg:match("const") then
print("reference to no const arg in",funcname,argscsinpars)
--only post error if not manual
local cname = getcimguiname(stname,funcname)
if not cimgui_manuals[cname] then
print("reference to no const arg in",funcname,argscsinpars)
end
end
end
argscsinpars = argscsinpars:gsub("&","")
@@ -792,6 +825,11 @@ local function gen_structs_and_enums_table(cdefs)
if (#enumnames > 0) then
assert(#structnames==0,"enum in struct")
-- if #structnames~=0 then
-- print(line,#line)
-- print(linecom,#linecom)
-- error"enuminstruct"
-- end
if line:match(struct_closing_re) and not line:match(struct_op_close_re) then
enumnames[#enumnames] = nil
break
@@ -925,13 +963,15 @@ local function gen_structs_and_enums(cdefs)
-- ImVector special treatment
if structnames[#structnames] == "ImVector" then
if line:match(struct_closing_re) then
table.insert(outtab,[[struct ImVector
table.insert(outtab,[[
struct ImVector
{
int Size;
int Capacity;
void* Data;
};
typedef struct ImVector ImVector;]])
typedef struct ImVector ImVector;
]])
structnames[#structnames] = nil
end
break -- dont write
@@ -1205,7 +1245,8 @@ local function check_arg_detection(fdefs,typedefs)
print"-----------------end check arg detection-----------------------"
end
local function get_defines(t)
local pipe,err = io.popen([[gcc -E -dM -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r")
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")
local defines = {}
while true do
local line = pipe:read"*l"
@@ -1294,35 +1335,20 @@ pipe:close()
cimgui_header = cimgui_header:gsub("XXX",imgui_version)
print("IMGUI_VERSION",imgui_version)
--get some defines----------------------------
if HAVE_GCC then
if HAVE_COMPILER then
gdefines = get_defines{"IMGUI_VERSION","FLT_MAX"}
end
--first without gcc
---[[
print"------------------generation without precompiler------------------------"
local pipe,err = io.open("../imgui/imgui.h","r")
if not pipe then
error("could not open file:"..err)
end
local STP = struct_parser()
local FP = func_parser()
for line in filelines(pipe) do
local line, comment = split_comment(line)
STP.insert(line,comment)
FP.insert(line,comment)
end
pipe:close()
FP:compute_overloads()
cimgui_generation("_nopreprocess",STP,FP)
--]]
--then gcc
print"------------------generation with precompiler------------------------"
--generation
print("------------------generation with "..COMPILER.."------------------------")
local pFP,pSTP,typedefs_dict2
if HAVE_GCC then
local pipe,err = io.popen([[gcc -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r")
local pipe,err
if HAVE_COMPILER then
pipe,err = io.popen(CPRE..[[../imgui/imgui.h]],"r")
else
pipe,err = io.open([[../imgui/imgui.h]],"r")
end
if not pipe then
error("could not execute gcc "..err)
@@ -1331,19 +1357,23 @@ end
pSTP = struct_parser() --overwrite
pFP = func_parser() --overwrite
for line in location(pipe,{"imgui"}) do
local iterator = (HAVE_COMPILER and location) or filelines
for line in iterator(pipe,{"imgui"}) do
local line, comment = split_comment(line)
--line = clean_spaces(line)
pSTP.insert(line,comment)
pFP.insert(line,comment)
end
pipe:close()
local ovstr = pFP:compute_overloads()
ADDnonUDT(pFP)
save_data("./output/overloads.txt",ovstr)
typedefs_dict2 = cimgui_generation("",pSTP,pFP)
--check arg detection failure if no name in function declaration
check_arg_detection(pFP.defsT,typedefs_dict2)
end
----------save fundefs in definitions.lua for using in bindings
set_defines(pFP.defsT)
@@ -1367,8 +1397,8 @@ if #implementations > 0 then
local source = [[../imgui/examples/imgui_impl_]].. impl .. ".h "
local locati = [[imgui_impl_]].. impl
local pipe,err
if HAVE_GCC then
pipe,err = io.popen([[gcc -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] ..source,"r")
if HAVE_COMPILER then
pipe,err = io.popen(CPRE..source,"r")
else
pipe,err = io.open(source,"r")
end
@@ -1376,7 +1406,7 @@ if #implementations > 0 then
error("could not get file: "..err)
end
local iterator = (HAVE_GCC and location) or filelines
local iterator = (HAVE_COMPILER and location) or filelines
for line,locat in iterator(pipe,{locati}) do
local line, comment = split_comment(line)

View File

@@ -40,7 +40,7 @@ typedef struct ImColor_Simple { ImVec4_Simple Value;} ImColor_Simple;
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
struct ImDrawChannel;
typedef struct CustomRect CustomRect;
typedef struct GlyphRangesBuilder GlyphRangesBuilder;
typedef struct ImFontGlyph ImFontGlyph;
@@ -69,7 +69,6 @@ typedef struct ImDrawList ImDrawList;
typedef struct ImDrawData ImDrawData;
typedef struct ImDrawCmd ImDrawCmd;
typedef struct ImDrawChannel ImDrawChannel;
struct ImDrawChannel;
struct ImDrawCmd;
struct ImDrawData;
struct ImDrawList;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff