Skip to content

Commit e994532

Browse files
committed
fix: Qt build on macOS 26 caused by AGL lib missing
1 parent 6fe49c0 commit e994532

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

ThirdParty/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
267267
set(QT_LIB_PREFIX ${Qt_SOURCE_DIR}/${QT_VERSION}/msvc2022_64 CACHE PATH "" FORCE)
268268
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
269269
set(QT_LIB_PREFIX ${Qt_SOURCE_DIR}/${QT_VERSION}/macos CACHE PATH "" FORCE)
270+
271+
# NOTICE: Fix Qt 6.9.1 build on macOS 26, #see https://codereview.qt-project.org/c/qt/qtbase/+/652022/3/cmake/FindWrapOpenGL.cmake#b50
272+
if (QT_VERSION STREQUAL "6.9.1")
273+
file(COPY_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Patch/Qt-Darwin-6.9.1-FindWrapOpenGL.cmake ${QT_LIB_PREFIX}/lib/cmake/Qt6/FindWrapOpenGL.cmake)
274+
endif ()
270275
endif ()
271276

272277
# rapidjson
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (C) 2022 The Qt Company Ltd.
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
# We can't create the same interface imported target multiple times, CMake will complain if we do
5+
# that. This can happen if the find_package call is done in multiple different subdirectories.
6+
if(TARGET WrapOpenGL::WrapOpenGL)
7+
set(WrapOpenGL_FOUND ON)
8+
return()
9+
endif()
10+
11+
set(WrapOpenGL_FOUND OFF)
12+
13+
find_package(OpenGL ${WrapOpenGL_FIND_VERSION})
14+
15+
if (OpenGL_FOUND)
16+
set(WrapOpenGL_FOUND ON)
17+
18+
add_library(WrapOpenGL::WrapOpenGL INTERFACE IMPORTED)
19+
if(APPLE)
20+
# CMake 3.27 and older:
21+
# On Darwin platforms FindOpenGL sets IMPORTED_LOCATION to the absolute path of the library
22+
# within the framework. This ends up as an absolute path link flag, which we don't want,
23+
# because that makes our .prl files un-relocatable.
24+
# Extract the framework path instead, and use that in INTERFACE_LINK_LIBRARIES,
25+
# which CMake ends up transforming into a relocatable -framework flag.
26+
# See https://gitlab.kitware.com/cmake/cmake/-/issues/20871 for details.
27+
#
28+
# CMake 3.28 and above:
29+
# IMPORTED_LOCATION is the absolute path the the OpenGL.framework folder.
30+
get_target_property(__opengl_fw_lib_path OpenGL::GL IMPORTED_LOCATION)
31+
if(__opengl_fw_lib_path AND NOT __opengl_fw_lib_path MATCHES "/([^/]+)\\.framework$")
32+
get_filename_component(__opengl_fw_path "${__opengl_fw_lib_path}" DIRECTORY)
33+
endif()
34+
35+
if(NOT __opengl_fw_path)
36+
# Just a safety measure in case if no OpenGL::GL target exists.
37+
set(__opengl_fw_path "-framework OpenGL")
38+
endif()
39+
40+
target_link_libraries(WrapOpenGL::WrapOpenGL INTERFACE ${__opengl_fw_path})
41+
else()
42+
target_link_libraries(WrapOpenGL::WrapOpenGL INTERFACE OpenGL::GL)
43+
endif()
44+
elseif(UNIX AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Integrity")
45+
# Requesting only the OpenGL component ensures CMake does not mark the package as
46+
# not found if neither GLX nor libGL are available. This allows finding OpenGL
47+
# on an X11-less Linux system.
48+
find_package(OpenGL ${WrapOpenGL_FIND_VERSION} COMPONENTS OpenGL)
49+
if (OpenGL_FOUND)
50+
set(WrapOpenGL_FOUND ON)
51+
add_library(WrapOpenGL::WrapOpenGL INTERFACE IMPORTED)
52+
target_link_libraries(WrapOpenGL::WrapOpenGL INTERFACE OpenGL::OpenGL)
53+
endif()
54+
endif()
55+
56+
include(FindPackageHandleStandardArgs)
57+
find_package_handle_standard_args(WrapOpenGL DEFAULT_MSG WrapOpenGL_FOUND)

0 commit comments

Comments
 (0)