Skip to content

Commit

Permalink
Merge pull request #3 from JuliaImGui/cimgui2
Browse files Browse the repository at this point in the history
CImGui 2 files
  • Loading branch information
JamesWrigley authored Jun 27, 2024
2 parents 86874ce + 659b1de commit 85d8bdb
Show file tree
Hide file tree
Showing 53 changed files with 7,055 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
build
*Manifest.toml
test_engine/ImGuiTestEngine
test_engine/config.toml
test_engine/jlImGuiTestEngine-report.txt
test_engine/src/overrides.h
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "cimnodes"]
path = cimnodes
url = https://github.com/cimgui/cimnodes.git
[submodule "test_engine/imgui_test_engine"]
path = test_engine/imgui_test_engine
url = https://github.com/ocornut/imgui_test_engine.git
93 changes: 88 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,110 @@ set(target cimgui)

add_library(${target} SHARED)

# cimgui and the backends
target_sources(${target} PRIVATE ./cimgui/imgui/imgui.cpp)
target_sources(${target} PRIVATE ./cimgui/imgui/imgui_demo.cpp)
target_sources(${target} PRIVATE ./cimgui/imgui/imgui_draw.cpp)
target_sources(${target} PRIVATE ./cimgui/imgui/imgui_tables.cpp)
target_sources(${target} PRIVATE ./cimgui/imgui/imgui_widgets.cpp)
target_sources(${target} PRIVATE ./cimgui/imgui/backends/imgui_impl_glfw.cpp)
target_sources(${target} PRIVATE ./cimgui/imgui/backends/imgui_impl_opengl3.cpp)
target_sources(${target} PRIVATE ./cimgui/cimgui.cpp)

# imgui_test_engine
set(TE_DIR "test_engine/imgui_test_engine/imgui_test_engine")
set(WRAPPER_DIR "test_engine/src")
target_sources(${target} PRIVATE
# Wrapper sources
${WRAPPER_DIR}/JlGlobals.cxx
${WRAPPER_DIR}/JlImBuildInfo.cxx
${WRAPPER_DIR}/JlImGuiCaptureArgs.cxx
${WRAPPER_DIR}/JlImGuiCaptureContext.cxx
${WRAPPER_DIR}/JlImGuiCaptureToolUI.cxx
${WRAPPER_DIR}/JlImGuiContext.cxx
${WRAPPER_DIR}/JlImGuiCsvParser.cxx
${WRAPPER_DIR}/JlImGuiPerfTool.cxx
${WRAPPER_DIR}/JlImGuiPerfToolBatch.cxx
${WRAPPER_DIR}/JlImGuiPerfToolEntry.cxx
${WRAPPER_DIR}/JlImGuiTest.cxx
${WRAPPER_DIR}/JlImGuiTestActionFilter.cxx
${WRAPPER_DIR}/JlImGuiTestContext.cxx
${WRAPPER_DIR}/JlImGuiTestCoroutineInterface.cxx
${WRAPPER_DIR}/JlImGuiTestEngine.cxx
${WRAPPER_DIR}/JlImGuiTestEngineIO.cxx
${WRAPPER_DIR}/JlImGuiTestFindByLabelTask.cxx
${WRAPPER_DIR}/JlImGuiTestGatherTask.cxx
${WRAPPER_DIR}/JlImGuiTestGenericItemStatus.cxx
${WRAPPER_DIR}/JlImGuiTestGenericVars.cxx
${WRAPPER_DIR}/JlImGuiTestInfoTask.cxx
${WRAPPER_DIR}/JlImGuiTestInput.cxx
${WRAPPER_DIR}/JlImGuiTestInputs.cxx
${WRAPPER_DIR}/JlImGuiTestItemInfo.cxx
${WRAPPER_DIR}/JlImGuiTestItemList.cxx
${WRAPPER_DIR}/JlImGuiTestLog.cxx
${WRAPPER_DIR}/JlImGuiTestLogLineInfo.cxx
${WRAPPER_DIR}/JlImGuiTestOutput.cxx
${WRAPPER_DIR}/JlImGuiTestRef.cxx
${WRAPPER_DIR}/JlImGuiTestRefDesc.cxx
${WRAPPER_DIR}/JlImGuiTestRunTask.cxx
${WRAPPER_DIR}/JlImMovingAverage.cxx
${WRAPPER_DIR}/JlImVec2.cxx
${WRAPPER_DIR}/JlImVec4.cxx
${WRAPPER_DIR}/JlStr.cxx
${WRAPPER_DIR}/jlImGuiTestEngine.cxx

# Test engine sources
${TE_DIR}/imgui_te_context.cpp
${TE_DIR}/imgui_te_coroutine.cpp
${TE_DIR}/imgui_te_engine.cpp
${TE_DIR}/imgui_te_perftool.cpp
${TE_DIR}/imgui_te_ui.cpp
${TE_DIR}/imgui_te_utils.cpp
${TE_DIR}/imgui_capture_tool.cpp
${TE_DIR}/imgui_te_exporters.cpp
)

