From 8d411f0a2ddd9ffa20d560914eb3c601324ee863 Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 29 Apr 2026 20:15:15 +0000 Subject: [PATCH] cmake: fix static build bootstrap is not autoconf and rejects the --enable-static/ --disable-shared flags injected by the static stdenv adapter; set dontAddStaticConfigureFlags to avoid them FindLibArchive doesn't handle static libarchive correctly, use pkg-config to find correct entry manually and pass via NIX_LDFLAGS. kwsys's DynamicLoader test is inimical to -static so disable BUILD_TESTING in that case. Co-authored-by: Luna Nova --- pkgs/by-name/cm/cmake/package.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkgs/by-name/cm/cmake/package.nix b/pkgs/by-name/cm/cmake/package.nix index 3f099d56c7f9..a7703db28158 100644 --- a/pkgs/by-name/cm/cmake/package.nix +++ b/pkgs/by-name/cm/cmake/package.nix @@ -124,6 +124,10 @@ stdenv.mkDerivation (finalAttrs: { ++ lib.optional cursesUI ncurses ++ lib.optional qt5UI qtbase; + # bootstrap is not autoconf and rejects --enable-static/--disable-shared + # FIXME: rebuild avoidance, drop optionalDrvAttr in staging + dontAddStaticConfigureFlags = lib.optionalDrvAttr stdenv.hostPlatform.isStatic true; + preConfigure = '' substituteInPlace Modules/Platform/UnixPaths.cmake \ --subst-var-by libc_bin ${lib.getBin stdenv.cc.libc} \ @@ -131,6 +135,10 @@ stdenv.mkDerivation (finalAttrs: { --subst-var-by libc_lib ${lib.getLib stdenv.cc.libc} # CC_FOR_BUILD and CXX_FOR_BUILD are used to bootstrap cmake configureFlags="--parallel=''${NIX_BUILD_CORES:-1} CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD $configureFlags $cmakeFlags" + '' + + lib.optionalString (stdenv.hostPlatform.isStatic && useSharedLibraries) '' + # FindLibArchive ignores libarchive.pc's Libs.private + export NIX_LDFLAGS+=" $($PKG_CONFIG --static --libs-only-l libarchive)" ''; # The configuration script is not autoconf-based, although being similar; @@ -175,6 +183,11 @@ stdenv.mkDerivation (finalAttrs: { (lib.cmakeBool "CMAKE_USE_OPENSSL" useOpenSSL) (lib.cmakeBool "BUILD_CursesDialog" cursesUI) + ] + ++ lib.optionals stdenv.hostPlatform.isStatic [ + # kwsys's DynamicLoader test is inimical to -static + # doCheck is off anyway so just skip building tests + (lib.cmakeBool "BUILD_TESTING" false) ]; # make install attempts to use the just-built cmake