From d59448763fc6255a04a41af2a3509e4e0c058e93 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Thu, 10 Sep 2020 12:19:15 +0200 Subject: [PATCH] Freetype2 allow generation and compilation with Freetype2 --- CMakeLists.txt | 10 ++++++++++ README.md | 3 ++- generator/cimgui_template.cpp | 3 +++ generator/generator.bat | 5 +++-- generator/generator.lua | 32 +++++++++++++++++++++++++------- generator/generator.sh | 5 +++-- 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4233be1..9565e3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,15 @@ file(GLOB IMGUI_SOURCES ) set(IMGUI_STATIC "no" CACHE STRING "Build as a static library") +set(IMGUI_FREETYPE "no" CACHE STRING "Build with freetype library") +set(IMGUI_LIBRARIES ) + +if(IMGUI_FREETYPE) + FIND_PACKAGE(freetype REQUIRED PATHS ${FREETYPE_PATH}) + list(APPEND IMGUI_LIBRARIES freetype) + list(APPEND IMGUI_SOURCES imgui/misc/freetype/imgui_freetype.cpp) + add_definitions("-DCIMGUI_FREETYPE=1") +endif(IMGUI_FREETYPE) #add library and link if (IMGUI_STATIC) @@ -30,6 +39,7 @@ endif (WIN32) target_include_directories(cimgui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(cimgui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/imgui) set_target_properties(cimgui PROPERTIES PREFIX "") +target_link_libraries(cimgui ${IMGUI_LIBRARIES}) #install install(TARGETS cimgui diff --git a/README.md b/README.md index c74f264..56b6774 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Notes: * git submodule update * compile * using makefile on linux/macOS/mingw (Or use CMake to generate project) + * cmake options are IMGUI_STATIC (compiling as static library), IMGUI_FREETYPE (for using Freetype2) and FREETYPE_PATH (Freetype2 cmake install location) * or as in https://github.com/sonoro1234/LuaJIT-ImGui/tree/master/build # using generator @@ -32,7 +33,7 @@ Notes: * 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) * update `imgui` folder to the version you desire. -* edit `generator/generator.bat` on windows, or `generator/generator.sh` on linux, to choose between gcc, clang, or cl and to choose desired implementations and whether imgui_internal is generated or not. +* edit `generator/generator.bat` on windows, or `generator/generator.sh` on linux, to choose between gcc, clang, or cl and to choose desired implementations and whether imgui_internal is generated or not and Freetype2 is used or not. * edit config_generator.lua for adding includes needed by your chosen implementations (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` 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. diff --git a/generator/cimgui_template.cpp b/generator/cimgui_template.cpp index 4ea849e..c6b2ffa 100644 --- a/generator/cimgui_template.cpp +++ b/generator/cimgui_template.cpp @@ -1,5 +1,8 @@ #include "./imgui/imgui.h" +#ifdef CIMGUI_FREETYPE +#include "./imgui/misc/freetype/imgui_freetype.h" +#endif #include "./imgui/imgui_internal.h" #include "cimgui.h" diff --git a/generator/generator.bat b/generator/generator.bat index d565d9d..b439743 100644 --- a/generator/generator.bat +++ b/generator/generator.bat @@ -15,9 +15,10 @@ set PATH=%PATH%;C:\anima;C:\mingws\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\min :: set PATH=%PATH%;C:\luaGL\sources\luajit-master\luajit-master\bin\mingw32;C:\mingw32\bin; ::process files :: arg[1] compiler name gcc, clang or cl -:: arg[2] imgui_internal functions generation: true or false +:: 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 -luajit ./generator.lua gcc true glfw opengl3 opengl2 sdl +luajit ./generator.lua gcc "internal" glfw opengl3 opengl2 sdl ::leave console open cmd /k diff --git a/generator/generator.lua b/generator/generator.lua index f76471e..2f6c6dd 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -6,7 +6,8 @@ assert(_VERSION=='Lua 5.1',"Must use LuaJIT") assert(bit,"Must use LuaJIT") local script_args = {...} local COMPILER = script_args[1] -local INTERNAL_GENERATION = script_args[2]=="true" +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 CPRE,CTEST if COMPILER == "gcc" or COMPILER == "clang" then CPRE = COMPILER..[[ -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] @@ -40,6 +41,7 @@ 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 table.insert(implementations,script_args[i]) end @@ -273,6 +275,10 @@ if INTERNAL_GENERATION then cimgui_header = cimgui_header..[[//with imgui_internal.h api ]] end +if FREETYPE_GENERATION then + cimgui_header = cimgui_header..[[//with imgui_freetype.h api +]] +end print("IMGUI_VERSION",imgui_version) --get some defines---------------------------- gdefines = get_defines{"IMGUI_VERSION","FLT_MAX"} @@ -333,14 +339,26 @@ end --generation print("------------------generation with "..COMPILER.."------------------------") local parser1 +local headers = [[#include "../imgui/imgui.h" +]] +local headersT = {[[imgui]]} if INTERNAL_GENERATION then - save_data("headers.h",[[#include "../imgui/imgui.h" - #include "../imgui/imgui_internal.h"]]) - parser1 = parseImGuiHeader([[headers.h]],{[[imgui]],[[imgui_internal]],[[imstb_textedit]]}) - os.remove("headers.h") -else - parser1 = parseImGuiHeader([[../imgui/imgui.h]],{[[imgui]]}) + headers = headers .. [[#include "../imgui/imgui_internal.h" + ]] + headersT[#headersT + 1] = [[imgui_internal]] + headersT[#headersT + 1] = [[imstb_textedit]] end +if FREETYPE_GENERATION then + headers = headers .. [[ + #include "../imgui/misc/freetype/imgui_freetype.h" + ]] + headersT[#headersT + 1] = [[imgui_freetype]] +end +save_data("headers.h",headers) +local include_cmd = COMPILER=="cl" and [[ /I ]] or [[ -I ]] +local extra_includes = include_cmd.." ../imgui " +local parser1 = parseImGuiHeader(extra_includes .. [[headers.h]],headersT) +os.remove("headers.h") parser1:do_parse() save_data("./output/overloads.txt",parser1.overloadstxt) diff --git a/generator/generator.sh b/generator/generator.sh index 8f5e6ee..efb48b3 100755 --- a/generator/generator.sh +++ b/generator/generator.sh @@ -13,6 +13,7 @@ #process files # arg[1] compiler name gcc, clang, or cl -# arg[2] imgui_internal functions generation: true or false +# 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 -luajit ./generator.lua gcc true glfw opengl3 opengl2 sdl +luajit ./generator.lua gcc "internal" glfw opengl3 opengl2 sdl