1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
3 ;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
5 ;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
6 ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
7 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
8 ;;; Copyright © 2017, 2018, 2020 Marius Bakke <mbakke@fastmail.com>
9 ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
10 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
11 ;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
12 ;;; Copyright © 2019 Pierre-Moana Levesque <pierre.moana.levesque@gmail.com>
14 ;;; This file is part of GNU Guix.
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
29 (define-module (gnu packages cmake)
30 #:use-module ((guix licenses) #:prefix license:)
31 #:use-module (guix packages)
32 #:use-module (guix download)
33 #:use-module (guix utils)
34 #:use-module (guix deprecation)
35 #:use-module (guix build-system gnu)
36 #:use-module (guix build-system cmake)
37 #:use-module (guix build-system emacs)
38 #:use-module (gnu packages)
39 #:use-module (gnu packages backup)
40 #:use-module (gnu packages compression)
41 #:use-module (gnu packages crypto)
42 #:use-module (gnu packages curl)
43 #:use-module (gnu packages file)
44 #:use-module (gnu packages libevent)
45 #:use-module (gnu packages ncurses)
46 #:use-module (gnu packages serialization)
47 #:use-module (gnu packages sphinx)
48 #:use-module (gnu packages texinfo)
49 #:use-module (gnu packages xml)
50 #:use-module (ice-9 match)
51 #:use-module (srfi srfi-1))
53 ;;; Build phases shared between 'cmake-bootstrap' and the later variants
54 ;;; that use cmake-build-system.
55 (define %common-build-phases
56 `((add-after 'unpack 'split-package
57 ;; Remove files that have been packaged in other package recipes.
59 (delete-file "Auxiliary/cmake-mode.el")
60 (substitute* "Auxiliary/CMakeLists.txt"
61 ((".*cmake-mode.el.*") ""))
63 (add-before 'configure 'patch-bin-sh
65 ;; Replace "/bin/sh" by the right path in... a lot of
68 '("Modules/CompilerId/Xcode-3.pbxproj.in"
69 "Modules/Internal/CPack/CPack.RuntimeScript.in"
70 "Source/cmGlobalXCodeGenerator.cxx"
71 "Source/cmLocalUnixMakefileGenerator3.cxx"
72 "Source/cmExecProgramCommand.cxx"
73 "Utilities/Release/release_cmake.cmake"
74 "Tests/CMakeLists.txt"
75 "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
76 (("/bin/sh") (which "sh")))
79 (define %common-disabled-tests
80 '(;; This test copies libgcc_s.so.1 from GCC and tries to modify its RPATH,
81 ;; but does not cope with the file being read-only.
83 ;; This test requires network access.
85 ;; This test requires 'ldconfig' which is not available in Guix.
88 (define %preserved-third-party-files
89 '(;; 'Source/cm_getdate.c' includes archive_getdate.c wholesale, so it must
90 ;; be available along with the required headers.
91 "Utilities/cmlibarchive/libarchive/archive_getdate.c"
92 "Utilities/cmlibarchive/libarchive/archive_getdate.h"))
94 ;;; The "bootstrap" CMake. It is used to build 'cmake-minimal' below, as well
95 ;;; as any dependencies that need cmake-build-system.
96 (define-public cmake-bootstrap
98 (name "cmake-bootstrap")
102 (uri (string-append "https://www.cmake.org/files/v"
103 (version-major+minor version)
104 "/cmake-" version ".tar.gz"))
107 "1z4bb8z6b4dvq5hrvajrf1hyybqay3xybyimf71w1jgcp180nxjz"))
108 (modules '((guix build utils)
112 ;; CMake bundles its dependencies in the "Utilities" directory.
113 ;; Delete those to ensure the system libraries are used.
114 (define preserved-files
115 '(,@%preserved-third-party-files
116 ;; Use the bundled JsonCpp during bootstrap to work around
117 ;; a circular dependency. TODO: JsonCpp can be built with
118 ;; Meson instead of CMake, but meson-build-system currently
119 ;; does not support cross-compilation.
120 "Utilities/cmjsoncpp"
121 ;; LibUV is required to bootstrap the initial build system.
122 "Utilities/cmlibuv"))
124 (file-system-fold (lambda (dir stat result) ;enter?
125 (or (string=? "Utilities" dir) ;init
126 ;; The bundled dependencies are
127 ;; distinguished by having a "cm"
128 ;; prefix to their upstream names.
129 (and (string-prefix? "Utilities/cm" dir)
130 (not (member dir preserved-files)))))
131 (lambda (file stat result) ;leaf
132 (unless (or (member file preserved-files)
133 ;; Preserve top-level files.
134 (string=? "Utilities"
138 (lambda (dir stat result) ;up
139 (when (equal? (scandir dir) '("." ".."))
142 (lambda (file stat errno result)
143 (format (current-error-port)
144 "warning: failed to delete ~a: ~a~%"
145 file (strerror errno)))
150 (patches (search-patches "cmake-curl-certificates.patch"))))
151 (build-system gnu-build-system)
153 `(#:test-target "test"
155 (let ((out (assoc-ref %outputs "out"))
156 (parallel-job-count (number->string (parallel-job-count))))
158 (string-append "--parallel=" parallel-job-count)
159 (string-append "--prefix=" out)
161 "--no-system-jsoncpp"
162 ;; By default, the man pages and other docs land
163 ;; in PREFIX/man and PREFIX/doc, but we want them
164 ;; in share/{man,doc}. Note that unlike
165 ;; autoconf-generated configure scripts, cmake's
166 ;; configure prepends "PREFIX/" to what we pass
167 ;; to --mandir and --docdir.
169 ,(string-append "--docdir=share/doc/cmake-"
170 (version-major+minor version))
172 ;; By default CMake is built without any optimizations. Use
173 ;; the recommended Release target for a ~2.5x speedup.
174 "--" "-DCMAKE_BUILD_TYPE=Release"))
177 (list ,@%common-disabled-tests
178 "CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
179 ;; This test fails when ARGS (below) is in use, see
180 ;; <https://gitlab.kitware.com/cmake/cmake/issues/17165>.
181 "CTestCoverageCollectGCOV")))
184 ;; These arguments apply for the tests only.
185 "ARGS=-j " (number->string (parallel-job-count))
186 " --output-on-failure"
187 " --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
189 (modify-phases %standard-phases
190 ,@%common-build-phases
191 (add-before 'configure 'set-paths
193 ;; Help cmake's bootstrap process to find system libraries
195 (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
196 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
197 (getenv "C_INCLUDE_PATH")))
199 ;; CMake uses its own configure script.
201 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
202 (apply invoke "./configure" configure-flags))))))
205 ("curl" ,curl-minimal)
208 ("libarchive" ,libarchive)
210 ("ncurses" ,ncurses) ;required for ccmake
214 (list (search-path-specification
215 (variable "CMAKE_PREFIX_PATH")
217 ;; "cmake-curl-certificates.patch" changes CMake to honor 'SSL_CERT_DIR'
218 ;; and 'SSL_CERT_FILE', hence these search path entries.
219 (search-path-specification
220 (variable "SSL_CERT_DIR")
221 (separator #f) ;single entry
222 (files '("etc/ssl/certs")))
223 (search-path-specification
224 (variable "SSL_CERT_FILE")
226 (separator #f) ;single entry
227 (files '("etc/ssl/certs/ca-certificates.crt")))))
228 (home-page "https://cmake.org/")
229 (synopsis "Cross-platform build system")
231 "CMake is a family of tools designed to build, test and package software.
232 CMake is used to control the software compilation process using simple platform
233 and compiler independent configuration files. CMake generates native makefiles
234 and workspaces that can be used in the compiler environment of your choice.")
235 (properties '((hidden? . #t)))
236 (license (list license:bsd-3 ; cmake
237 license:expat ; cmjsoncpp is dual MIT/public domain
238 license:public-domain)))) ; cmlibarchive/archive_getdate.c
240 ;;; This minimal variant of CMake does not include the documentation. It is
241 ;;; used by the cmake-build-system.
242 (define-public cmake-minimal
244 (inherit cmake-bootstrap)
245 (name "cmake-minimal")
247 (inherit (package-source cmake-bootstrap))
249 (match (origin-snippet (package-source cmake-bootstrap))
251 ;; Now we can delete the remaining software bundles.
253 (define preserved-files ',%preserved-third-party-files))
258 ,@(alist-delete "curl" (package-inputs cmake-bootstrap))))
259 (build-system cmake-build-system)
262 (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
263 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
264 ,(version-major+minor (package-version
267 ;; This is the CMake used in cmake-build-system. Ensure compiler
268 ;; optimizations are enabled to save size and CPU cycles.
269 #:build-type "Release"
271 (modify-phases %standard-phases
272 ,@%common-build-phases
274 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
275 (let ((skipped-tests (list ,@%common-disabled-tests
276 ;; This test requires the bundled libuv.
280 (invoke "ctest" "-j" (if parallel-tests?
281 (number->string (parallel-job-count))
284 (string-append "^(" (string-join skipped-tests "|") ")$")))
285 (format #t "test suite not run~%"))
287 ,@(if (%current-target-system)
289 `(#:cmake ,cmake-bootstrap))))))
291 ;;; The "user-facing" CMake, now with manuals and HTML documentation.
294 (inherit cmake-minimal)
297 (substitute-keyword-arguments (package-arguments cmake-minimal)
298 ;; Use cmake-minimal this time.
300 (if (%current-target-system)
304 ;; Enable debugging information for convenience.
305 ((#:build-type _ #f) "RelWithDebInfo")
307 ((#:configure-flags flags ''())
308 `(append (list "-DSPHINX_INFO=ON" "-DSPHINX_MAN=ON" "-DSPHINX_HTML=ON"
309 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
310 ,(version-major+minor (package-version
312 "-DCMAKE_INFO_DIR=share/info"
313 "-DCMAKE_MAN_DIR=share/man")
316 `(modify-phases ,phases
317 (add-after 'install 'move-html-doc
318 (lambda* (#:key outputs #:allow-other-keys)
319 (let ((out (assoc-ref outputs "out"))
320 (doc (assoc-ref outputs "doc"))
321 (html (string-append "/share/doc/cmake-"
322 ,(version-major+minor
323 (package-version cmake-minimal))
325 (copy-recursively (string-append out html)
326 (string-append doc html))
327 (delete-file-recursively (string-append out html))
329 ;; Extra inputs required to build the documentation.
331 `(,@(package-native-inputs cmake-minimal)
332 ("python-sphinx" ,python-sphinx)
333 ("texinfo" ,texinfo)))
334 (outputs '("out" "doc"))
335 (properties (alist-delete 'hidden? (package-properties cmake-minimal)))))
337 (define-public cmake-minimal-cross
339 (inherit cmake-minimal)
340 (name "cmake-minimal-cross")
341 (native-search-paths '())
343 (package-native-search-paths cmake-minimal))))
345 (define-public emacs-cmake-mode
348 (name "emacs-cmake-mode")
352 (build-system emacs-build-system)
355 (modify-phases %standard-phases
356 (add-after 'unpack 'chdir-elisp
357 ;; Elisp directory is not in root of the source.
361 (synopsis "Emacs major mode for editing Cmake expressions")
362 (description "@code{cmakeos-mode} provides an Emacs major mode for editing
363 Cmake files. It supports syntax highlighting, indenting and refilling of