From b5a73033ab54009186bb8e4c711e03e6b939cb91 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 14 May 2025 18:05:23 +0200 Subject: [PATCH] Examples: Apple: Amend build scripts and gitignore, fix misc OSX warnings. (#8637) # Conflicts: # backends/imgui_impl_metal.mm --- .gitignore | 4 +++- backends/imgui_impl_osx.mm | 2 +- docs/CHANGELOG.txt | 1 + examples/example_apple_metal/Makefile | 28 ++++++++++------------ examples/example_apple_opengl2/Makefile | 32 +++++++++++-------------- 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 5a5c8cda3..6cadd63b4 100644 --- a/.gitignore +++ b/.gitignore @@ -32,9 +32,10 @@ JSON/ ## Commonly used CMake directories build*/ -## Xcode artifacts +## Xcode & macOS artifacts project.xcworkspace xcuserdata +examples/*/*.dSYM ## Emscripten artifacts examples/*.o.tmp @@ -54,6 +55,7 @@ cmake-build-* ## Unix executables from our example Makefiles examples/example_apple_metal/example_apple_metal +examples/example_apple_opengl2/example_apple_opengl2 examples/example_glfw_metal/example_glfw_metal examples/example_glfw_opengl2/example_glfw_opengl2 examples/example_glfw_opengl3/example_glfw_opengl3 diff --git a/backends/imgui_impl_osx.mm b/backends/imgui_impl_osx.mm index 558ed9f2a..32e562472 100644 --- a/backends/imgui_impl_osx.mm +++ b/backends/imgui_impl_osx.mm @@ -477,7 +477,7 @@ bool ImGui_ImplOSX_Init(NSView* view) [view addSubview:bd->KeyEventResponder]; ImGui_ImplOSX_AddTrackingArea(view); - platform_io.Platform_SetImeDataFn = [](ImGuiContext*, ImGuiViewport* viewport, ImGuiPlatformImeData* data) -> void + platform_io.Platform_SetImeDataFn = [](ImGuiContext*, ImGuiViewport*, ImGuiPlatformImeData* data) -> void { ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData(); if (data->WantVisible) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1d37496b5..5f957e7f0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -130,6 +130,7 @@ Other changes: - Backends: Vulkan: fixed validation errors in window create/resize helpers used by examples and by multi-viewports implementation, which would typically trigger errors while detaching secondary viewports. (#8600, #8176) [@ChrisTom-94] +- Examples: Apple+Metal, Apple+OpenGL: add Makefile (CLion opens them nicely). (#8637) [@pthom] - Examples: DirectX12+Win32: also test for IsIconic() for sleeping since we don't seem to get a DXGI_STATUS_OCCLUDED signal when minimized. (#8603) [@dooann] diff --git a/examples/example_apple_metal/Makefile b/examples/example_apple_metal/Makefile index a15fc431c..9412c9b53 100644 --- a/examples/example_apple_metal/Makefile +++ b/examples/example_apple_metal/Makefile @@ -1,25 +1,21 @@ # Makefile for example_apple_metal, for macOS only (**not iOS**) -TARGET := example_apple_metal -CXX := clang++ -CXXFLAGS := -std=c++17 -ObjC++ -fobjc-arc -Wall -Wextra \ - -I../../ \ - -I../../backends -FRAMEWORKS := -framework AppKit -framework Metal -framework MetalKit -framework QuartzCore -framework GameController -IMGUI_SRC := ../../imgui.cpp ../../imgui_draw.cpp ../../imgui_demo.cpp \ - ../../imgui_tables.cpp ../../imgui_widgets.cpp -BACKENDS := ../../backends/imgui_impl_metal.mm ../../backends/imgui_impl_osx.mm -SRC := main.mm $(IMGUI_SRC) $(BACKENDS) +CXX = clang++ +EXE = example_apple_metal +IMGUI_DIR = ../../ +SOURCES = main.mm +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_osx.mm $(IMGUI_DIR)/backends/imgui_impl_metal.mm -.PHONY: all run clean +CXXFLAGS = -std=c++11 -ObjC++ -fobjc-arc -Wall -Wextra -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends +FRAMEWORKS = -framework AppKit -framework Metal -framework MetalKit -framework QuartzCore -framework GameController +all: $(EXE) -all: $(TARGET) - -$(TARGET): $(SRC) +$(EXE): $(SOURCES) $(CXX) $(CXXFLAGS) $^ $(FRAMEWORKS) -o $@ run: all - ./$(TARGET) + ./$(EXE) clean: - rm -f $(TARGET) *.o + rm -f $(EXE) *.o diff --git a/examples/example_apple_opengl2/Makefile b/examples/example_apple_opengl2/Makefile index 02b4fba58..4ad5fa692 100644 --- a/examples/example_apple_opengl2/Makefile +++ b/examples/example_apple_opengl2/Makefile @@ -1,25 +1,21 @@ -IMGUI_DIR = ../../ +# Makefile for example_apple_metal, for macOS only (**not iOS**) CXX = clang++ -CXXFLAGS = -std=c++17 -ObjC++ -Wall -Wextra -g -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends +EXE = example_apple_opengl2 +IMGUI_DIR = ../../ +SOURCES = main.mm +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_osx.mm $(IMGUI_DIR)/backends/imgui_impl_opengl2.cpp + +CXXFLAGS = -std=c++11 -ObjC++ -fobjc-arc -Wall -Wextra -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends FRAMEWORKS = -framework Cocoa -framework OpenGL -framework GameController -SOURCES = \ - main.mm \ - $(IMGUI_DIR)/backends/imgui_impl_osx.mm \ - $(IMGUI_DIR)/backends/imgui_impl_opengl2.cpp \ - $(IMGUI_DIR)/imgui.cpp \ - $(IMGUI_DIR)/imgui_draw.cpp \ - $(IMGUI_DIR)/imgui_demo.cpp \ - $(IMGUI_DIR)/imgui_tables.cpp \ - $(IMGUI_DIR)/imgui_widgets.cpp +all: $(EXE) -TARGET = imgui_example_apple_opengl2 +$(EXE): $(SOURCES) + $(CXX) $(CXXFLAGS) $(SOURCES) -o $(EXE) $(FRAMEWORKS) -all: $(TARGET) - -$(TARGET): $(SOURCES) - $(CXX) $(CXXFLAGS) $(SOURCES) -o imgui_example_apple_opengl2 $(FRAMEWORKS) +run: all + ./$(EXE) clean: - rm -f $(TARGET) - rm -rf $(TARGET).dSYM + rm -f $(EXE) *.o