From 0cee625e8b961ff34609fc78382cddbc17e80ad6 Mon Sep 17 00:00:00 2001 From: Daniel Dada Date: Tue, 9 Dec 2025 14:17:30 +0300 Subject: [PATCH] statically link glwf on windows and ubuntu --- .github/workflows/Test packages.yml | 4 ++-- AUR/PKGBUILD | 1 + AUR/PKGBUILD-git | 1 + AUR/PKGBUILD.in | 1 + CMakeLists.txt | 36 ++++++++++++++++++++--------- flake.nix | 1 + 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/.github/workflows/Test packages.yml b/.github/workflows/Test packages.yml index 552b74a..bb67d7d 100644 --- a/.github/workflows/Test packages.yml +++ b/.github/workflows/Test packages.yml @@ -29,7 +29,7 @@ jobs: - name: Configure CMake run: | - cmake -B build -DCMAKE_BUILD_TYPE=Release + cmake -B build -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_GLFW=OFF - name: Build run: cmake --build build --config Release @@ -77,7 +77,7 @@ jobs: - name: Configure CMake run: | - cmake -B build -DCMAKE_BUILD_TYPE=Release + cmake -B build -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_GLFW=ON - name: Build run: cmake --build build --config Release diff --git a/AUR/PKGBUILD b/AUR/PKGBUILD index bde2c3a..914b482 100644 --- a/AUR/PKGBUILD +++ b/AUR/PKGBUILD @@ -35,6 +35,7 @@ build() { cd "$pkgname-$pkgver" cmake -B build -S . \ -DCMAKE_BUILD_TYPE=Release \ + -DUSE_SYSTEM_GLFW=ON \ -DCMAKE_INSTALL_PREFIX=/usr cmake --build build } diff --git a/AUR/PKGBUILD-git b/AUR/PKGBUILD-git index d97b41f..64709cc 100644 --- a/AUR/PKGBUILD-git +++ b/AUR/PKGBUILD-git @@ -41,6 +41,7 @@ build() { cd "$srcdir/$pkgname" cmake -B build -S . \ -DCMAKE_BUILD_TYPE=Release \ + -DUSE_SYSTEM_GLFW=ON \ -DCMAKE_INSTALL_PREFIX=/usr cmake --build build } diff --git a/AUR/PKGBUILD.in b/AUR/PKGBUILD.in index c28922d..be80acc 100644 --- a/AUR/PKGBUILD.in +++ b/AUR/PKGBUILD.in @@ -35,6 +35,7 @@ build() { cd "$pkgname-$pkgver" cmake -B build -S . \ -DCMAKE_BUILD_TYPE=Release \ + -DUSE_SYSTEM_GLFW=ON \ -DCMAKE_INSTALL_PREFIX=/usr cmake --build build } diff --git a/CMakeLists.txt b/CMakeLists.txt index bc4ce0b..324132d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,9 @@ include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +option(USE_SYSTEM_GLFW "Use system-installed GLFW instead of fetching it statically" OFF) +message(STATUS "USE_SYSTEM_GLFW: ${USE_SYSTEM_GLFW}") + # ----------------------------- # Platform-specific install dirs # ----------------------------- @@ -52,16 +55,6 @@ if(WIN32) URL https://download.savannah.gnu.org/releases/freetype/freetype-2.14.1.tar.gz ) FetchContent_MakeAvailable(freetype) - - FetchContent_Declare( - glfw - GIT_REPOSITORY https://github.com/glfw/glfw.git - GIT_TAG 3.4 - ) - set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) - set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) - set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(glfw) else() find_package(Freetype REQUIRED) find_package(PkgConfig REQUIRED) @@ -74,12 +67,33 @@ else() find_library(BROTLICOMMON_LIBRARY NAMES brotlicommon) pkg_check_modules(HARFBUZZ harfbuzz) - pkg_check_modules(GLFW REQUIRED glfw3) pkg_check_modules(WAYLAND_CLIENT wayland-client) pkg_check_modules(WAYLAND_EGL wayland-egl) endif() + +if(USE_SYSTEM_GLFW) + pkg_check_modules(GLFW REQUIRED glfw3) +else() + include(FetchContent) + FetchContent_Declare( + glfw + GIT_REPOSITORY https://github.com/glfw/glfw.git + GIT_TAG 3.4 + ) + set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) + set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) + set(GLFW_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) + set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) + + FetchContent_MakeAvailable(glfw) + set(GLFW_FOUND TRUE) + set(GLFW_INCLUDE_DIRS ${glfw_SOURCE_DIR}/include) + set(GLFW_LIBRARIES glfw) +endif() + # ----------------------------- # Extra libraries for Freetype # ----------------------------- diff --git a/flake.nix b/flake.nix index 5c4161c..8304201 100644 --- a/flake.nix +++ b/flake.nix @@ -47,6 +47,7 @@ cmakeFlags = [ "-DCMAKE_BUILD_TYPE=Release" + "-DUSE_SYSTEM_GLFW=ON" ]; installPhase = ''