MacOS Catalina 从源码构建Qt6.2开发库之01: 编译Qt6.2源代码

安装xcode, cmake, ninja

brew install node

mac下安装OpenGL库并使之对各项目可见

在macOS上安装OpenGL通常涉及到安装一些依赖库,如MGL、GLUT或者是GLEW等,同时确保LLVM的OpenGL框架和相关工具链的兼容性。以下是一个基本的安装步骤,你可以在终端中执行:

  1. 安装 Homebrew (如果还没有安装的话):
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  2. 安装 MGL (Mac上的OpenGL开发库):
    brew install mgl
  3. 安装 GLUT (OpenGL Utility Toolkit):
    brew install freeglut

对于较旧的系统,你可能需要安装GLUT的较旧版本:
brew install freeglut --with-contrib
7.
8. 安装 GLEW (OpenGL Extension Wrangler Library):
brew install glew
9.
10. 配置你的项目
每个步骤之后,确保你的工作目录下有相应的头文件和库文件路径。你可以通过在.pro文件(对于Qt项目)或适当的地方设置C_INCLUDE_PATH和LIBRARY_PATH环境变量来设置路径。
11. 添加环境变量
export CPPFLAGS="-I/usr/local/opt/glew/include"
12. export LDFLAGS="-L/usr/local/opt/glew/lib"
13.

复制代码
如果你需要重复使用这些环境变量,可以将它们添加到你的.bash_profile或.zshrc文件中。
  1. 编译和链接你的程序
    在编译和链接你的OpenGL程序时,确保你的构建系统(如CMake、Makefile或IDE)能够找到这些库和头文件。

解压qt-everywhere-src-6.2.0.tar.xz到/Volumes/MacOS/Program/, 将目录名改为qt6.2.0

终端窗口进入/Volumes/MacOS/Program/qt6.2.0/,执行:

./configure

用CMake打开项目,设置安装目录为/us r/local

cmake ---build . ---parallel

修改 下面的 文件,明确链接OpenGL:

/Volumes/MacOS/Program/qt6.2.0/qtbase/src/plugins/platforms/cocoa/CMakeLists.txt

Generated from cocoa.pro.

special case:

#####################################################################

QCocoaIntegrationPlugin Plugin:

#####################################################################

找到 OpenGL 库

find_package(OpenGL REQUIRED)

qt_internal_add_plugin(QCocoaIntegrationPlugin

OUTPUT_NAME qcocoa

DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES cocoa # special case

PLUGIN_TYPE platforms

SOURCES

main.mm

qcocoaapplication.h qcocoaapplication.mm

qcocoaapplicationdelegate.h qcocoaapplicationdelegate.mm

qcocoabackingstore.h qcocoabackingstore.mm

qcocoaclipboard.h qcocoaclipboard.mm

qcocoacolordialoghelper.h qcocoacolordialoghelper.mm

qcocoacursor.h qcocoacursor.mm

qcocoadrag.h qcocoadrag.mm

qcocoaeventdispatcher.h qcocoaeventdispatcher.mm

qcocoafiledialoghelper.h qcocoafiledialoghelper.mm

qcocoafontdialoghelper.h qcocoafontdialoghelper.mm

qcocoahelpers.h qcocoahelpers.mm

qcocoainputcontext.h qcocoainputcontext.mm

qcocoaintegration.h qcocoaintegration.mm

qcocoaintrospection.h qcocoaintrospection.mm

qcocoamenu.h qcocoamenu.mm

qcocoamenubar.h qcocoamenubar.mm

qcocoamenuitem.h qcocoamenuitem.mm

qcocoamenuloader.h qcocoamenuloader.mm

qcocoamimetypes.h qcocoamimetypes.mm

qcocoanativeinterface.h qcocoanativeinterface.mm

qcocoansmenu.h qcocoansmenu.mm

qcocoascreen.h qcocoascreen.mm

qcocoaservices.h qcocoaservices.mm

qcocoasystemtrayicon.h qcocoasystemtrayicon.mm

qcocoatheme.h qcocoatheme.mm

qcocoawindow.h qcocoawindow.mm

qcocoawindowmanager.h qcocoawindowmanager.mm

qiosurfacegraphicsbuffer.h qiosurfacegraphicsbuffer.mm

qmacclipboard.h qmacclipboard.mm

qmultitouch_mac.mm qmultitouch_mac_p.h

qnsview.h qnsview.mm

qnswindow.h qnswindow.mm

qnswindowdelegate.h qnswindowdelegate.mm

qcocoacolordialoghelper.h qcocoacolordialoghelper.mm

qcocoafiledialoghelper.h qcocoafiledialoghelper.mm

qcocoafontdialoghelper.h qcocoafontdialoghelper.mm

DEFINES

QT_NO_FOREACH

LIBRARIES

${FWAppKit}

${FWCarbon}

${FWCoreServices}

${FWCoreVideo}

${FWIOKit}

${FWIOSurface}

${FWMetal}

${FWQuartzCore}

Qt::Core

Qt::CorePrivate

Qt::Gui

Qt::GuiPrivate

OpenGL::GL # 添加 OpenGL 库链接

)

