From 3782a0cadc5c3eaa924f62d4d5d42eff5049f772 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Thu, 30 Jul 2026 09:33:57 +0000 Subject: [PATCH] cmake: allow Cocoa with GCC, OpenGL interop with Cocoa, PPC flags opt-out - HAVE_COCOA no longer requires clang: window_cocoa.mm now builds with GCC's Objective-C++ frontend. - Allow WITH_OPENGL with the Cocoa backend (unless Qt is the GUI): this enables cv::ogl interoperability in core; OpenGL windows remain unimplemented in the Cocoa backend (stubs raise OpenGlNotSupported). - Do not force -mcpu=G3 -mtune=G5 on PowerPC when the user already passed -mcpu=/-mtune= in their flags. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01NmeP4C25nM6MhcEXEpT6Ae --- cmake/OpenCVCompilerOptimizations.cmake | 5 ++++- cmake/OpenCVFindLibsGUI.cmake | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cmake/OpenCVCompilerOptimizations.cmake b/cmake/OpenCVCompilerOptimizations.cmake index 64da33d..53c2bf4 100644 --- a/cmake/OpenCVCompilerOptimizations.cmake +++ b/cmake/OpenCVCompilerOptimizations.cmake @@ -697,7 +697,10 @@ macro(ocv_compiler_optimization_options) endforeach() if(ENABLE_POWERPC) - add_extra_compiler_option("-mcpu=G3 -mtune=G5") + # Do not override CPU tuning explicitly requested by the user + if(NOT "${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES "-m(cpu|tune)=") + add_extra_compiler_option("-mcpu=G4 -mtune=G5") + endif() endif() endmacro() diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 735aae3..6a20de3 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -59,11 +59,20 @@ if(WITH_QT) endif() endif() +# --- Cocoa --- +if(APPLE) + if(NOT IOS AND NOT XROS AND (CV_CLANG OR CV_GCC)) + set(HAVE_COCOA YES) + endif() +endif() + # --- OpenGl --- +# With the Cocoa backend OpenGL windows are not implemented, but enabling +# OpenGL still provides cv::ogl interoperability in the core module. ocv_update(OpenGL_GL_PREFERENCE LEGACY) ocv_clear_vars(HAVE_OPENGL HAVE_QT_OPENGL) if(WITH_OPENGL) - if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR HAVE_GTK3 OR (HAVE_GTK AND NOT HAVE_GTK3 AND HAVE_GTKGLEXT)) + if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR HAVE_GTK3 OR (HAVE_GTK AND NOT HAVE_GTK3 AND HAVE_GTKGLEXT) OR (HAVE_COCOA AND NOT HAVE_QT)) find_package (OpenGL QUIET) if(OPENGL_FOUND) set(HAVE_OPENGL TRUE) @@ -75,10 +84,3 @@ if(WITH_OPENGL) endif() endif() endif(WITH_OPENGL) - -# --- Cocoa --- -if(APPLE) - if(NOT IOS AND NOT XROS AND CV_CLANG) - set(HAVE_COCOA YES) - endif() -endif()