freetype-2.13.3-windows编译

        本文操作按照《c&c++开源库编译指南》中内容规范编写,编译环境配置、工具下载、目录规划,及更多其他开源库编译方法请参考该文章。

        c&c++开源库编译指南:https://blog.youkuaiyun.com/binary0006/article/details/144086155

        本文章中的源代码已提交到gitee仓库,地址:https://gitee.com/binary0010/depends/tree/master/c/freetype-2.13.3

1.freetype 概述

        FreeType 是一款开源的跨平台字体渲染引擎,支持 TrueType、OpenType、PostScript 等多种字体格式,提供高质量的字形渲染、抗锯齿、提示(hinting)及布局处理能力。其模块化设计允许开发者灵活集成,编译时支持多平台(Windows/Linux/macOS/Android/iOS)及编译器(GCC/Clang/MSVC),依赖项轻量(仅需 zlib 或 freetype),可生成静态 / 动态库适配不同项目需求。

        该引擎广泛应用于图形库(如 SDL、Qt)、浏览器(Chrome、Firefox)、操作系统(Linux 字体渲染)及游戏引擎(Unity、Unreal)中,用于实现文本的高效渲染与排版。基于 BSD 许可开源,代码托管于 GitHub,社区维护活跃且文档完善,典型用户包括 Adobe、Mozilla 等技术公司,以及 LibreOffice、Inkscape 等开源项目。

2.freetype编译

2.1.源代码下载

        从freetype官网https://freetype.org/index.html看到当前2.13.3版本,源代码下载地址:https://download.savannah.gnu.org/releases/freetype/,找到最新版2.13.3版本,点击下图所示链接直接下载即可。

         也可以自己复制这个地址下载:https://download.savannah.gnu.org/releases/freetype/freetype-2.13.3.tar.gz

2.2.windows编译

        先解压源代码到指定目录,freetype源代码中已经提供了CMakeList.txt脚本,后面我们按照规范会对该脚本进行修改。

2.2.1.修改CMake脚本 

        修改CMake脚本按照我们的设计的编译规范来进行构建和编译,修改源代码根目录下的CMakeLists.txt即可。

        脚本涉及的内容主要是使用我们编译规范来对工程命名和输出,以及mt工程的链接库设置。freetype可选依赖zlib、bizp2、png、brotli、harfbuzz,之前已经按照规范编译了zlib、bizp2、png、brotli,由于harfbuzz在vs2008下无法编译通过,在CMakeLists.txt脚本的修改中不会涉及到harfbuzz相关内容。

        CMakeLists.txt完整内容:

# CMakeLists.txt
#
# Copyright (C) 2013-2024 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# Written originally by John Cary <cary@txcorp.com>
#
# This file is part of the FreeType project, and may only be used, modified,
# and distributed under the terms of the FreeType project license,
# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
# indicate that you have read the license and understand and accept it
# fully.
#
#
# The following will (1) create a build directory, and (2) change into it and
# call cmake to configure the build with default parameters as a static
# library.  See
#
# https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
#
# for information about debug or release builds, for example
#
# cmake -B build -D CMAKE_BUILD_TYPE=Release
#
#
# For a dynamic library, use
#
# cmake -B build -D BUILD_SHARED_LIBS=true -D CMAKE_BUILD_TYPE=Release
#
# For a framework on OS X, use
#
# cmake -E chdir build cmake -G Xcode -D BUILD_FRAMEWORK:BOOL=true ..
#
# For an iOS static library, use
#
# cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=OS ..
#
# or
#
# cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=SIMULATOR ..
#
# or
#
# cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=SIMULATOR64 ..
#
#
# Finally, build the project with
#
# cmake --build build
#
# Install it with
#
# (sudo) cmake --build build --target install
#
# A binary distribution can be made with
#
# cmake --build build --config Release --target package
#
# Please refer to the cmake manual for further options, in particular, how
# to modify compilation and linking parameters.
#
# Some notes.
#
# - Say `cmake -LAH` to see all configuration options.
#
# - `cmake' creates configuration files in
#
# <build-directory>/include/freetype/config
#
# which should be further modified if necessary.
#
# - You can use `cmake' directly on a freshly cloned FreeType git
# repository.
#
# - `CMakeLists.txt' is provided as-is since it is normally not used by the
# developer team.
#
# - Set the `FT_REQUIRE_ZLIB', `FT_REQUIRE_freetype', `FT_REQUIRE_PNG',
# `FT_REQUIRE_HARFBUZZ', and `FT_REQUIRE_BROTLI' CMake variables to `ON'
# or `TRUE' to force using a dependency.  Leave a variable undefined
# (which is the default) to use the dependency only if it is available.
# Example:
#
# cmake -B build -D FT_REQUIRE_ZLIB=TRUE \
# -D FT_REQUIRE_freetype=TRUE \
# -D FT_REQUIRE_PNG=TRUE \
# -D FT_REQUIRE_HARFBUZZ=TRUE \
# -D FT_REQUIRE_BROTLI=TRUE [...]
#
# - Set `FT_DISABLE_XXX=TRUE' to disable a dependency completely (where
# `XXX' is a CMake package name like `freetype').  Example for disabling all
# dependencies:
#
# cmake -B build -D FT_DISABLE_ZLIB=TRUE \
# -D FT_DISABLE_freetype=TRUE \
# -D FT_DISABLE_PNG=TRUE \
# -D FT_DISABLE_HARFBUZZ=TRUE \
# -D FT_DISABLE_BROTLI=TRUE [...]
#
# - NOTE: If a package is set as DISABLED, it cannot be set as REQUIRED
# without unsetting the DISABLED value first.  For example, if
# `FT_DISABLE_HARFBUZZ=TRUE' has been set (Cache is present), you need to
# call `FT_DISABLE_HARFBUZZ=FALSE' before calling
# `FT_REQUIRE_HARFBUZZ=TRUE'.
#
# - Installation of FreeType can be controlled with the CMake variables
# `SKIP_INSTALL_HEADERS', `SKIP_INSTALL_LIBRARIES', and `SKIP_INSTALL_ALL'
# (this is compatible with the same CMake variables in zlib's CMake
# support).

