21 if isBootstrap != null
23 "isBootstrap argument is deprecated and will be removed; use isMinimalBuild instead"
26 , useOpenSSL ? !isMinimalBuild
27 , useSharedLibraries ? (!isMinimalBuild && !stdenv.isCygwin)
28 , uiToolkits ? [] # can contain "ncurses" and/or "qt5"
29 , buildDocs ? !(isMinimalBuild || (uiToolkits == []))
35 inherit (darwin.apple_sdk.frameworks) SystemConfiguration;
36 inherit (libsForQt5) qtbase wrapQtAppsHook;
37 cursesUI = lib.elem "ncurses" uiToolkits;
38 qt5UI = lib.elem "qt5" uiToolkits;
40 # Accepts only "ncurses" and "qt5" as possible uiToolkits
41 assert lib.subtractLists [ "ncurses" "qt5" ] uiToolkits == [];
42 # Minimal, bootstrap cmake does not have toolkits
43 assert isMinimalBuild -> (uiToolkits == []);
44 stdenv.mkDerivation (finalAttrs: {
46 + lib.optionalString isMinimalBuild "-minimal"
47 + lib.optionalString cursesUI "-cursesUI"
48 + lib.optionalString qt5UI "-qt5UI";
52 url = "https://cmake.org/files/v${lib.versions.majorMinor finalAttrs.version}/cmake-${finalAttrs.version}.tar.gz";
53 hash = "sha256-CPcaEGA2vwUfaSdg75VYwFd8Qqw56Wugl+dmK9QVjY4=";
57 # Don't search in non-Nix locations such as /usr, but do search in our libc.
58 ./001-search-path.diff
59 # Don't depend on frameworks.
60 ./002-application-services.diff
61 # Derived from https://github.com/libuv/libuv/commit/1a5d4f08238dd532c3718e210078de1186a5920d
62 ./003-libuv-application-services.diff
64 ++ lib.optional stdenv.isCygwin ./004-cygwin.diff
65 # Derived from https://github.com/curl/curl/commit/31f631a142d855f069242f3e0c643beec25d1b51
66 ++ lib.optional (stdenv.isDarwin && isMinimalBuild) ./005-remove-systemconfiguration-dep.diff
67 # On Darwin, always set CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG.
68 ++ lib.optional stdenv.isDarwin ./006-darwin-always-set-runtime-c-flag.diff;
70 outputs = [ "out" ] ++ lib.optionals buildDocs [ "man" "info" ];
71 setOutputFlags = false;
75 ./check-pc-files-hook.sh
78 depsBuildBuild = [ buildPackages.stdenv.cc ];
80 nativeBuildInputs = finalAttrs.setupHooks ++ [
83 ++ lib.optionals buildDocs [ texinfo ]
84 ++ lib.optionals qt5UI [ wrapQtAppsHook ];
86 buildInputs = lib.optionals useSharedLibraries [
96 ++ lib.optional useOpenSSL openssl
97 ++ lib.optional cursesUI ncurses
98 ++ lib.optional qt5UI qtbase
99 ++ lib.optional (stdenv.isDarwin && !isMinimalBuild) SystemConfiguration;
101 propagatedBuildInputs = lib.optional stdenv.isDarwin ps;
105 substituteInPlace Modules/Platform/UnixPaths.cmake \
106 --subst-var-by libc_bin ${lib.getBin stdenv.cc.libc} \
107 --subst-var-by libc_dev ${lib.getDev stdenv.cc.libc} \
108 --subst-var-by libc_lib ${lib.getLib stdenv.cc.libc}
109 # CC_FOR_BUILD and CXX_FOR_BUILD are used to bootstrap cmake
110 configureFlags="--parallel=''${NIX_BUILD_CORES:-1} CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD $configureFlags"
113 # The configuration script is not autoconf-based, although being similar;
114 # triples and other interesting info are passed via CMAKE_* environment
115 # variables and commandline switches
116 configurePlatforms = [ ];
119 "CXXFLAGS=-Wno-elaborated-enum-base"
120 "--docdir=share/doc/${finalAttrs.pname}-${finalAttrs.version}"
121 ] ++ (if useSharedLibraries
124 "--no-system-jsoncpp"
130 ++ lib.optional qt5UI "--qt-gui"
131 ++ lib.optionals buildDocs [
132 "--sphinx-build=${sphinx}/bin/sphinx-build"
136 # Workaround https://gitlab.kitware.com/cmake/cmake/-/issues/20568
137 ++ lib.optionals stdenv.hostPlatform.is32bit [
138 "CFLAGS=-D_FILE_OFFSET_BITS=64"
139 "CXXFLAGS=-D_FILE_OFFSET_BITS=64"
143 # We should set the proper `CMAKE_SYSTEM_NAME`.
144 # http://www.cmake.org/Wiki/CMake_Cross_Compiling
146 # Unfortunately cmake seems to expect absolute paths for ar, ranlib, and
147 # strip. Otherwise they are taken to be relative to the source root of the
148 # package being built.
149 (lib.cmakeFeature "CMAKE_CXX_COMPILER" "${stdenv.cc.targetPrefix}c++")
150 (lib.cmakeFeature "CMAKE_C_COMPILER" "${stdenv.cc.targetPrefix}cc")
151 (lib.cmakeFeature "CMAKE_AR"
152 "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar")
153 (lib.cmakeFeature "CMAKE_RANLIB"
154 "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ranlib")
155 (lib.cmakeFeature "CMAKE_STRIP"
156 "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}strip")
158 (lib.cmakeBool "CMAKE_USE_OPENSSL" useOpenSSL)
159 (lib.cmakeBool "BUILD_CursesDialog" cursesUI)
162 # make install attempts to use the just-built cmake
163 preInstall = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
164 sed -i 's|bin/cmake|${buildPackages.cmakeMinimal}/bin/cmake|g' Makefile
167 dontUseCmakeConfigure = true;
168 enableParallelBuilding = true;
170 doCheck = false; # fails
173 homepage = "https://cmake.org/";
174 description = "Cross-platform, open-source build system generator";
176 CMake is an open-source, cross-platform family of tools designed to build,
177 test and package software. CMake is used to control the software
178 compilation process using simple platform and compiler independent
179 configuration files, and generate native makefiles and workspaces that can
180 be used in the compiler environment of your choice.
182 changelog = "https://cmake.org/cmake/help/v${lib.versions.majorMinor finalAttrs.version}/release/${lib.versions.majorMinor finalAttrs.version}.html";
183 license = lib.licenses.bsd3;
184 maintainers = with lib.maintainers; [ ttuegel lnl7 AndersonTorres ];
185 platforms = lib.platforms.all;
186 broken = (qt5UI && stdenv.isDarwin);