Examples: CI: backtrack and make example_null embed backend: simpler for all sorts of quick build scripts.

This commit is contained in:
ocornut
2025-11-17 16:36:54 +01:00
parent 0cf5b93a0a
commit cfb48969af
7 changed files with 36 additions and 55 deletions

View File

@@ -61,7 +61,7 @@ jobs:
echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp
echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp
g++ -I. -Wall -Wformat -shared -o libimgui.dll -Wl,--out-implib,libimgui.a example_single_file.cpp -limm32
g++ -I. -Ibackends -Wall -Wformat -DIMGUI_API='__declspec(dllimport)' -o example_null.exe examples/example_null/main.cpp backends/imgui_impl_null.cpp -L. -limgui
g++ -I. -Wall -Wformat -DIMGUI_API='__declspec(dllimport)' -o example_null.exe examples/example_null/main.cpp -L. -limgui
rm -f example_null.exe libimgui.* example_single_file.*
- name: Build example_null (extra warnings, msvc 64-bit)
@@ -78,11 +78,10 @@ jobs:
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "examples/backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -Wall -Wformat -o example_single_file.exe example_single_file.cpp -limm32
g++ -I. -Wall -Wformat -o example_single_file.exe example_single_file.cpp -limm32
- name: Build example_null (with IMGUI_DISABLE_WIN32_FUNCTIONS)
shell: bash
@@ -92,11 +91,10 @@ jobs:
#define IMGUI_DISABLE_WIN32_FUNCTIONS
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "examples/backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -Wall -Wformat -o example_single_file.exe example_single_file.cpp -limm32
g++ -I. -Wall -Wformat -o example_single_file.exe example_single_file.cpp -limm32
- name: Build example_null (as DLL)
shell: cmd
@@ -107,8 +105,8 @@ jobs:
echo #define IMGUI_IMPLEMENTATION >> example_single_file.cpp
echo #include "misc/single_file/imgui_single_file.h" >> example_single_file.cpp
cl.exe /D_USRDLL /D_WINDLL /I. /Ibackends example_single_file.cpp /LD /FeImGui.dll /link
cl.exe /DIMGUI_API=__declspec(dllimport) /I. ImGui.lib /Feexample_null.exe backends/imgui_impl_null.cpp examples/example_null/main.cpp
cl.exe /D_USRDLL /D_WINDLL /I. example_single_file.cpp /LD /FeImGui.dll /link
cl.exe /DIMGUI_API=__declspec(dllimport) /I. ImGui.lib /Feexample_null.exe examples/example_null/main.cpp
# Win64 examples are more frequently compilted than the Win32 examples.
# More of the Win32 examples requires 'workflow_run' to reduce waste.
@@ -296,11 +294,10 @@ jobs:
#define IM_ASSERT(x)
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -Wextra -Werror -Wno-zero-as-null-pointer-constant -Wno-double-promotion -Wno-variadic-macros -Wno-empty-body -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -Wextra -Werror -Wno-zero-as-null-pointer-constant -Wno-double-promotion -Wno-variadic-macros -Wno-empty-body -o example_single_file example_single_file.cpp
- name: Build example_null (freetype)
run: |
@@ -313,11 +310,10 @@ jobs:
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with ImWchar32)
run: |
@@ -326,11 +322,10 @@ jobs:
#define IMGUI_USE_WCHAR32
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with large ImDrawIdx + pointer ImTextureID)
run: |
@@ -340,11 +335,10 @@ jobs:
#define ImDrawIdx unsigned int
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with IMGUI_DISABLE_OBSOLETE_FUNCTIONS)
run: |
@@ -353,11 +347,10 @@ jobs:
#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with IMGUI_DISABLE_OBSOLETE_KEYIO)
run: |
@@ -366,11 +359,10 @@ jobs:
#define IMGUI_DISABLE_OBSOLETE_KEYIO
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with C++20)
run: |
@@ -379,11 +371,10 @@ jobs:
#define IMGUI_DISABLE_OBSOLETE_KEYIO
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++20 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++20 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with IMGUI_DISABLE_DEMO_WINDOWS and IMGUI_DISABLE_DEBUG_TOOLS)
run: |
@@ -393,11 +384,10 @@ jobs:
#define IMGUI_DISABLE_DEBUG_TOOLS
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with IMGUI_DISABLE_FILE_FUNCTIONS)
run: |
@@ -406,11 +396,10 @@ jobs:
#define IMGUI_DISABLE_FILE_FUNCTIONS
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with IMGUI_USE_BGRA_PACKED_COLOR)
run: |
@@ -419,11 +408,10 @@ jobs:
#define IMGUI_USE_BGRA_PACKED_COLOR
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with IM_VEC2_CLASS_EXTRA and IM_VEC4_CLASS_EXTRA)
run: |
@@ -440,11 +428,10 @@ jobs:
operator MyVec4() const { return MyVec4(x, y, z, w); }
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (C++26, Clang)
run: |
@@ -453,11 +440,10 @@ jobs:
#define IMGUI_IMPLEMENTATION
#define IMGUI_DISABLE_DEMO_WINDOWS
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
clang++ -I. -Ibackends -std=c++26 -Wall -Wformat -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp
clang++ -I. -std=c++26 -Wall -Wformat -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp
- name: Build example_null (without c++ runtime, Clang)
run: |
@@ -466,11 +452,10 @@ jobs:
#define IMGUI_IMPLEMENTATION
#define IMGUI_DISABLE_DEMO_WINDOWS
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
clang++ -I. -Ibackends -std=c++11 -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp
clang++ -I. -std=c++11 -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp
- name: Build example_glfw_opengl2
run: make -C examples/example_glfw_opengl2
@@ -487,7 +472,7 @@ jobs:
run: make -C examples/example_sdl2_opengl3
- name: Build with IMGUI_IMPL_VULKAN_NO_PROTOTYPES
run: g++ -c -I. -Ibackends -std=c++11 -DIMGUI_IMPL_VULKAN_NO_PROTOTYPES=1 backends/imgui_impl_vulkan.cpp
run: g++ -c -I. -std=c++11 -DIMGUI_IMPL_VULKAN_NO_PROTOTYPES=1 backends/imgui_impl_vulkan.cpp
MacOS:
runs-on: macos-latest
@@ -507,11 +492,10 @@ jobs:
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
clang++ -I. -Ibackends -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
clang++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (single file build, c++20)
run: |
@@ -519,11 +503,10 @@ jobs:
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
clang++ -I. -Ibackends -std=c++20 -Wall -Wformat -o example_single_file example_single_file.cpp
clang++ -I. -std=c++20 -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (without c++ runtime)
run: |
@@ -531,11 +514,10 @@ jobs:
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "backends/imgui_impl_null.cpp"
#include "examples/example_null/main.cpp"
EOF
clang++ -I. -Ibackends -std=c++11 -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp
clang++ -I. -std=c++11 -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp
- name: Build example_glfw_opengl2
run: make -C examples/example_glfw_opengl2