# To minimize the number of cmake_policy() workarounds,
# CMake >= 3 is requested.
cmake_minimum_required(VERSION 3.0...3.15)

if(NOT CMAKE_VERSION VERSION_LESS 3.3)
  # Allow symbol visibility settings also on static libraries. CMake < 3.3
  # only sets the property on a shared library build.
  cmake_policy(SET CMP0063 NEW)

  # Support new IN_LIST if() operator.
  cmake_policy(SET CMP0057 NEW)
endif()

include(CheckIncludeFile)
include(CMakeDependentOption)

# CMAKE_TOOLCHAIN_FILE must be set before `project' is called, which
# configures the base build environment and references the toolchain file
if(APPLE)
  if(DEFINED IOS_PLATFORM)
    if(NOT "${IOS_PLATFORM}" STREQUAL "OS"
      AND NOT "${IOS_PLATFORM}" STREQUAL "SIMULATOR"
      AND NOT "${IOS_PLATFORM}" STREQUAL "SIMULATOR64")
      message(FATAL_ERROR
        "IOS_PLATFORM must be set to either OS, SIMULATOR, or SIMULATOR64")
    endif()

    if(NOT "${CMAKE_GENERATOR}" STREQUAL "Xcode")
      message(AUTHOR_WARNING
        "You should use Xcode generator with IOS_PLATFORM enabled to get Universal builds.")
    endif()

    if(BUILD_SHARED_LIBS)
      message(FATAL_ERROR
        "BUILD_SHARED_LIBS can not be on with IOS_PLATFORM enabled")
    endif()

    if(BUILD_FRAMEWORK)
      message(FATAL_ERROR
        "BUILD_FRAMEWORK can not be on with IOS_PLATFORM enabled")
    endif()

    # iOS only uses static libraries
    set(BUILD_SHARED_LIBS OFF)

    set(CMAKE_TOOLCHAIN_FILE
      ${CMAKE_SOURCE_DIR}/builds/cmake/iOS.cmake)
  endif()
else()
  if(DEFINED IOS_PLATFORM)
    message(FATAL_ERROR "IOS_PLATFORM is not supported on this platform")
  endif()
endif()

project(freetype C)

set(VERSION_MAJOR "2")
set(VERSION_MINOR "13")
set(VERSION_PATCH "3")

# Generate LIBRARY_VERSION and LIBRARY_SOVERSION.
set(LIBTOOL_REGEX "version_info='([0-9]+):([0-9]+):([0-9]+)'")
file(STRINGS "${PROJECT_SOURCE_DIR}/builds/unix/configure.raw"
  VERSION_INFO
  REGEX ${LIBTOOL_REGEX})
string(REGEX REPLACE
  ${LIBTOOL_REGEX} "\\1"
  LIBTOOL_CURRENT "${VERSION_INFO}")
string(REGEX REPLACE
  ${LIBTOOL_REGEX} "\\2"
  LIBTOOL_REVISION "${VERSION_INFO}")
string(REGEX REP
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

binary0010

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值