Skip to content

ci: use submodules for freetype #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
run: |
set -x
sudo apt-get update
sudo apt-get -y -q --no-install-recommends install zlib1g-dev libncursesw5-dev libgeoip-dev nettle-dev libgmp-dev libcurl4-gnutls-dev libsdl2-dev libogg-dev libvorbis-dev libopusfile-dev libwebp-dev libjpeg8-dev libpng-dev libfreetype6-dev libglew-dev libopenal-dev ninja-build
sudo apt-get -y -q --no-install-recommends install zlib1g-dev libncursesw5-dev libgeoip-dev nettle-dev libgmp-dev libcurl4-gnutls-dev libsdl2-dev libogg-dev libvorbis-dev libopusfile-dev libwebp-dev libjpeg8-dev libpng-dev libglew-dev libopenal-dev ninja-build
git submodule update --init --recursive

curl -sS https://gitlab.com/illwieckz/git-checkout-modules/raw/master/git-checkout-modules -o ~/git-checkout-modules
Expand Down
21 changes: 12 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -775,19 +775,23 @@ if (USE_BREAKPAD)
endif()
endif()

option(PREFER_EXTERNAL_LIBS "Tries to use system libs where possible." ON)
option(PREFER_EXTERNAL_LIBS "Tries to use system libs where possible." OFF)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be changed because Unvanquished doesn't even build in the default configuration that way (it defines the Freetype lib twice).

Copy link
Member Author

@illwieckz illwieckz Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Freetype submodule double build bug is now fixed.

When building both the engine and a native game, the native game now reuses the Freetype target already sets by the engine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Freetype submodule double build bug is now fixed.

Great!

What's the motivation for the change though? It makes builds longer and people building Daemon themselves can no longer benefit from distro security updates.


macro(prefer_package LIB_NAME LIB_CMAKE)
if (PREFER_EXTERNAL_LIBS AND NOT NACL)
find_package(${LIB_NAME})
if (NOT ${LIB_NAME}_FOUND)
if (PREFER_EXTERNAL_LIBS AND NOT NACL)
find_package(${LIB_NAME})

if (NOT ${LIB_NAME}_FOUND)
message(WARNING "PREFER_EXTERNAL_LIBS is enabled but external ${LIB_NAME} is not found, falling back to vendored ${LIB_NAME}.")
if (NOT ${LIB_NAME}_FOUND)
message(WARNING "PREFER_EXTERNAL_LIBS is enabled but external ${LIB_NAME} is not found, falling back to vendored ${LIB_NAME}.")
endif()
endif()
endif()

if (NOT ${LIB_NAME}_FOUND)
include(${LIB_CMAKE})
if (NOT ${LIB_NAME}_FOUND)
include(${LIB_CMAKE})

set(${LIB_NAME}_FOUND ON)
endif()
endif()
endmacro()

Expand Down Expand Up @@ -817,7 +821,6 @@ if (BUILD_CLIENT)
set(LIBS_CLIENT ${LIBS_CLIENT} ${PNG_LIBRARIES})

prefer_package(Freetype ${DAEMON_DIR}/freetype.cmake)

include_directories(${FREETYPE_INCLUDE_DIRS})
set(LIBS_CLIENT ${LIBS_CLIENT} ${FREETYPE_LIBRARIES})

Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
- bash: |
set -e
sudo apt-get update
sudo apt-get -y -q --no-install-recommends install zlib1g-dev libncursesw5-dev libgeoip-dev nettle-dev libgmp-dev libcurl4-gnutls-dev libsdl2-dev libogg-dev libvorbis-dev libopusfile-dev libwebp-dev libjpeg8-dev libpng-dev libfreetype6-dev libglew-dev libopenal-dev liblua5.2-dev ninja-build $(EXTRA_PACKAGES)
sudo apt-get -y -q --no-install-recommends install zlib1g-dev libncursesw5-dev libgeoip-dev nettle-dev libgmp-dev libcurl4-gnutls-dev libsdl2-dev libogg-dev libvorbis-dev libopusfile-dev libwebp-dev libjpeg8-dev libpng-dev libglew-dev libopenal-dev liblua5.2-dev ninja-build $(EXTRA_PACKAGES)
$(EXTRA_INSTALLS)
displayName: 'Install deps'
- bash: |
Expand Down
4 changes: 2 additions & 2 deletions cmake/DaemonFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ else()
# Don't set _FORTIFY_SOURCE in debug builds.
endif()

try_c_cxx_flag(FPIC "-fPIC")

if (USE_HARDENING)
# PNaCl accepts the flags but does not define __stack_chk_guard and __stack_chk_fail.
if (NOT NACL)
Expand All @@ -395,8 +397,6 @@ else()
try_c_cxx_flag(WSTACK_PROTECTOR "-Wstack-protector")

if (NOT NACL OR (NACL AND GAME_PIE))
try_c_cxx_flag(FPIC "-fPIC")

# The -pie flag requires -fPIC:
# > ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
# This flag isn't used on macOS:
Expand Down
35 changes: 22 additions & 13 deletions freetype.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@ set(FREETYPE_DIR ${DAEMON_DIR}/libs/freetype)
set(FREETYPE_INCLUDE_DIRS ${FREETYPE_DIR}/include)
set(FREETYPE_LIBRARIES freetype)

option(FT_DISABLE_BROTLI "Disable Brotli" ON)
option(FT_DISABLE_BZIP2 "Disable bzip2" ON)
option(FT_DISABLE_HARFBUZZ "Disable HarfBuzz" ON)
option(FT_DISABLE_PNG "Disable PNG" ON)

if (PREFER_EXTERNAL_LIBS AND NOT NACL)
set(FREETYPE_INTERNAL_ZLIB OFF)
else()
set(FREETYPE_INTERNAL_ZLIB ON)
endif()

set(FT_DISABLE_ZLIB ${FREETYPE_INTERNAL_ZLIB} CACHE BOOL "Disable external zlib" FORCE)
if (NOT ${FREETYPE_INTERNAL_ZLIB})
find_package(ZLIB REQUIRED)
set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARIES} ${ZLIB_LIBRARIES})
endif()

# Do not re-add the target if already set to be built.
# For example both the engine and a native game may request Freetype
# to be built, but we need to only build once for both.
if (NOT TARGET freetype)
option(FT_DISABLE_BROTLI "Disable Brotli" ON)
option(FT_DISABLE_BZIP2 "Disable bzip2" ON)
option(FT_DISABLE_HARFBUZZ "Disable HarfBuzz" ON)
option(FT_DISABLE_PNG "Disable PNG" ON)
set(FT_DISABLE_ZLIB ${FREETYPE_INTERNAL_ZLIB} CACHE BOOL "Disable external zlib" FORCE)

add_subdirectory(${FREETYPE_DIR})
add_subdirectory(${FREETYPE_DIR})

mark_as_advanced(FT_DISABLE_BROTLI)
mark_as_advanced(FT_DISABLE_BZIP2)
mark_as_advanced(FT_DISABLE_HARFBUZZ)
mark_as_advanced(FT_DISABLE_PNG)
mark_as_advanced(FT_DISABLE_ZLIB)
mark_as_advanced(FT_ENABLE_ERROR_STRINGS)
mark_as_advanced(FT_DISABLE_BROTLI)
mark_as_advanced(FT_DISABLE_BZIP2)
mark_as_advanced(FT_DISABLE_HARFBUZZ)
mark_as_advanced(FT_DISABLE_PNG)
mark_as_advanced(FT_DISABLE_ZLIB)
mark_as_advanced(FT_ENABLE_ERROR_STRINGS)
endif()