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