- 安装 xcode
- 安装Homebrew
- Homebrew 下安装必要的软件 cmake linpng libjpeg openssl icu4c
- 编译 qt 5.7.1
- 编译 qtwebkit 5.7.1
1. 安装 xcode
- XCode - https://developer.apple.com/downloads
- XCode Command Line Tools - (after you installed XCode)
xcode-select --install
2. 安装 brew
#!/bin/sh
#
# Homebrew
#
# This installs some of the common dependencies needed (or at least desired)
# using Homebrew.
echo "Running Mac setup. This would take a while. Please sit back and relax."
# Check for Homebrew
if test ! "$(which brew)"
then
echo "Installing Homebrew for you."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# Make sure we’re using the latest Homebrew
brew update
# Upgrade any already-installed formulae
brew upgrade
3. 安装 cmake
# For buildng with Qt >= 5.10
brew install libpng libjpeg-turbo cmake
# For building with Qt < 5.10
brew install libpng libjpeg cmake
brew install ninja
brew install openssl icu4c
brew link icu4c
brew link openssl
4. 编译 Qt
cd ~/Desktop
mkdir qt5.7.1-build
cd qt5.7.1-build
vim build.sh
配置编译参数
#!/bin/sh
OPENSSL_DIR=/usr/local/opt/openssl/
../qt-everywhere-opensource-src-5.7.1/configure -shared -debug-and-release -nomake examples -nomake tests -prefix ~/Desktop/Qt/5.7.1_osx -qt-sql-sqlite -plugin-sql-sqlite -qt-pcre -opensource -confirm-license -opengl -largefile -qt-freetype -arch "X86_64" -c++std c++14 -system-zlib -system-libpng -system-libjpeg -I "/usr/local/opt/icu4c/include" -L "/usr/local/opt/icu4c/lib" -I "/usr/local/opt/openssl/include" -L "/usr/local/opt/openssl/lib" -l "crypto" -l "ssl" -openssl-linked -I "/usr/local/include" -L "/usr/local/lib"
开始编译
chomd +x ./build.sh
./build.sh
5. 编译 QtWebkit
http://download.qt.io/community_releases/5.7/5.7.1/qtwebkit-opensource-src-5.7.1.tar.gz 下载 qtwebkit-opensource-src-5.7.1.tar.gz
解压并释放到 qt-everywhere-opensource-src-5.7.1 下,改名 qtwebkit
cd qtwebkit
vim build.sh
#!/bin/sh
export PATH=$PATH:~/Desktop/Qt/5.7.1_osx/bin
echo $PATH
./Tools/Scripts/build-webkit --qt --cmakeargs="-Wno-dev -DQt5_DIR=~/Desktop/Qt/5.7.1_osx/lib/cmake/Qt5"
开始编译
chomd +x ./build.sh
./build.sh
测试例子
QT += core gui webkitwidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = webkit-01
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp
#include <QApplication>
#include <QWebView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWebView view;
view.show();
view.load(QUrl("http://www.baidu.com"));
return a.exec();
}