View File

@@ -220,7 +220,7 @@ IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd)
return ImGui_ImplWin32_InitEx(hwnd, true);
}
IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown()
void ImGui_ImplWin32_Shutdown()
{
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
@@ -392,7 +392,7 @@ static void ImGui_ImplWin32_UpdateGamepads(ImGuiIO& io)
#endif
}
IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame()
void ImGui_ImplWin32_NewFrame()
{
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
IM_ASSERT(bd != nullptr && "Context or backend not initialized? Did you call ImGui_ImplWin32_Init()?");
@@ -861,7 +861,7 @@ typedef HRESULT(WINAPI* PFN_GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT*,
typedef DPI_AWARENESS_CONTEXT(WINAPI* PFN_SetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); // User32.lib + dll, Windows 10 v1607+ (Creators Update)
// Helper function to enable DPI awareness without setting up a manifest
IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness()
void ImGui_ImplWin32_EnableDpiAwareness()
{
if (_IsWindows10OrGreater())
{
@@ -890,7 +890,7 @@ IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness()
#pragma comment(lib, "gdi32") // Link with gdi32.lib for GetDeviceCaps(). MinGW will require linking with '-lgdi32'
#endif
IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor)
float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor)
{
UINT xdpi = 96, ydpi = 96;
if (_IsWindows8Point1OrGreater())
@@ -916,7 +916,7 @@ IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor)
return xdpi / 96.0f;
}
IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd)
float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd)
{
HMONITOR monitor = ::MonitorFromWindow((HWND)hwnd, MONITOR_DEFAULTTONEAREST);
return ImGui_ImplWin32_GetDpiScaleForMonitor(monitor);
@@ -933,7 +933,7 @@ IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd)
// [experimental]
// Borrowed from GLFW's function updateFramebufferTransparency() in src/win32_window.c
// (the Dwm* functions are Vista era functions but we are borrowing logic from GLFW)
IMGUI_IMPL_API void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd)
void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd)
{
if (!_IsWindowsVistaOrGreater())
return;

View File

@@ -14,11 +14,10 @@ EXE = example_null
IMGUI_DIR = ../..
SOURCES = main.cpp
SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_null.cpp
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
UNAME_S := $(shell uname -s)
CXXFLAGS += -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
CXXFLAGS += -std=c++11 -I$(IMGUI_DIR)
CXXFLAGS += -g -Wall -Wformat
LIBS =

View File

@@ -1,3 +1,3 @@
@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler.
mkdir Debug
cl /nologo /Zi /MD /utf-8 /I ..\.. %* *.cpp ..\..\*.cpp ..\..\backends\imgui_impl_null.cpp /FeDebug/example_null.exe /FoDebug/ /link gdi32.lib shell32.lib imm32.lib
cl /nologo /Zi /MD /utf-8 /I ..\.. %* *.cpp ..\..\*.cpp /FeDebug/example_null.exe /FoDebug/ /link gdi32.lib shell32.lib imm32.lib

View File

@@ -151,7 +151,6 @@
<ClInclude Include="..\..\imconfig.h" />
<ClInclude Include="..\..\imgui.h" />
<ClInclude Include="..\..\imgui_internal.h" />
<ClInclude Include="..\..\backends\imgui_impl_null.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\imgui.cpp" />

View File

@@ -18,9 +18,6 @@
<ClInclude Include="..\..\imgui_internal.h">
<Filter>imgui</Filter>
</ClInclude>
<ClInclude Include="..\..\backends\imgui_impl_null.h">
<Filter>sources</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\imgui.cpp">
@@ -54,4 +51,4 @@
<Filter>imgui</Filter>
</None>
</ItemGroup>
</Project>
</Project>

View File

@@ -3,7 +3,11 @@
// This is useful to test building, but you cannot interact with anything here!
#include "imgui.h"
#include <stdio.h>
#include "imgui_impl_null.h"
// For imgui_impl_null: use relative filename + embed implementation directly by including the .cpp file.
// This is to simplify casual building of this example from all sorts of test scripts.
#include "../../backends/imgui_impl_null.h"
#include "../../backends/imgui_impl_null.cpp"
int main(int, char**)
{