# cimplot
target_sources(${target} PRIVATE ./cimplot/implot/implot.cpp)
target_sources(${target} PRIVATE ./cimplot/implot/implot_items.cpp)
target_sources(${target} PRIVATE ./cimplot/implot/implot_demo.cpp)
target_sources(${target} PRIVATE ./cimplot/cimplot.cpp)

# cimnodes
target_sources(${target} PRIVATE ./cimnodes/imnodes/imnodes.cpp)
target_sources(${target} PRIVATE ./cimnodes/cimnodes.cpp)

add_definitions(-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1 -DIMNODES_NAMESPACE=imnodes)
target_compile_definitions(${target} PRIVATE
IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1
IMNODES_NAMESPACE=imnodes
IMGUI_ENABLE_TEST_ENGINE
IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL=0)

# Find GLFW
if (NOT DEFINED GLFW_LIBRARY)
find_package(glfw3 3.1 REQUIRED)
set(GLFW_LIBRARY "glfw")
endif()
target_link_libraries(${target} "${GLFW_LIBRARY}")

if (WIN32)
add_definitions("-DIMGUI_IMPL_API=extern \"C\" __declspec\(dllexport\)")
target_link_libraries(${target} imm32)
add_definitions("-DIMGUI_IMPL_API=extern \"C\" __declspec\(dllexport\)")
target_link_libraries(${target} imm32 opengl32)
elseif(APPLE)
add_definitions("-DIMGUI_IMPL_API=extern \"C\" ")
target_link_libraries(${target} "-framework OpenGL")
else()
add_definitions("-DIMGUI_IMPL_API=extern \"C\" ")
endif(WIN32)
add_definitions("-DIMGUI_IMPL_API=extern \"C\" ")
target_link_libraries(${target} GL)
endif()

# Linking for cxxwrap
find_package(JlCxx)
get_target_property(JlCxx_location JlCxx::cxxwrap_julia LOCATION)
get_filename_component(JlCxx_location ${JlCxx_location} DIRECTORY)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${JlCxx_location}")
message(STATUS "Found JlCxx at ${JlCxx_location}")
target_link_libraries(${target} JlCxx::cxxwrap_julia)

