singe/cmake/zig/x86_64-linux-gnu.cmake
2026-09-04 22:36:58 -05:00

59 lines
3.2 KiB
CMake

#
# Singe 3
# Copyright (C) 2006-2026 Scott Duensing <scott@kangaroopunch.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public Licens
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Linux x86_64 with zig as the compiler, targeting glibc 2.28 (Debian 10, Ubuntu 18.04) so one
# release binary runs on more distributions than the build host's own glibc allows. zig supplies
# libc and its headers; the platform libraries (ALSA, X11, DRM, VA-API, VDPAU, GL) and their
# headers come from the host's development packages, searched after zig's own so the host's
# newer glibc headers never shadow the pinned ones.
include(${CMAKE_CURRENT_LIST_DIR}/zig.cmake)
set(SINGE_GLIBC_VERSION 2.28)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
# The linker may see the host's platform libraries but never its libc, libm, libpthread or gcc
# runtime, or symbols get bound to the host's newer glibc versions. A directory of links to
# everything else under the host's library directory keeps the two apart.
set(hostLibs ${CMAKE_BINARY_DIR}/hostlibs)
file(MAKE_DIRECTORY ${hostLibs})
file(GLOB hostSharedLibs /usr/lib/x86_64-linux-gnu/lib*.so)
foreach(lib ${hostSharedLibs})
get_filename_component(name ${lib} NAME)
if(NOT name MATCHES "^lib(c|m|dl|pthread|rt|resolv|util|anl|nsl|crypt|gcc_s|stdc\\+\\+|BrokenLocale|mvec|memusage|pcprofile|SegFault|thread_db|c_malloc_debug|asan|ubsan|tsan|lsan|atomic|gomp|itm|quadmath)\\.so$")
if(NOT EXISTS ${hostLibs}/${name})
file(CREATE_LINK ${lib} ${hostLibs}/${name} SYMBOLIC)
endif()
endif()
endforeach()
# --allow-shlib-undefined: the host's platform libraries reference its newer glibc; at link time only
# their symbols matter, and the machine that runs the binary brings its own copies.
singeZigToolchain(x86_64-linux-gnu.${SINGE_GLIBC_VERSION} "-idirafter /usr/include/x86_64-linux-gnu -idirafter /usr/include -L${hostLibs} -Wl,--allow-shlib-undefined")
# No find-root restrictions: the host's development packages are the platform packages here, so
# SDL3 must find X11, Wayland, ALSA and the rest where they are. CMake learns the Debian multiarch
# library directory from gcc, not from a clang-style compiler, and its compiler detection overwrites
# a plain variable, so the settings are forced into the cache or FindX11 never sees libX11.
set(CMAKE_LIBRARY_ARCHITECTURE x86_64-linux-gnu CACHE STRING "Debian multiarch library directory name" FORCE)
set(CMAKE_C_LIBRARY_ARCHITECTURE x86_64-linux-gnu CACHE STRING "Debian multiarch library directory name" FORCE)
set(CMAKE_LIBRARY_PATH /usr/lib/x86_64-linux-gnu CACHE PATH "Where the host platform libraries live" FORCE)
set(KANGAROO_OS linux)
set(KANGAROO_ARCH x86_64)