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-x1nJcnTx56qq/LHw0mH53pvzpdbst+LfYWMkpG/nBLI=";
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 outputs = [ "out" ] ++ lib.optionals buildDocs [ "man" "info" ];
82 separateDebugInfo = true;
83 setOutputFlags = false;
87 ./check-pc-files-hook.sh
90 depsBuildBuild = [ buildPackages.stdenv.cc ];
92 nativeBuildInputs = finalAttrs.setupHooks ++ [
95 ++ lib.optionals buildDocs [ texinfo ]
96 ++ lib.optionals qt5UI [ wrapQtAppsHook ];
98 buildInputs = lib.optionals useSharedLibraries [
108 ++ lib.optional useOpenSSL openssl
109 ++ lib.optional cursesUI ncurses
110 ++ lib.optional qt5UI qtbase
111 ++ lib.optional stdenv.hostPlatform.isDarwin CoreServices
112 ++ lib.optional (stdenv.hostPlatform.isDarwin && !isMinimalBuild) SystemConfiguration;
116 substituteInPlace Modules/Platform/UnixPaths.cmake \
117 --subst-var-by libc_bin ${lib.getBin stdenv.cc.libc} \
118 --subst-var-by libc_dev ${lib.getDev stdenv.cc.libc} \
119 --subst-var-by libc_lib ${lib.getLib stdenv.cc.libc}
120 # CC_FOR_BUILD and CXX_FOR_BUILD are used to bootstrap cmake
121 configureFlags="--parallel=''${NIX_BUILD_CORES:-1} CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD $configureFlags $cmakeFlags"
124 # The configuration script is not autoconf-based, although being similar;
125 # triples and other interesting info are passed via CMAKE_* environment
126 # variables and commandline switches
127 configurePlatforms = [ ];
130 "CXXFLAGS=-Wno-elaborated-enum-base"
131 "--docdir=share/doc/${finalAttrs.pname}-${finalAttrs.version}"
132 ] ++ (if useSharedLibraries
135 "--no-system-jsoncpp"
141 ++ lib.optional qt5UI "--qt-gui"
142 ++ lib.optionals buildDocs [
143 "--sphinx-build=${sphinx}/bin/sphinx-build"
147 # Workaround https://gitlab.kitware.com/cmake/cmake/-/issues/20568
148 ++ lib.optionals stdenv.hostPlatform.is32bit [
149 "CFLAGS=-D_FILE_OFFSET_BITS=64"
150 "CXXFLAGS=-D_FILE_OFFSET_BITS=64"
154 # We should set the proper `CMAKE_SYSTEM_NAME`.
155 # http://www.cmake.org/Wiki/CMake_Cross_Compiling
157 # Unfortunately cmake seems to expect absolute paths for ar, ranlib, and
158 # strip. Otherwise they are taken to be relative to the source root of the
159 # package being built.
160 (lib.cmakeFeature "CMAKE_CXX_COMPILER" "${stdenv.cc.targetPrefix}c++")
161 (lib.cmakeFeature "CMAKE_C_COMPILER" "${stdenv.cc.targetPrefix}cc")
162 (lib.cmakeFeature "CMAKE_AR"
163 "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar")
164 (lib.cmakeFeature "CMAKE_RANLIB"
165 "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ranlib")
166 (lib.cmakeFeature "CMAKE_STRIP"
167 "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}strip")
169 (lib.cmakeBool "CMAKE_USE_OPENSSL" useOpenSSL)
170 (lib.cmakeBool "BUILD_CursesDialog" cursesUI)
173 # `pkgsCross.musl64.cmake.override { stdenv = pkgsCross.musl64.llvmPackages_16.libcxxStdenv; }`
174 # fails with `The C++ compiler does not support C++11 (e.g. std::unique_ptr).`
175 # The cause is a compiler warning `warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]`
176 # interfering with the feature check.
177 env.NIX_CFLAGS_COMPILE = "-Wno-unused-command-line-argument";
179 # make install attempts to use the just-built cmake
180 preInstall = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
181 sed -i 's|bin/cmake|${buildPackages.cmakeMinimal}/bin/cmake|g' Makefile
184 # Undo some of `fixCmakeFiles` for Darwin to make sure that checks for libraries in the SDK find them
185 # (e.g., `find_library(MATH_LIBRARY m)` should find `$SDKROOT/usr/lib/libm.tbd`).
186 postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
187 substituteInPlace "$out/share/cmake-${lib.versions.majorMinor finalAttrs.version}/Modules/Platform/Darwin.cmake" \
188 --replace-fail '/var/empty/include' '/usr/include' \
189 --replace-fail '/var/empty/lib' '/usr/lib'
192 dontUseCmakeConfigure = true;
193 enableParallelBuilding = true;
195 doCheck = false; # fails
197 passthru.updateScript = gitUpdater {
198 url = "https://gitlab.kitware.com/cmake/cmake.git";
200 ignoredVersions = "-"; # -rc1 and friends
204 homepage = "https://cmake.org/";
205 description = "Cross-platform, open-source build system generator";
207 CMake is an open-source, cross-platform family of tools designed to build,
208 test and package software. CMake is used to control the software
209 compilation process using simple platform and compiler independent
210 configuration files, and generate native makefiles and workspaces that can
211 be used in the compiler environment of your choice.
213 changelog = "https://cmake.org/cmake/help/v${lib.versions.majorMinor finalAttrs.version}/release/${lib.versions.majorMinor finalAttrs.version}.html";
214 license = lib.licenses.bsd3;
215 maintainers = with lib.maintainers; [ ttuegel lnl7 AndersonTorres ];
216 platforms = lib.platforms.all;
217 mainProgram = "cmake";
218 broken = (qt5UI && stdenv.hostPlatform.isDarwin);