target_include_directories(${target} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cimgui>
Expand All @@ -39,6 +120,7 @@ target_include_directories(${target} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cimplot/implot>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cimnodes>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cimnodes/imnodes>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test_engine/imgui_test_engine/imgui_test_engine>
$<INSTALL_INTERFACE:include>)

target_compile_features(${target} PRIVATE cxx_std_11)
Expand All @@ -49,6 +131,7 @@ set(hdrs ${CMAKE_CURRENT_SOURCE_DIR}/cimgui/imgui/imgui.h
${CMAKE_CURRENT_SOURCE_DIR}/cimgui/imgui/imstb_rectpack.h
${CMAKE_CURRENT_SOURCE_DIR}/cimgui/imgui/imstb_textedit.h
${CMAKE_CURRENT_SOURCE_DIR}/cimgui/imgui/imstb_truetype.h
${CMAKE_CURRENT_SOURCE_DIR}/cimgui/generator/output/cimgui_impl.h
${CMAKE_CURRENT_SOURCE_DIR}/cimgui/cimgui.h
${CMAKE_CURRENT_SOURCE_DIR}/cimplot/implot/implot.h
${CMAKE_CURRENT_SOURCE_DIR}/cimplot/implot/implot_internal.h
Expand Down
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[deps]
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
GLFW_jll = "0656b61e-2033-5cc2-a64a-77c0f6c09b89"
WrapIt = "962878d8-9763-11ee-8c14-fbf60c98afae"
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# cimgui-pack

### This repository is deprecated, development continues in the [CImGui.jl](https://github.com/Gnimuc/CImGui.jl) monorepo.

---

This is a meta-repo containing submodules of the C bindings for Dear ImGui and
related packages:
- [cimgui](https://github.com/cimgui/cimgui)
Expand All @@ -12,7 +8,13 @@ related packages:

The versions have been picked so that they're all compatible with each other,
i.e. matching the latest ImGui version. The currently supported ImGui version
is: [*v1.89.4*](https://github.com/ocornut/imgui/releases/tag/v1.89.4).
is: [*v1.90.8*](https://github.com/ocornut/imgui/releases/tag/v1.90.8).

You can build the resulting shared library locally with:
```julia-repl
# $ julia --project=.
julia> include("cimgui-pack/build.jl")
```

This repo is used directly by:
- [CImGuiPack](https://github.com/JuliaPackaging/Yggdrasil/tree/master/C/CImGuiPack)
Expand Down
35 changes: 35 additions & 0 deletions build.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import WrapIt: wrapit
import CxxWrap
import GLFW_jll


cxxwrap_prefix = CxxWrap.prefix_path()

# Generate the imgui_test_engine wrappers
cd(joinpath(@__DIR__, "test_engine")) do
# Write the config file from the template
config = read("config.template.toml", String)
new_config = replace(config,
"{CXXWRAP_INCLUDE_DIR}" => joinpath(cxxwrap_prefix, "include"),
"{JULIA_INCLUDE_DIR}" => joinpath(dirname(Sys.BINDIR), "include/julia"))
write("config.toml", new_config)

rm("src/overrides.h"; force=true)
wrapit("config.toml"; force=true, verbosity=0)
end

cd(@__DIR__) do
if !isdir("build")
mkdir("build")
end

cp("test_engine/overrides.h", "test_engine/src/overrides.h"; force=true)

cd("build") do
run(`cmake -DCMAKE_BUILD_TYPE=Release
-DGLFW_LIBRARY=$(GLFW_jll.libglfw)
-DCMAKE_PREFIX_PATH=$(cxxwrap_prefix) ..`)
nprocs = Sys.CPU_THREADS
run(`cmake --build . -j$(nprocs)`)
end
end
2 changes: 1 addition & 1 deletion cimnodes
Submodule cimnodes updated 2 files
+1 −1 .gitmodules
+1 −1 imnodes
17 changes: 17 additions & 0 deletions test_engine/config.template.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module_name = "ImGuiTestEngine"
uuid = "d6eb4cb6-1e07-14c4-5835-ae91bedf8555"
include_dirs = [".", "./imgui_test_engine/imgui_test_engine", "../cimgui/imgui"]
input = ["imgui_te_engine.h", "imgui_te_internal.h", "imgui_te_context.h",
"imgui_te_perftool.h", "imgui_te_ui.h", "imgui_te_utils.h", "imgui_te_exporters.h",
"overrides.h"]
cxx-std = "c++17"
out_cxx_dir = "src"

veto_list = "veto_list.txt"
extra_headers = ["imgui.h", "imgui_internal.h", "thirdparty/Str/Str.h"]
clang_opts = ["-DIMGUI_TEST_ENGINE_ENABLE_STD_FUNCTION=1", "-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1",
"-I{CXXWRAP_INCLUDE_DIR}",
"-I{JULIA_INCLUDE_DIR}"]
lib_basename = "$(@__DIR__)/../../../build/libcimgui"
export = "none"
vetoed_copy_ctor_classes = ["ImGuiContext"]
1 change: 1 addition & 0 deletions test_engine/imgui_test_engine
Submodule imgui_test_engine added at c3a507
65 changes: 65 additions & 0 deletions test_engine/overrides.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef OVERRIDES_H
#define OVERRIDES_H

#include "imgui_internal.h"
#include "imgui_te_engine.h"
#include "jlcxx/array.hpp"

inline void* TestFunc(ImGuiTest* test) {
return reinterpret_cast<void*>(test->TestFunc);
}

inline void* set_TestFunc(ImGuiTest* test, void* func) {
test->TestFunc = reinterpret_cast<ImGuiTestTestFunc*>(func);
return func;
}

inline void* GuiFunc(ImGuiTest* test) {
return reinterpret_cast<void*>(test->GuiFunc);
}

inline void* set_GuiFunc(ImGuiTest* test, void* func) {
test->GuiFunc = reinterpret_cast<ImGuiTestGuiFunc*>(func);
return func;
}

inline ImGuiContext* Ptr2ImGuiContext(void* ctx) {
return static_cast<ImGuiContext*>(ctx);
}

inline void* GetWindowByRef(ImGuiTestContext* ctx, ImGuiTestRef ref) {
return static_cast<void*>(ctx->GetWindowByRef(ref));
}

inline void SetRef(ImGuiTestContext* ctx, void* window) {
ctx->SetRef(static_cast<ImGuiWindow*>(window));
}

inline void ScrollToTabItem(ImGuiTestContext* ctx, void* tab_bar, ImGuiID tab_id) {
ctx->ScrollToTabItem(static_cast<ImGuiTabBar*>(tab_bar), tab_id);
}

inline bool TabBarCompareOrder(ImGuiTestContext* ctx, void* tab_bar, const char** tab_order) {
return ctx->TabBarCompareOrder(static_cast<ImGuiTabBar*>(tab_bar), tab_order);
}

inline jlcxx::Array<ImGuiTest*> TestsAll(ImGuiTestEngine* engine) {
auto size{ engine->TestsAll.size() };
jlcxx::Array<ImGuiTest*> tests{ static_cast<size_t>(size) };

// jl_array_data() changed in 1.11 so we need to check the Julia version
// we're building against.
#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR < 11
ImGuiTest** data_ptr{ (ImGuiTest**)jl_array_data(tests.wrapped()) };
#else
ImGuiTest** data_ptr{ jl_array_data(tests.wrapped(), ImGuiTest*) };
#endif

for (int i = 0; i < size; ++i) {
data_ptr[i] = engine->TestsAll[i];
}

return tests;
}

#endif
Loading

0 comments on commit 85d8bdb

Please sign in to comment.