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-E5ExMAO4PUjiqxFai1JaVX942MFURhi0jR2QGEoQ8K8=";
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 dontUseCmakeConfigure = true;
185 enableParallelBuilding = true;
187 doCheck = false; # fails
189 passthru.updateScript = gitUpdater {
190 url = "https://gitlab.kitware.com/cmake/cmake.git";
192 ignoredVersions = "-"; # -rc1 and friends
196 homepage = "https://cmake.org/";
197 description = "Cross-platform, open-source build system generator";
199 CMake is an open-source, cross-platform family of tools designed to build,
200 test and package software. CMake is used to control the software
201 compilation process using simple platform and compiler independent
202 configuration files, and generate native makefiles and workspaces that can
203 be used in the compiler environment of your choice.
205 changelog = "https://cmake.org/cmake/help/v${lib.versions.majorMinor finalAttrs.version}/release/${lib.versions.majorMinor finalAttrs.version}.html";
206 license = lib.licenses.bsd3;
207 maintainers = with lib.maintainers; [ ttuegel lnl7 AndersonTorres ];
208 platforms = lib.platforms.all;
209 mainProgram = "cmake";
210 broken = (qt5UI && stdenv.hostPlatform.isDarwin);