special case begin

qt_disable_apple_app_extension_api_only(QCocoaIntegrationPlugin)

special case end

Resources:

set(qcocoaresources_resource_files

"images/sizeallcursor.png"

"images/spincursor.png"

"images/waitcursor.png"

)

qt_internal_add_resource(QCocoaIntegrationPlugin "qcocoaresources"

PREFIX

"/qt-project.org/mac/cursors"

FILES

${qcocoaresources_resource_files}

)

Keys ignored in scope 1:.:.:cocoa.pro:<TRUE>:

OTHER_FILES = "cocoa.json"

Scopes:

#####################################################################

qt_internal_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_opengl

SOURCES

qcocoaglcontext.h qcocoaglcontext.mm

LIBRARIES

OpenGL::GL # 添加OpenGL库

)

qt_internal_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_vulkan

SOURCES

qcocoavulkaninstance.h qcocoavulkaninstance.mm

LIBRARIES

OpenGL::GL # 添加OpenGL库

)

qt_internal_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_accessibility

SOURCES

qcocoaaccessibility.h qcocoaaccessibility.mm

qcocoaaccessibilityelement.h qcocoaaccessibilityelement.mm

LIBRARIES

OpenGL::GL # 添加OpenGL库

)

qt_internal_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_sessionmanager

SOURCES

qcocoasessionmanager.cpp qcocoasessionmanager.h

LIBRARIES

OpenGL::GL # 添加OpenGL库

)

Keys ignored in scope 7:.:.:cocoa.pro:TARGET Qt::Widgets:

QT_FOR_CONFIG = "widgets"

Keys ignored in scope 12:.:.:cocoa.pro:NOT TARGET___equals____ss_QT_DEFAULT_QPA_PLUGIN:

PLUGIN_EXTENDS = "-"

/Volumes/MacOS/Program/qt=6.2.0/qtbase/src/opengl/CMakeLists.txt

Generated from opengl.pro.

#####################################################################

OpenGL Module:

#####################################################################

