Skip to content

Commit

Permalink
Build imgui_test_engine in cimgui-pack
Browse files Browse the repository at this point in the history
This is needed for linking.
  • Loading branch information
JamesWrigley committed Jun 20, 2024
1 parent 637507e commit bc37505
Show file tree
Hide file tree
Showing 51 changed files with 6,980 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ imgui_log.txt
.vscode
*Manifest.toml
build
cimgui-pack/test_engine/ImGuiTestEngine
cimgui-pack/test_engine/*-report.txt
cimgui-pack/test_engine/src/overrides.h
cimgui-pack/test_engine/config.toml
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 = cimgui-pack/cimnodes
url = https://github.com/cimgui/cimnodes.git
[submodule "cimgui-pack/test_engine/imgui_test_engine"]
path = cimgui-pack/test_engine/imgui_test_engine
url = https://github.com/ocornut/imgui_test_engine.git
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name = "CImGui"
uuid = "5d785b6c-b76f-510e-a07c-3070796c7e87"
authors = ["Yupei Qi <qiyupei@gmail.com>"]
version = "2"
version = "2.0.0"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
CSyntax = "ea656a56-6ca6-5dda-bba5-7b6963a5f74c"
LibCImGui = "9be01004-c4f5-478b-abeb-cb32b114cf5e"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

[weakdeps]
GLFW = "f7f18e0c-5ee9-5ccd-a5bf-e8befd85ed98"
Expand All @@ -20,7 +19,6 @@ GlfwOpenGLBackend = ["GLFW", "ModernGL"]
CEnum = "0.4, 0.5"
CSyntax = "0.4"
LibCImGui = "~1.90"
Preferences = "1"
julia = "1.6"

[extras]
Expand Down
71 changes: 70 additions & 1 deletion cimgui-pack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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)
Expand All @@ -17,15 +18,74 @@ 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 -DIMGUI_ENABLE_TEST_ENGINE)
target_compile_definitions(${target} PRIVATE
IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1
IMNODES_NAMESPACE=imnodes
IMGUI_ENABLE_TEST_ENGINE
IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL=1)

# Find GLFW
if (NOT DEFINED GLFW_LIBRARY)
Expand All @@ -45,13 +105,22 @@ else()
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>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cimgui/imgui>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cimplot>
$<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 Down
2 changes: 2 additions & 0 deletions cimgui-pack/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[deps]
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
GLFW_jll = "0656b61e-2033-5cc2-a64a-77c0f6c09b89"
WrapIt = "962878d8-9763-11ee-8c14-fbf60c98afae"
29 changes: 28 additions & 1 deletion cimgui-pack/build.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
import WrapIt: wrapit
import CxxWrap
import GLFW_jll

# 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_path(), "include"),
"{JULIA_INCLUDE_DIR}" => joinpath(dirname(Sys.BINDIR), "include"))
write("config.toml", new_config)

# We currently need a custom build of wrapit with these changes:
# - https://github.com/grasph/wrapit/pull/54
# - https://github.com/grasph/wrapit/pull/55
# - https://github.com/grasph/wrapit/pull/56
#
# TODO: when they're all merged and released, delete the generated sources
rm("src/overrides.h"; force=true)
run(`/home/james/git/wrapit/build/wrapit config.toml --force`)
# 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) ..`)
cxxwrap_prefix = CxxWrap.prefix_path()
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
Expand Down
4 changes: 4 additions & 0 deletions cimgui-pack/test_engine/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[deps]
CImGuiPack_jll = "333409e9-af72-5310-9767-d6ad21a76a05"
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
WrapIt = "962878d8-9763-11ee-8c14-fbf60c98afae"
17 changes: 17 additions & 0 deletions cimgui-pack/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 cimgui-pack/test_engine/imgui_test_engine
Submodule imgui_test_engine added at c3a507
43 changes: 43 additions & 0 deletions cimgui-pack/test_engine/overrides.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#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 jlcxx::Array<ImGuiTest*> TestsAll(ImGuiTestEngine* engine) {
auto size{ engine->TestsAll.size() };
jlcxx::Array<ImGuiTest*> tests{ static_cast<size_t>(size) };

ImGuiTest** data_ptr{ jl_array_data(tests.wrapped(), ImGuiTest*) };

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

return tests;
}

#endif
Loading

0 comments on commit bc37505

Please sign in to comment.