Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 230 lines 7.7 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 replaceVars, 6 buildPackages, 7 bzip2, 8 curlMinimal, 9 expat, 10 libarchive, 11 libuv, 12 ncurses, 13 openssl, 14 pkg-config, 15 ps, 16 rhash, 17 sphinx, 18 texinfo, 19 xz, 20 zlib, 21 isBootstrap ? null, 22 isMinimalBuild ? ( 23 if isBootstrap != null then 24 lib.warn "isBootstrap argument is deprecated and will be removed; use isMinimalBuild instead" isBootstrap 25 else 26 false 27 ), 28 useOpenSSL ? !isMinimalBuild, 29 useSharedLibraries ? (!isMinimalBuild && !stdenv.hostPlatform.isCygwin), 30 uiToolkits ? [ ], # can contain "ncurses" and/or "qt5" 31 buildDocs ? !(isMinimalBuild || (uiToolkits == [ ])), 32 libsForQt5, 33 gitUpdater, 34}: 35 36let 37 inherit (libsForQt5) qtbase wrapQtAppsHook; 38 cursesUI = lib.elem "ncurses" uiToolkits; 39 qt5UI = lib.elem "qt5" uiToolkits; 40in 41# Accepts only "ncurses" and "qt5" as possible uiToolkits 42assert lib.subtractLists [ "ncurses" "qt5" ] uiToolkits == [ ]; 43# Minimal, bootstrap cmake does not have toolkits 44assert isMinimalBuild -> (uiToolkits == [ ]); 45stdenv.mkDerivation (finalAttrs: { 46 pname = 47 "cmake" 48 + lib.optionalString isMinimalBuild "-minimal" 49 + lib.optionalString cursesUI "-cursesUI" 50 + lib.optionalString qt5UI "-qt5UI"; 51 version = "3.31.7"; 52 53 src = fetchurl { 54 url = "https://cmake.org/files/v${lib.versions.majorMinor finalAttrs.version}/cmake-${finalAttrs.version}.tar.gz"; 55 hash = "sha256-ptLrHr65kTDf5j71o0DD/bEUMczj18oUhSTBJZJM6mg="; 56 }; 57 58 patches = [ 59 # Add NIXPKGS_CMAKE_PREFIX_PATH to cmake which is like CMAKE_PREFIX_PATH 60 # except it is not searched for programs 61 ./000-nixpkgs-cmake-prefix-path.diff 62 # Don't search in non-Nix locations such as /usr, but do search in our libc. 63 ./001-search-path.diff 64 ] 65 ++ lib.optional stdenv.hostPlatform.isCygwin ./004-cygwin.diff 66 # On Darwin, always set CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG. 67 ++ lib.optional stdenv.hostPlatform.isDarwin ./006-darwin-always-set-runtime-c-flag.diff 68 # On platforms where ps is not part of stdenv, patch the invocation of ps to use an absolute path. 69 ++ lib.optional (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isFreeBSD) ( 70 replaceVars ./007-darwin-bsd-ps-abspath.diff { 71 ps = lib.getExe ps; 72 } 73 ) 74 ++ [ 75 # Backport of https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9900 76 # Needed to correctly link curl in pkgsStatic. 77 ./008-FindCURL-Add-more-target-properties-from-pkg-config.diff 78 ]; 79 80 outputs = [ 81 "out" 82 ] 83 ++ lib.optionals buildDocs [ 84 "man" 85 "info" 86 ]; 87 separateDebugInfo = true; 88 setOutputFlags = false; 89 90 setupHooks = [ 91 ./setup-hook.sh 92 ./check-pc-files-hook.sh 93 ]; 94 95 depsBuildBuild = [ buildPackages.stdenv.cc ]; 96 97 nativeBuildInputs = 98 finalAttrs.setupHooks 99 ++ [ 100 pkg-config 101 ] 102 ++ lib.optionals buildDocs [ texinfo ] 103 ++ lib.optionals qt5UI [ wrapQtAppsHook ]; 104 105 buildInputs = 106 lib.optionals useSharedLibraries [ 107 bzip2 108 curlMinimal 109 expat 110 libarchive 111 xz 112 zlib 113 libuv 114 rhash 115 ] 116 ++ lib.optional useOpenSSL openssl 117 ++ lib.optional cursesUI ncurses 118 ++ lib.optional qt5UI qtbase; 119 120 preConfigure = '' 121 fixCmakeFiles . 122 substituteInPlace Modules/Platform/UnixPaths.cmake \ 123 --subst-var-by libc_bin ${lib.getBin stdenv.cc.libc} \ 124 --subst-var-by libc_dev ${lib.getDev stdenv.cc.libc} \ 125 --subst-var-by libc_lib ${lib.getLib stdenv.cc.libc} 126 # CC_FOR_BUILD and CXX_FOR_BUILD are used to bootstrap cmake 127 configureFlags="--parallel=''${NIX_BUILD_CORES:-1} CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD $configureFlags $cmakeFlags" 128 ''; 129 130 # The configuration script is not autoconf-based, although being similar; 131 # triples and other interesting info are passed via CMAKE_* environment 132 # variables and commandline switches 133 configurePlatforms = [ ]; 134 135 configureFlags = [ 136 "CXXFLAGS=-Wno-elaborated-enum-base" 137 "--docdir=share/doc/${finalAttrs.pname}-${finalAttrs.version}" 138 ] 139 ++ ( 140 if useSharedLibraries then 141 [ 142 "--no-system-cppdap" 143 "--no-system-jsoncpp" 144 "--system-libs" 145 ] 146 else 147 [ 148 "--no-system-libs" 149 ] 150 ) # FIXME: cleanup 151 ++ lib.optional qt5UI "--qt-gui" 152 ++ lib.optionals buildDocs [ 153 "--sphinx-build=${sphinx}/bin/sphinx-build" 154 "--sphinx-info" 155 "--sphinx-man" 156 ] 157 # Workaround https://gitlab.kitware.com/cmake/cmake/-/issues/20568 158 ++ lib.optionals stdenv.hostPlatform.is32bit [ 159 "CFLAGS=-D_FILE_OFFSET_BITS=64" 160 "CXXFLAGS=-D_FILE_OFFSET_BITS=64" 161 ] 162 ++ [ 163 "--" 164 # We should set the proper `CMAKE_SYSTEM_NAME`. 165 # http://www.cmake.org/Wiki/CMake_Cross_Compiling 166 # 167 # Unfortunately cmake seems to expect absolute paths for ar, ranlib, and 168 # strip. Otherwise they are taken to be relative to the source root of the 169 # package being built. 170 (lib.cmakeFeature "CMAKE_CXX_COMPILER" "${stdenv.cc.targetPrefix}c++") 171 (lib.cmakeFeature "CMAKE_C_COMPILER" "${stdenv.cc.targetPrefix}cc") 172 (lib.cmakeFeature "CMAKE_AR" "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar") 173 (lib.cmakeFeature "CMAKE_RANLIB" "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ranlib") 174 (lib.cmakeFeature "CMAKE_STRIP" "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}strip") 175 176 (lib.cmakeBool "CMAKE_USE_OPENSSL" useOpenSSL) 177 (lib.cmakeBool "BUILD_CursesDialog" cursesUI) 178 ]; 179 180 # `pkgsCross.musl64.cmake.override { stdenv = pkgsCross.musl64.llvmPackages_16.libcxxStdenv; }` 181 # fails with `The C++ compiler does not support C++11 (e.g. std::unique_ptr).` 182 # The cause is a compiler warning `warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]` 183 # interfering with the feature check. 184 env.NIX_CFLAGS_COMPILE = "-Wno-unused-command-line-argument"; 185 186 # make install attempts to use the just-built cmake 187 preInstall = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' 188 sed -i 's|bin/cmake|${buildPackages.cmakeMinimal}/bin/cmake|g' Makefile 189 ''; 190 191 # Undo some of `fixCmakeFiles` for Darwin to make sure that checks for libraries in the SDK find them 192 # (e.g., `find_library(MATH_LIBRARY m)` should find `$SDKROOT/usr/lib/libm.tbd`). 193 postFixup = lib.optionalString stdenv.hostPlatform.isDarwin '' 194 substituteInPlace "$out/share/cmake-${lib.versions.majorMinor finalAttrs.version}/Modules/Platform/Darwin.cmake" \ 195 --replace-fail '/var/empty/include' '/usr/include' \ 196 --replace-fail '/var/empty/lib' '/usr/lib' 197 ''; 198 199 dontUseCmakeConfigure = true; 200 enableParallelBuilding = true; 201 202 doCheck = false; # fails 203 204 passthru.updateScript = gitUpdater { 205 url = "https://gitlab.kitware.com/cmake/cmake.git"; 206 rev-prefix = "v"; 207 ignoredVersions = "-"; # -rc1 and friends 208 }; 209 210 meta = { 211 homepage = "https://cmake.org/"; 212 description = "Cross-platform, open-source build system generator"; 213 longDescription = '' 214 CMake is an open-source, cross-platform family of tools designed to build, 215 test and package software. CMake is used to control the software 216 compilation process using simple platform and compiler independent 217 configuration files, and generate native makefiles and workspaces that can 218 be used in the compiler environment of your choice. 219 ''; 220 changelog = "https://cmake.org/cmake/help/v${lib.versions.majorMinor finalAttrs.version}/release/${lib.versions.majorMinor finalAttrs.version}.html"; 221 license = lib.licenses.bsd3; 222 maintainers = with lib.maintainers; [ 223 ttuegel 224 lnl7 225 ]; 226 platforms = lib.platforms.all; 227 mainProgram = "cmake"; 228 broken = (qt5UI && stdenv.hostPlatform.isDarwin); 229 }; 230})