qt_internal_add_module(OpenGL

SOURCES

qopengl2pexvertexarray.cpp qopengl2pexvertexarray_p.h

qopenglbuffer.cpp qopenglbuffer.h

qopenglcustomshaderstage.cpp qopenglcustomshaderstage_p.h

qopengldebug.cpp qopengldebug.h

qopenglengineshadermanager.cpp qopenglengineshadermanager_p.h

qopenglengineshadersource_p.h

qopenglframebufferobject.cpp qopenglframebufferobject.h qopenglframebufferobject_p.h

qopenglgradientcache.cpp qopenglgradientcache_p.h

qopenglpaintdevice.cpp qopenglpaintdevice.h qopenglpaintdevice_p.h

qopenglpaintengine.cpp qopenglpaintengine_p.h

qopenglpixeltransferoptions.cpp qopenglpixeltransferoptions.h

qopenglshadercache_p.h

qopenglshaderprogram.cpp qopenglshaderprogram.h

qopengltexture.cpp qopengltexture.h qopengltexture_p.h

qopengltextureblitter.cpp qopengltextureblitter.h

qopengltexturecache.cpp qopengltexturecache_p.h

qopengltextureglyphcache.cpp qopengltextureglyphcache_p.h

qopengltexturehelper.cpp qopengltexturehelper_p.h

qopengltextureuploader.cpp qopengltextureuploader_p.h

qopenglversionfunctions.cpp qopenglversionfunctions.h qopenglversionfunctions_p.h

qopenglversionfunctionsfactory.cpp qopenglversionfunctionsfactory.h

qopenglversionprofile.cpp qopenglversionprofile.h

qopenglvertexarrayobject.cpp qopenglvertexarrayobject.h

qopenglwindow.cpp qopenglwindow.h

qplatformbackingstoreopenglsupport.cpp qplatformbackingstoreopenglsupport.h

qtopenglglobal.h

DEFINES

QT_NO_FOREACH

QT_NO_USING_NAMESPACE

LIBRARIES

Qt::CorePrivate

Qt::GuiPrivate

PUBLIC_LIBRARIES

Qt::Core

Qt::Gui

PRIVATE_MODULE_INTERFACE

Qt::CorePrivate

Qt::GuiPrivate

)

Scopes:

#####################################################################

qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_opengles2

SOURCES

qopenglfunctions_es2.cpp qopenglfunctions_es2.h

)

qt_internal_extend_target(OpenGL CONDITION NOT QT_FEATURE_opengles2

SOURCES

qopenglfunctions_1_0.cpp qopenglfunctions_1_0.h

qopenglfunctions_1_1.cpp qopenglfunctions_1_1.h

qopenglfunctions_1_2.cpp qopenglfunctions_1_2.h

qopenglfunctions_1_3.cpp qopenglfunctions_1_3.h

qopenglfunctions_1_4.cpp qopenglfunctions_1_4.h

qopenglfunctions_1_5.cpp qopenglfunctions_1_5.h

qopenglfunctions_2_0.cpp qopenglfunctions_2_0.h

qopenglfunctions_2_1.cpp qopenglfunctions_2_1.h

qopenglfunctions_3_0.cpp qopenglfunctions_3_0.h

qopenglfunctions_3_1.cpp qopenglfunctions_3_1.h

qopenglfunctions_3_2_compatibility.cpp qopenglfunctions_3_2_compatibility.h

qopenglfunctions_3_2_core.cpp qopenglfunctions_3_2_core.h

qopenglfunctions_3_3_compatibility.cpp qopenglfunctions_3_3_compatibility.h

qopenglfunctions_3_3_core.cpp qopenglfunctions_3_3_core.h

qopenglfunctions_4_0_compatibility.cpp qopenglfunctions_4_0_compatibility.h

qopenglfunctions_4_0_core.cpp qopenglfunctions_4_0_core.h

qopenglfunctions_4_1_compatibility.cpp qopenglfunctions_4_1_compatibility.h

qopenglfunctions_4_1_core.cpp qopenglfunctions_4_1_core.h

qopenglfunctions_4_2_compatibility.cpp qopenglfunctions_4_2_compatibility.h

qopenglfunctions_4_2_core.cpp qopenglfunctions_4_2_core.h

qopenglfunctions_4_3_compatibility.cpp qopenglfunctions_4_3_compatibility.h

qopenglfunctions_4_3_core.cpp qopenglfunctions_4_3_core.h

qopenglfunctions_4_4_compatibility.cpp qopenglfunctions_4_4_compatibility.h

qopenglfunctions_4_4_core.cpp qopenglfunctions_4_4_core.h

qopenglfunctions_4_5_compatibility.cpp qopenglfunctions_4_5_compatibility.h

qopenglfunctions_4_5_core.cpp qopenglfunctions_4_5_core.h

qopenglqueryhelper_p.h

qopengltimerquery.cpp qopengltimerquery.h

LIBRARIES

OpenGL::GL # 添加 OenGL 库

)

qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_vulkan

SOURCES

qvkconvenience.cpp qvkconvenience_p.h

LIBRARIES

OpenGL::GL # 添加 OenGL 库

)

if(QT_FEATURE_vulkan)

qt_internal_add_target_include_dirs_and_optionally_propagate(

OpenGL WrapVulkanHeaders::WrapVulkanHeaders)

endif()

qt_internal_extend_target(OpenGL CONDITION QT_FEATURE_egl

SOURCES

qopenglcompositor.cpp qopenglcompositor_p.h

qopenglcompositorbackingstore.cpp qopenglcompositorbackingstore_p.h

LIBRARIES

OpenGL::GL # 添加 OenGL 库

)

qt_internal_create_tracepoints(OpenGL qtopengl.tracepoints)

qt_internal_add_docs(OpenGL

doc/qtopengl.qdocconf

)

终端窗口进入/Volumes/MacOS/Program/qt6.2.0/,执行:

cmake ---build . ---parallel

发现报错:

In file included from ../../../3rdparty/chromium/content/public/browser/browser_accessibility_state.h:12:

../../../3rdparty/chromium/content/public/browser/browser_context.h:21:10: fatal error: 'components/spellcheck/spellcheck_buildflags.h' file not found

#include "components/spellcheck/spellcheck_buildflags.h"

文件缺失:qt-6.2.0/qtwebengine/src/3rdparty/chromium/components/spellcheck/spellcheck_buildflags.h

手工创建该文件,写入内容

#define ENABLE_SPELLCHCEK 0

#define BUILDFLAG_INTERNAL_ENABLE_SPELLCHECK 0

修改文件browser_context.h第352行如下

//#if defined(TOOLKIT_QT) && BUILDFLAG(ENABLE_SPELLCHECK)

#if defined(TOOLKIT_QT)

// Inform about not working dictionary for given language

virtual void FailedToLoadDictionary(const std::string& language) = 0;

#endif

最后执行

cmake ---build . ---parallel

cmake --install .

相关推荐
浪客灿心10 分钟前
项目篇:模块设计与实现
数据库·c++
牛油果子哥q23 分钟前
【C++ STL vector】C++ STL vector 终极精讲:动态数组底层原理、两倍扩容机制、迭代器失效、增删查改、性能剖析与工程避坑指南
开发语言·c++
为何创造硅基生物2 小时前
独占指针的创建std::make_unique 本身自带堆出现
c++
kyle~2 小时前
ROS 2 与 Isaac Sim 联合仿真(一)体系架构、环境选型与基础通信闭环
c++·机器人·nvidia·仿真·ros2
努力努力再努力wz3 小时前
【内存管理与高并发内存池系列】从 mmap 到 malloc:文件映射、匿名映射与 glibc 内存分配机制详解
linux·c语言·数据结构·数据库·c++·qt·链表
八解毒剂3 小时前
数据结构-平衡二叉树——对二叉搜索树的优化
数据结构·c++·算法
JdSnE27zv3 小时前
Qt 操作SQLite数据库
数据库·qt·sqlite
ryanuo73 小时前
Mac(M芯片)上进行嵌入式开发遇到的问题
嵌入式硬件·macos·开发板
起床困难户5754 小时前
条款20:协助完成返回值优化
c++
啦啦啦啦啦zzzz4 小时前
算法总结(二分查找、双指针)
c++·算法