2020-11-07 00:36:08 +01:00
# This toolchain file helps building a fully statically linked executable (besides DLLs from Windows itself) by
# defining certain variables. It is mainly focusing on dependencies used by Qt.
# build this on top of the regular toolchain file
2020-10-31 22:38:29 +01:00
include ( "/usr/share/mingw/toolchain-@TRIPLE@.cmake" )
# prefer libraries from "static" sub-prefix
2024-01-02 18:46:39 +01:00
set ( CMAKE_STATIC_PREFIX "/usr/@TRIPLE@/static" )
set ( CMAKE_FIND_ROOT_PATH "${CMAKE_STATIC_PREFIX};${CMAKE_FIND_ROOT_PATH}" )
2020-10-31 22:38:29 +01:00
# prefer static libraries
2020-11-07 00:36:08 +01:00
# note: It is of no use to set the real variable CMAKE_FIND_LIBRARY_SUFFIXES here because it gets overridden by CMake
# after loading the toolchain file. The project needs to make the actual override if enforcing static libraries
# is required.
set ( CMAKE_FIND_LIBRARY_SUFFIXES_OVERRIDE ".a;.lib" )
2020-10-31 22:38:29 +01:00
set ( CMAKE_EXE_LINKER_FLAGS "$ENV{LDFLAGS} -static -static-libgcc -static-libstdc++" CACHE STRING "linker flags for static builds" FORCE )
set ( OPENSSL_USE_STATIC_LIBS ON )
2020-11-07 00:36:08 +01:00
set ( BOOST_USE_STATIC_LIBS ON )
# force-use the shared Vulkan library because there's no static one
# note: The library is not used anyways but required for Vulkan to be considered installed and enabled.
set ( Vulkan_LIBRARY "/usr/@TRIPLE@/lib/libvulkan.dll.a" CACHE FILEPATH "shared Vulkan IDC library" )
2020-10-31 22:38:29 +01:00
# workaround limitations in upstream pkg-config files and CMake find modules
2024-01-02 18:46:39 +01:00
set ( pkgcfg_lib_libbrotlicommon_brotlicommon "${CMAKE_STATIC_PREFIX}/lib/libbrotlicommon.a" CACHE INTERNAL "static libbrotlicommon" )
set ( pkgcfg_lib_libbrotlienc_brotlienc "${CMAKE_STATIC_PREFIX}/lib/libbrotlienc.a;${CMAKE_STATIC_PREFIX}/lib/libbrotlicommon.a" CACHE INTERNAL "static libbrotliend" )
set ( pkgcfg_lib_libbrotlidec_brotlidec "${CMAKE_STATIC_PREFIX}/lib/libbrotlidec.a;${CMAKE_STATIC_PREFIX}/lib/libbrotlicommon.a" CACHE INTERNAL "static libbrotlidec" )
2020-10-31 22:38:29 +01:00
set ( libbrotlicommon_STATIC_LDFLAGS "${pkgcfg_lib_libbrotlicommon_brotlicommon}" CACHE INTERNAL "static libbrotlicommon" )
set ( libbrotlienc_STATIC_LDFLAGS "${pkgcfg_lib_libbrotlienc_brotlienc}" CACHE INTERNAL "static libbrotliend" )
set ( libbrotlidec_STATIC_LDFLAGS "${pkgcfg_lib_libbrotlidec_brotlidec}" CACHE INTERNAL "static libbrotlidec" )
2023-08-09 16:36:59 +02:00
# disable use of find modules that don't work for static libraries
set ( CMAKE_DISABLE_FIND_PACKAGE_harfbuzz TRUE )
2020-10-31 22:38:29 +01:00
# define dependencies of various static libraries as CMake doesn't pull them reliably automatically
2020-11-07 00:36:08 +01:00
# note: It would be possible to deduce the dependencies via pkg-config. However, for simplicity I'm hard-coding the dependencies for now.
# In some cases the pkg-config file wouldn't work anyways because it is only covering the shared version (despite use of `-static`).
2020-10-31 22:38:29 +01:00
set ( OPENSSL_DEPENDENCIES "-lws2_32;-lgdi32;-lcrypt32" CACHE INTERNAL "dependencies of static OpenSSL libraries" )
set ( POSTGRESQL_DEPENDENCIES "-lpgcommon;-lpgport;-lintl;-lssl;-lcrypto;-lshell32;-lws2_32;-lsecur32;-liconv" CACHE INTERNAL "dependencies of static PostgreSQL libraries" )
set ( MYSQL_DEPENDENCIES "-lssl;-lcrypto;-lshlwapi;-lgdi32;-lws2_32;-lpthread;-lz;-lm" CACHE INTERNAL "dependencies of static MySQL/MariaDB libraries" )
set ( LIBPNG_DEPENDENCIES "-lz" CACHE INTERNAL "dependencies of static libpng" )
set ( GLIB2_DEPENDENCIES "-lintl;-lws2_32;-lole32;-lwinmm;-lshlwapi;-lm" CACHE INTERNAL "dependencies of static Glib2" )
2024-01-02 18:46:39 +01:00
set ( FREETYPE_DEPENDENCIES "-lbz2;-lharfbuzz;-lfreetype;-lbrotlidec;-lbrotlicommon" CACHE INTERNAL "dependencies of static FreeType2 library" )
2020-10-31 22:38:29 +01:00
set ( HARFBUZZ_DEPENDENCIES "-lglib-2.0;${GLIB2_DEPENDENCIES};-lintl;-lm;-lfreetype;-lgraphite2" CACHE INTERNAL "dependencies of static HarfBuzz library" )
set ( DBUS1_DEPENDENCIES "-lws2_32;-liphlpapi;-ldbghelp" CACHE INTERNAL "dependencies of static D-Bus1 library" )