gnu: emacs-consult: Fix grammar.
[jackhill/guix/guix.git] / gnu / packages / cmake.scm
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, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
11 ;;; Copyright © 2019, 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
12 ;;; Copyright © 2019 Pierre-Moana Levesque <pierre.moana.levesque@gmail.com>
13 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
14 ;;;
15 ;;; This file is part of GNU Guix.
16 ;;;
17 ;;; GNU Guix is free software; you can redistribute it and/or modify it
18 ;;; under the terms of the GNU General Public License as published by
19 ;;; the Free Software Foundation; either version 3 of the License, or (at
20 ;;; your option) any later version.
21 ;;;
22 ;;; GNU Guix is distributed in the hope that it will be useful, but
23 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;;; GNU General Public License for more details.
26 ;;;
27 ;;; You should have received a copy of the GNU General Public License
28 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
29
30 (define-module (gnu packages cmake)
31 #:use-module ((guix licenses) #:prefix license:)
32 #:use-module (guix packages)
33 #:use-module (guix download)
34 #:use-module (guix git-download)
35 #:use-module (guix utils)
36 #:use-module (guix deprecation)
37 #:use-module (guix build-system gnu)
38 #:use-module (guix build-system cmake)
39 #:use-module (guix build-system emacs)
40 #:use-module (gnu packages)
41 #:use-module (gnu packages backup)
42 #:use-module (gnu packages compression)
43 #:use-module (gnu packages crypto)
44 #:use-module (gnu packages curl)
45 #:use-module (gnu packages file)
46 #:use-module (gnu packages hurd)
47 #:use-module (gnu packages kde-frameworks)
48 #:use-module (gnu packages libevent)
49 #:use-module (gnu packages ncurses)
50 #:use-module (gnu packages serialization)
51 #:use-module (gnu packages sphinx)
52 #:use-module (gnu packages texinfo)
53 #:use-module (gnu packages xml)
54 #:use-module (ice-9 match)
55 #:use-module (srfi srfi-1))
56
57 (define-public cmake-shared
58 (let ((commit "8122f2b96c8da38ea41b653cf69958e75fe2129d")
59 (revision "32"))
60 (package
61 (name "cmake-shared")
62 (version
63 (git-version "1.1.0" revision commit))
64 (source
65 (origin
66 (method git-fetch)
67 (uri
68 (git-reference
69 (url "https://github.com/lirios/cmake-shared.git")
70 (commit commit)))
71 (file-name
72 (git-file-name name version))
73 (sha256
74 (base32 "05avwzqcnliwx9h7qi1kl0iz4smqmxc4vkavyjbmlc6h2b97i58g"))
75 (modules '((guix build utils)
76 (ice-9 ftw)
77 (srfi srfi-1)))
78 (snippet
79 `(begin
80 (delete-file-recursively "3rdparty")))))
81 (build-system cmake-build-system)
82 (arguments
83 `(#:tests? #f)) ; No target
84 (native-inputs
85 `(("extra-cmake-modules" ,extra-cmake-modules)))
86 (synopsis "Shared CMake functions and macros")
87 (description "CMake-Shared are shared functions and macros for projects
88 using the CMake build system.")
89 (home-page "https://github.com/lirios/cmake-shared/")
90 (license license:bsd-3))))
91
92 ;;; Build phases shared between 'cmake-bootstrap' and the later variants
93 ;;; that use cmake-build-system.
94 (define %common-build-phases
95 `((add-after 'unpack 'split-package
96 ;; Remove files that have been packaged in other package recipes.
97 (lambda _
98 (delete-file "Auxiliary/cmake-mode.el")
99 (substitute* "Auxiliary/CMakeLists.txt"
100 ((".*cmake-mode.el.*") ""))
101 #t))
102 (add-before 'configure 'patch-bin-sh
103 (lambda _
104 ;; Replace "/bin/sh" by the right path in... a lot of
105 ;; files.
106 (substitute*
107 '("Modules/CompilerId/Xcode-3.pbxproj.in"
108 "Modules/Internal/CPack/CPack.RuntimeScript.in"
109 "Source/cmGlobalXCodeGenerator.cxx"
110 "Source/cmLocalUnixMakefileGenerator3.cxx"
111 "Source/cmExecProgramCommand.cxx"
112 "Utilities/Release/release_cmake.cmake"
113 "Tests/CMakeLists.txt"
114 "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
115 (("/bin/sh") (which "sh")))
116 #t))))
117
118 (define %common-disabled-tests
119 '(;; This test copies libgcc_s.so.1 from GCC and tries to modify its RPATH,
120 ;; but does not cope with the file being read-only.
121 "BundleUtilities"
122 ;; This test requires network access.
123 "CTestTestUpload"
124 ;; This test requires 'ldconfig' which is not available in Guix.
125 "RunCMake.install"))
126
127 (define %preserved-third-party-files
128 '(;; 'Source/cm_getdate.c' includes archive_getdate.c wholesale, so it must
129 ;; be available along with the required headers.
130 "Utilities/cmlibarchive/libarchive/archive_getdate.c"
131 "Utilities/cmlibarchive/libarchive/archive_getdate.h"))
132
133 ;;; The "bootstrap" CMake. It is used to build 'cmake-minimal' below, as well
134 ;;; as any dependencies that need cmake-build-system.
135 (define-public cmake-bootstrap
136 (package
137 (name "cmake-bootstrap")
138 (version "3.16.5")
139 (source (origin
140 (method url-fetch)
141 (uri (string-append "https://cmake.org/files/v"
142 (version-major+minor version)
143 "/cmake-" version ".tar.gz"))
144 (sha256
145 (base32
146 "1z4bb8z6b4dvq5hrvajrf1hyybqay3xybyimf71w1jgcp180nxjz"))
147 (modules '((guix build utils)
148 (ice-9 ftw)))
149 (snippet
150 `(begin
151 ;; CMake bundles its dependencies in the "Utilities" directory.
152 ;; Delete those to ensure the system libraries are used.
153 (define preserved-files
154 '(,@%preserved-third-party-files
155 ;; Use the bundled JsonCpp during bootstrap to work around
156 ;; a circular dependency. TODO: JsonCpp can be built with
157 ;; Meson instead of CMake, but meson-build-system currently
158 ;; does not support cross-compilation.
159 "Utilities/cmjsoncpp"
160 ;; LibUV is required to bootstrap the initial build system.
161 "Utilities/cmlibuv"))
162
163 (file-system-fold (lambda (dir stat result) ;enter?
164 (or (string=? "Utilities" dir) ;init
165 ;; The bundled dependencies are
166 ;; distinguished by having a "cm"
167 ;; prefix to their upstream names.
168 (and (string-prefix? "Utilities/cm" dir)
169 (not (member dir preserved-files)))))
170 (lambda (file stat result) ;leaf
171 (unless (or (member file preserved-files)
172 ;; Preserve top-level files.
173 (string=? "Utilities"
174 (dirname file)))
175 (delete-file file)))
176 (const #t) ;down
177 (lambda (dir stat result) ;up
178 (when (equal? (scandir dir) '("." ".."))
179 (rmdir dir)))
180 (const #t) ;skip
181 (lambda (file stat errno result)
182 (format (current-error-port)
183 "warning: failed to delete ~a: ~a~%"
184 file (strerror errno)))
185 #t
186 "Utilities"
187 lstat)
188 #t))
189 (patches (search-patches "cmake-curl-certificates.patch"))))
190 (build-system gnu-build-system)
191 (arguments
192 `(#:test-target "test"
193 #:configure-flags
194 (let ((out (assoc-ref %outputs "out"))
195 (parallel-job-count (number->string (parallel-job-count))))
196 (list "--verbose"
197 (string-append "--parallel=" parallel-job-count)
198 (string-append "--prefix=" out)
199 "--system-libs"
200 "--no-system-jsoncpp"
201 ;; By default, the man pages and other docs land
202 ;; in PREFIX/man and PREFIX/doc, but we want them
203 ;; in share/{man,doc}. Note that unlike
204 ;; autoconf-generated configure scripts, cmake's
205 ;; configure prepends "PREFIX/" to what we pass
206 ;; to --mandir and --docdir.
207 "--mandir=share/man"
208 ,(string-append "--docdir=share/doc/cmake-"
209 (version-major+minor version))
210
211 ;; By default CMake is built without any optimizations. Use
212 ;; the recommended Release target for a ~2.5x speedup.
213 "--" "-DCMAKE_BUILD_TYPE=Release"))
214 #:make-flags
215 (let ((skipped-tests
216 (list ,@%common-disabled-tests
217 "CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
218 ;; This test fails when ARGS (below) is in use, see
219 ;; <https://gitlab.kitware.com/cmake/cmake/issues/17165>.
220 "CTestCoverageCollectGCOV")))
221 (list
222 (string-append
223 ;; These arguments apply for the tests only.
224 "ARGS=-j " (number->string (parallel-job-count))
225 " --output-on-failure"
226 " --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
227 #:phases
228 (modify-phases %standard-phases
229 ,@%common-build-phases
230 (add-before 'configure 'set-paths
231 (lambda _
232 ;; Help cmake's bootstrap process to find system libraries
233 (begin
234 (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
235 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
236 (getenv "C_INCLUDE_PATH")))
237 #t)))
238 ;; CMake uses its own configure script.
239 (replace 'configure
240 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
241 (apply invoke "./configure" configure-flags))))))
242 (inputs
243 `(("bzip2" ,bzip2)
244 ("curl" ,curl-minimal)
245 ("expat" ,expat)
246 ("file" ,file)
247 ("libarchive" ,libarchive)
248 ,@(if (hurd-target?)
249 '()
250 `(("libuv" ,libuv))) ;not supported on the Hurd
251 ("ncurses" ,ncurses) ;required for ccmake
252 ("rhash" ,rhash)
253 ("zlib" ,zlib)))
254 (native-search-paths
255 (list (search-path-specification
256 (variable "CMAKE_PREFIX_PATH")
257 (files '("")))
258 ;; "cmake-curl-certificates.patch" changes CMake to honor 'SSL_CERT_DIR'
259 ;; and 'SSL_CERT_FILE', hence these search path entries.
260 (search-path-specification
261 (variable "SSL_CERT_DIR")
262 (separator #f) ;single entry
263 (files '("etc/ssl/certs")))
264 (search-path-specification
265 (variable "SSL_CERT_FILE")
266 (file-type 'regular)
267 (separator #f) ;single entry
268 (files '("etc/ssl/certs/ca-certificates.crt")))))
269 (home-page "https://cmake.org/")
270 (synopsis "Cross-platform build system")
271 (description
272 "CMake is a family of tools designed to build, test and package software.
273 CMake is used to control the software compilation process using simple platform
274 and compiler independent configuration files. CMake generates native makefiles
275 and workspaces that can be used in the compiler environment of your choice.")
276 (properties '((hidden? . #t)))
277 (license (list license:bsd-3 ; cmake
278 license:expat ; cmjsoncpp is dual MIT/public domain
279 license:public-domain)))) ; cmlibarchive/archive_getdate.c
280
281 ;;; This minimal variant of CMake does not include the documentation. It is
282 ;;; used by the cmake-build-system.
283 (define-public cmake-minimal
284 (package
285 (inherit cmake-bootstrap)
286 (name "cmake-minimal")
287 (source (origin
288 (inherit (package-source cmake-bootstrap))
289 (snippet
290 (match (origin-snippet (package-source cmake-bootstrap))
291 ((_ _ exp ...)
292 ;; Now we can delete the remaining software bundles.
293 (append `(begin
294 (define preserved-files ',%preserved-third-party-files))
295 exp))))))
296 (inputs
297 `(("curl" ,curl)
298 ("jsoncpp" ,jsoncpp)
299 ,@(alist-delete "curl" (package-inputs cmake-bootstrap))))
300 (build-system cmake-build-system)
301 (arguments
302 `(#:configure-flags
303 (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
304 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
305 ,(version-major+minor (package-version
306 cmake-bootstrap))))
307
308 ;; This is the CMake used in cmake-build-system. Ensure compiler
309 ;; optimizations are enabled to save size and CPU cycles.
310 #:build-type "Release"
311 #:phases
312 (modify-phases %standard-phases
313 ,@%common-build-phases
314 (replace 'check
315 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
316 (let ((skipped-tests (list ,@%common-disabled-tests
317 ;; This test requires the bundled libuv.
318 "BootstrapTest")))
319 (if tests?
320 (begin
321 (invoke "ctest" "-j" (if parallel-tests?
322 (number->string (parallel-job-count))
323 "1")
324 "--exclude-regex"
325 (string-append "^(" (string-join skipped-tests "|") ")$")))
326 (format #t "test suite not run~%"))
327 #t))))
328 ,@(if (%current-target-system)
329 '()
330 `(#:cmake ,cmake-bootstrap))))))
331
332 ;;; The "user-facing" CMake, now with manuals and HTML documentation.
333 (define-public cmake
334 (package
335 (inherit cmake-minimal)
336 (name "cmake")
337 (version "3.19.2")
338 ;; TODO: Move the following source field to the cmake-bootstrap package in
339 ;; the next rebuild cycle.
340 (source (origin
341 (inherit (package-source cmake-bootstrap))
342 (uri (string-append "https://cmake.org/files/v"
343 (version-major+minor version)
344 "/cmake-" version ".tar.gz"))
345 (sha256
346 (base32
347 "1w67w0ak6vf37501dlz9yhnzlvvpw1w10n2nm3hi7yxp4cxzvq73"))
348 (snippet
349 (match (origin-snippet (package-source cmake-bootstrap))
350 ((_ _ exp ...)
351 ;; Now we can delete the remaining software bundles.
352 (append `(begin
353 (define preserved-files
354 '(,@%preserved-third-party-files
355 ;; TODO: Move this file to the
356 ;; %preserved-third-party-files variable in
357 ;; the next rebuild cycle.
358 "Utilities/cm3p" ;CMake header wrappers
359 ;; Use the bundled JsonCpp during bootstrap
360 ;; to work around a circular dependency.
361 ;; TODO: JsonCpp can be built with Meson
362 ;; instead of CMake, but meson-build-system
363 ;; currently does not support
364 ;; cross-compilation.
365 "Utilities/cmjsoncpp"
366 ;; LibUV is required to bootstrap the initial
367 ;; build system.
368 "Utilities/cmlibuv")))
369 exp))))))
370 (arguments
371 (substitute-keyword-arguments (package-arguments cmake-minimal)
372 ;; Use cmake-minimal this time.
373 ((#:cmake _ #f)
374 (if (%current-target-system)
375 cmake-minimal-cross
376 cmake-minimal))
377
378 ;; Enable debugging information for convenience.
379 ((#:build-type _ #f) "RelWithDebInfo")
380
381 ((#:configure-flags flags ''())
382 `(append (list "-DSPHINX_INFO=ON" "-DSPHINX_MAN=ON" "-DSPHINX_HTML=ON"
383 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
384 ,(version-major+minor (package-version
385 cmake-minimal)))
386 "-DCMAKE_INFO_DIR=share/info"
387 "-DCMAKE_MAN_DIR=share/man")
388 ,flags))
389 ((#:phases phases)
390 `(modify-phases ,phases
391 ;; TODO: Remove this override in the next rebuild cycle and adjust
392 ;; the %common-build-phases variable instead: the
393 ;; Utilities/Release/release_cmake.cmake file no longer exists in
394 ;; version 3.19.0.
395 (replace 'patch-bin-sh
396 (lambda _
397 ;; Replace "/bin/sh" by the right path in... a lot of
398 ;; files.
399 (substitute*
400 '("Modules/CompilerId/Xcode-3.pbxproj.in"
401 "Modules/Internal/CPack/CPack.RuntimeScript.in"
402 "Source/cmGlobalXCodeGenerator.cxx"
403 "Source/cmLocalUnixMakefileGenerator3.cxx"
404 "Source/cmExecProgramCommand.cxx"
405 "Tests/CMakeLists.txt"
406 "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
407 (("/bin/sh") (which "sh")))
408 #t))
409 ;; TODO: Remove this override in the next rebuild cycle and adjust
410 ;; the %common-disabled-tests variable instead.
411 (replace 'check
412 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
413 (let ((skipped-tests (list ,@%common-disabled-tests
414 ;; This test fails for unknown reason.
415 "RunCMake.file-GET_RUNTIME_DEPENDENCIES"
416 ;; This test requires the bundled libuv.
417 "BootstrapTest")))
418 (if tests?
419 (begin
420 (invoke "ctest" "-j" (if parallel-tests?
421 (number->string (parallel-job-count))
422 "1")
423 "--exclude-regex"
424 (string-append "^(" (string-join skipped-tests "|") ")$")))
425 (format #t "test suite not run~%"))
426 #t)))
427 (add-after 'install 'move-html-doc
428 (lambda* (#:key outputs #:allow-other-keys)
429 (let ((out (assoc-ref outputs "out"))
430 (doc (assoc-ref outputs "doc"))
431 (html (string-append "/share/doc/cmake-"
432 ,(version-major+minor
433 (package-version cmake-minimal))
434 "/html")))
435 (copy-recursively (string-append out html)
436 (string-append doc html))
437 (delete-file-recursively (string-append out html))
438 #t)))))))
439 ;; Extra inputs required to build the documentation.
440 (native-inputs
441 `(,@(package-native-inputs cmake-minimal)
442 ("python-sphinx" ,python-sphinx)
443 ("texinfo" ,texinfo)))
444 (outputs '("out" "doc"))
445 (properties (alist-delete 'hidden? (package-properties cmake-minimal)))))
446
447 (define-public cmake-minimal-cross
448 (package
449 (inherit cmake-minimal)
450 (name "cmake-minimal-cross")
451 (native-search-paths '())
452 (search-paths
453 (package-native-search-paths cmake-minimal))))
454
455 (define-public emacs-cmake-mode
456 (package
457 (inherit cmake)
458 (name "emacs-cmake-mode")
459 (native-inputs '())
460 (inputs '())
461 (outputs '("out"))
462 (build-system emacs-build-system)
463 (arguments
464 `(#:phases
465 (modify-phases %standard-phases
466 (add-after 'unpack 'chdir-elisp
467 ;; Elisp directory is not in root of the source.
468 (lambda _
469 (chdir "Auxiliary")
470 #t)))))
471 (synopsis "Emacs major mode for editing Cmake expressions")
472 (description "@code{cmakeos-mode} provides an Emacs major mode for editing
473 Cmake files. It supports syntax highlighting, indenting and refilling of
474 comments.")))