22 if isBootstrap != null
24 "isBootstrap argument is deprecated and will be removed; use isMinimalBuild instead"
27 , useOpenSSL ? !isMinimalBuild
28 , useSharedLibraries ? (!isMinimalBuild && !stdenv.hostPlatform.isCygwin)
29 , uiToolkits ? [] # can contain "ncurses" and/or "qt5"
30 , buildDocs ? !(isMinimalBuild || (uiToolkits == []))
37 inherit (darwin.apple_sdk.frameworks) CoreServices SystemConfiguration;
38 inherit (libsForQt5) qtbase wrapQtAppsHook;
39 cursesUI = lib.elem "ncurses" uiToolkits;
40 qt5UI = lib.elem "qt5" uiToolkits;
42 # Accepts only "ncurses" and "qt5" as possible uiToolkits
43 assert lib.subtractLists [ "ncurses" "qt5" ] uiToolkits == [];
44 # Minimal, bootstrap cmake does not have toolkits
45 assert isMinimalBuild -> (uiToolkits == []);
46 stdenv.mkDerivation (finalAttrs: {
48 + lib.optionalString isMinimalBuild "-minimal"
49 + lib.optionalString cursesUI "-cursesUI"
50 + lib.optionalString qt5UI "-qt5UI";
54 url = "https://cmake.org/files/v${lib.versions.majorMinor finalAttrs.version}/cmake-${finalAttrs.version}.tar.gz";
55 hash = "sha256-n1XhpAUI8vKbfgZfoIwp+CxAL6BALag5//5koldVqG0=";
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 # Don't depend on frameworks.
65 ./002-application-services.diff
66 # Derived from https://github.com/libuv/libuv/commit/1a5d4f08238dd532c3718e210078de1186a5920d
67 ./003-libuv-application-services.diff
69 ++ lib.optional stdenv.hostPlatform.isCygwin ./004-cygwin.diff
70 # Derived from https://github.com/curl/curl/commit/31f631a142d855f069242f3e0c643beec25d1b51
71 ++ lib.optional (stdenv.hostPlatform.isDarwin && isMinimalBuild) ./005-remove-systemconfiguration-dep.diff
72 # On Darwin, always set CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG.
73 ++ lib.optional stdenv.hostPlatform.isDarwin ./006-darwin-always-set-runtime-c-flag.diff
74 # On platforms where ps is not part of stdenv, patch the invocation of ps to use an absolute path.
75 ++ lib.optional (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isFreeBSD) (
77 src = ./007-darwin-bsd-ps-abspath.diff;
81 # Backport of https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9900
82 # Needed to corretly link curl in pkgsStatic.
83 ./008-FindCURL-Add-more-target-properties-from-pkg-config.diff
86 outputs = [ "out" ] ++ lib.optionals buildDocs [ "man" "info" ];
87 separateDebugInfo = true;
88 setOutputFlags = false;
92 ./check-pc-files-hook.sh
95 depsBuildBuild = [ buildPackages.stdenv.cc ];
97 nativeBuildInputs = finalAttrs.setupHooks ++ [
100 ++ lib.optionals buildDocs [ texinfo ]
101 ++ lib.optionals qt5UI [ wrapQtAppsHook ];
103 buildInputs = lib.optionals useSharedLibraries [
113 ++ lib.optional useOpenSSL openssl
114 ++ lib.optional cursesUI ncurses
115 ++ lib.optional qt5UI qtbase
116 ++ lib.optional stdenv.hostPlatform.isDarwin CoreServices
117 ++ lib.optional (stdenv.hostPlatform.isDarwin && !isMinimalBuild) SystemConfiguration;
121 substituteInPlace Modules/Platform/UnixPaths.cmake \
122 --subst-var-by libc_bin ${lib.getBin stdenv.cc.libc} \
123 --subst-var-by libc_dev ${lib.getDev stdenv.cc.libc} \
124 --subst-var-by libc_lib ${lib.getLib stdenv.cc.libc}
125 # CC_FOR_BUILD and CXX_FOR_BUILD are used to bootstrap cmake
126 configureFlags="--parallel=''${NIX_BUILD_CORES:-1} CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD $configureFlags $cmakeFlags"
129 # The configuration script is not autoconf-based, although being similar;
130 # triples and other interesting info are passed via CMAKE_* environment
131 # variables and commandline switches
132 configurePlatforms = [ ];
135 "CXXFLAGS=-Wno-elaborated-enum-base"
136 "--docdir=share/doc/${finalAttrs.pname}-${finalAttrs.version}"
137 ] ++ (if useSharedLibraries
140 "--no-system-jsoncpp"
146 ++ lib.optional qt5UI "--qt-gui"
147 ++ lib.optionals buildDocs [
148 "--sphinx-build=${sphinx}/bin/sphinx-build"
152 # Workaround https://gitlab.kitware.com/cmake/cmake/-/issues/20568
153 ++ lib.optionals stdenv.hostPlatform.is32bit [
154 "CFLAGS=-D_FILE_OFFSET_BITS=64"
155 "CXXFLAGS=-D_FILE_OFFSET_BITS=64"
159 # We should set the proper `CMAKE_SYSTEM_NAME`.
160 # http://www.cmake.org/Wiki/CMake_Cross_Compiling
162 # Unfortunately cmake seems to expect absolute paths for ar, ranlib, and
163 # strip. Otherwise they are taken to be relative to the source root of the
164 # package being built.
165 (lib.cmakeFeature "CMAKE_CXX_COMPILER" "${stdenv.cc.targetPrefix}c++")
166 (lib.cmakeFeature "CMAKE_C_COMPILER" "${stdenv.cc.targetPrefix}cc")
167 (lib.cmakeFeature "CMAKE_AR"
168 "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar")
169 (lib.cmakeFeature "CMAKE_RANLIB"
170 "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ranlib")
171 (lib.cmakeFeature "CMAKE_STRIP"
172 "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}strip")
174 (lib.cmakeBool "CMAKE_USE_OPENSSL" useOpenSSL)
175 (lib.cmakeBool "BUILD_CursesDialog" cursesUI)
178 # `pkgsCross.musl64.cmake.override { stdenv = pkgsCross.musl64.llvmPackages_16.libcxxStdenv; }`
179 # fails with `The C++ compiler does not support C++11 (e.g. std::unique_ptr).`
180 # The cause is a compiler warning `warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]`
181 # interfering with the feature check.
182 env.NIX_CFLAGS_COMPILE = "-Wno-unused-command-line-argument";
184 # make install attempts to use the just-built cmake
185 preInstall = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
186 sed -i 's|bin/cmake|${buildPackages.cmakeMinimal}/bin/cmake|g' Makefile
189 # Undo some of `fixCmakeFiles` for Darwin to make sure that checks for libraries in the SDK find them
190 # (e.g., `find_library(MATH_LIBRARY m)` should find `$SDKROOT/usr/lib/libm.tbd`).
191 postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
192 substituteInPlace "$out/share/cmake-${lib.versions.majorMinor finalAttrs.version}/Modules/Platform/Darwin.cmake" \
193 --replace-fail '/var/empty/include' '/usr/include' \
194 --replace-fail '/var/empty/lib' '/usr/lib'
197 dontUseCmakeConfigure = true;
198 enableParallelBuilding = true;
200 doCheck = false; # fails
202 passthru.updateScript = gitUpdater {
203 url = "https://gitlab.kitware.com/cmake/cmake.git";
205 ignoredVersions = "-"; # -rc1 and friends
209 homepage = "https://cmake.org/";
210 description = "Cross-platform, open-source build system generator";
212 CMake is an open-source, cross-platform family of tools designed to build,
213 test and package software. CMake is used to control the software
214 compilation process using simple platform and compiler independent
215 configuration files, and generate native makefiles and workspaces that can
216 be used in the compiler environment of your choice.
218 changelog = "https://cmake.org/cmake/help/v${lib.versions.majorMinor finalAttrs.version}/release/${lib.versions.majorMinor finalAttrs.version}.html";
219 license = lib.licenses.bsd3;
220 maintainers = with lib.maintainers; [ ttuegel lnl7 ];
221 platforms = lib.platforms.all;
222 mainProgram = "cmake";
223 broken = (qt5UI && stdenv.hostPlatform.isDarwin);