gnu: ruby-pandoc-ruby: Use pandoc instead of ghc-pandoc.
[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 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>
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 utils)
35 #:use-module (guix deprecation)
36 #:use-module (guix build-system gnu)
37 #:use-module (guix build-system cmake)
38 #:use-module (guix build-system emacs)
39 #:use-module (gnu packages)
40 #:use-module (gnu packages backup)
41 #:use-module (gnu packages compression)
42 #:use-module (gnu packages crypto)
43 #:use-module (gnu packages curl)
44 #:use-module (gnu packages file)
45 #:use-module (gnu packages hurd)
46 #:use-module (gnu packages libevent)
47 #:use-module (gnu packages ncurses)
48 #:use-module (gnu packages serialization)
49 #:use-module (gnu packages sphinx)
50 #:use-module (gnu packages texinfo)
51 #:use-module (gnu packages xml)
52 #:use-module (ice-9 match)
53 #:use-module (srfi srfi-1))
54
55 ;;; Build phases shared between 'cmake-bootstrap' and the later variants
56 ;;; that use cmake-build-system.
57 (define %common-build-phases
58 `((add-after 'unpack 'split-package
59 ;; Remove files that have been packaged in other package recipes.
60 (lambda _
61 (delete-file "Auxiliary/cmake-mode.el")
62 (substitute* "Auxiliary/CMakeLists.txt"
63 ((".*cmake-mode.el.*") ""))
64 #t))
65 (add-before 'configure 'patch-bin-sh
66 (lambda _
67 ;; Replace "/bin/sh" by the right path in... a lot of
68 ;; files.
69 (substitute*
70 '("Modules/CompilerId/Xcode-3.pbxproj.in"
71 "Modules/Internal/CPack/CPack.RuntimeScript.in"
72 "Source/cmGlobalXCodeGenerator.cxx"
73 "Source/cmLocalUnixMakefileGenerator3.cxx"
74 "Source/cmExecProgramCommand.cxx"
75 "Utilities/Release/release_cmake.cmake"
76 "Tests/CMakeLists.txt"
77 "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
78 (("/bin/sh") (which "sh")))
79 #t))))
80
81 (define %common-disabled-tests
82 '(;; This test copies libgcc_s.so.1 from GCC and tries to modify its RPATH,
83 ;; but does not cope with the file being read-only.
84 "BundleUtilities"
85 ;; This test requires network access.
86 "CTestTestUpload"
87 ;; This test requires 'ldconfig' which is not available in Guix.
88 "RunCMake.install"))
89
90 (define %preserved-third-party-files
91 '(;; 'Source/cm_getdate.c' includes archive_getdate.c wholesale, so it must
92 ;; be available along with the required headers.
93 "Utilities/cmlibarchive/libarchive/archive_getdate.c"
94 "Utilities/cmlibarchive/libarchive/archive_getdate.h"))
95
96 ;;; The "bootstrap" CMake. It is used to build 'cmake-minimal' below, as well
97 ;;; as any dependencies that need cmake-build-system.
98 (define-public cmake-bootstrap
99 (package
100 (name "cmake-bootstrap")
101 (version "3.16.5")
102 (source (origin
103 (method url-fetch)
104 (uri (string-append "https://www.cmake.org/files/v"
105 (version-major+minor version)
106 "/cmake-" version ".tar.gz"))
107 (sha256
108 (base32
109 "1z4bb8z6b4dvq5hrvajrf1hyybqay3xybyimf71w1jgcp180nxjz"))
110 (modules '((guix build utils)
111 (ice-9 ftw)))
112 (snippet
113 `(begin
114 ;; CMake bundles its dependencies in the "Utilities" directory.
115 ;; Delete those to ensure the system libraries are used.
116 (define preserved-files
117 '(,@%preserved-third-party-files
118 ;; Use the bundled JsonCpp during bootstrap to work around
119 ;; a circular dependency. TODO: JsonCpp can be built with
120 ;; Meson instead of CMake, but meson-build-system currently
121 ;; does not support cross-compilation.
122 "Utilities/cmjsoncpp"
123 ;; LibUV is required to bootstrap the initial build system.
124 "Utilities/cmlibuv"))
125
126 (file-system-fold (lambda (dir stat result) ;enter?
127 (or (string=? "Utilities" dir) ;init
128 ;; The bundled dependencies are
129 ;; distinguished by having a "cm"
130 ;; prefix to their upstream names.
131 (and (string-prefix? "Utilities/cm" dir)
132 (not (member dir preserved-files)))))
133 (lambda (file stat result) ;leaf
134 (unless (or (member file preserved-files)
135 ;; Preserve top-level files.
136 (string=? "Utilities"
137 (dirname file)))
138 (delete-file file)))
139 (const #t) ;down
140 (lambda (dir stat result) ;up
141 (when (equal? (scandir dir) '("." ".."))
142 (rmdir dir)))
143 (const #t) ;skip
144 (lambda (file stat errno result)
145 (format (current-error-port)
146 "warning: failed to delete ~a: ~a~%"
147 file (strerror errno)))
148 #t
149 "Utilities"
150 lstat)
151 #t))
152 (patches (search-patches "cmake-curl-certificates.patch"))))
153 (build-system gnu-build-system)
154 (arguments
155 `(#:test-target "test"
156 #:configure-flags
157 (let ((out (assoc-ref %outputs "out"))
158 (parallel-job-count (number->string (parallel-job-count))))
159 (list "--verbose"
160 (string-append "--parallel=" parallel-job-count)
161 (string-append "--prefix=" out)
162 "--system-libs"
163 "--no-system-jsoncpp"
164 ;; By default, the man pages and other docs land
165 ;; in PREFIX/man and PREFIX/doc, but we want them
166 ;; in share/{man,doc}. Note that unlike
167 ;; autoconf-generated configure scripts, cmake's
168 ;; configure prepends "PREFIX/" to what we pass
169 ;; to --mandir and --docdir.
170 "--mandir=share/man"
171 ,(string-append "--docdir=share/doc/cmake-"
172 (version-major+minor version))
173
174 ;; By default CMake is built without any optimizations. Use
175 ;; the recommended Release target for a ~2.5x speedup.
176 "--" "-DCMAKE_BUILD_TYPE=Release"))
177 #:make-flags
178 (let ((skipped-tests
179 (list ,@%common-disabled-tests
180 "CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
181 ;; This test fails when ARGS (below) is in use, see
182 ;; <https://gitlab.kitware.com/cmake/cmake/issues/17165>.
183 "CTestCoverageCollectGCOV")))
184 (list
185 (string-append
186 ;; These arguments apply for the tests only.
187 "ARGS=-j " (number->string (parallel-job-count))
188 " --output-on-failure"
189 " --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
190 #:phases
191 (modify-phases %standard-phases
192 ,@%common-build-phases
193 (add-before 'configure 'set-paths
194 (lambda _
195 ;; Help cmake's bootstrap process to find system libraries
196 (begin
197 (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
198 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
199 (getenv "C_INCLUDE_PATH")))
200 #t)))
201 ;; CMake uses its own configure script.
202 (replace 'configure
203 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
204 (apply invoke "./configure" configure-flags))))))
205 (inputs
206 `(("bzip2" ,bzip2)
207 ("curl" ,curl-minimal)
208 ("expat" ,expat)
209 ("file" ,file)
210 ("libarchive" ,libarchive)
211 ,@(if (hurd-target?)
212 '()
213 `(("libuv" ,libuv))) ;not supported on the Hurd
214 ("ncurses" ,ncurses) ;required for ccmake
215 ("rhash" ,rhash)
216 ("zlib" ,zlib)))
217 (native-search-paths
218 (list (search-path-specification
219 (variable "CMAKE_PREFIX_PATH")
220 (files '("")))
221 ;; "cmake-curl-certificates.patch" changes CMake to honor 'SSL_CERT_DIR'
222 ;; and 'SSL_CERT_FILE', hence these search path entries.
223 (search-path-specification
224 (variable "SSL_CERT_DIR")
225 (separator #f) ;single entry
226 (files '("etc/ssl/certs")))
227 (search-path-specification
228 (variable "SSL_CERT_FILE")
229 (file-type 'regular)
230 (separator #f) ;single entry
231 (files '("etc/ssl/certs/ca-certificates.crt")))))
232 (home-page "https://cmake.org/")
233 (synopsis "Cross-platform build system")
234 (description
235 "CMake is a family of tools designed to build, test and package software.
236 CMake is used to control the software compilation process using simple platform
237 and compiler independent configuration files. CMake generates native makefiles
238 and workspaces that can be used in the compiler environment of your choice.")
239 (properties '((hidden? . #t)))
240 (license (list license:bsd-3 ; cmake
241 license:expat ; cmjsoncpp is dual MIT/public domain
242 license:public-domain)))) ; cmlibarchive/archive_getdate.c
243
244 ;;; This minimal variant of CMake does not include the documentation. It is
245 ;;; used by the cmake-build-system.
246 (define-public cmake-minimal
247 (package
248 (inherit cmake-bootstrap)
249 (name "cmake-minimal")
250 (source (origin
251 (inherit (package-source cmake-bootstrap))
252 (snippet
253 (match (origin-snippet (package-source cmake-bootstrap))
254 ((_ _ exp ...)
255 ;; Now we can delete the remaining software bundles.
256 (append `(begin
257 (define preserved-files ',%preserved-third-party-files))
258 exp))))))
259 (inputs
260 `(("curl" ,curl)
261 ("jsoncpp" ,jsoncpp)
262 ,@(alist-delete "curl" (package-inputs cmake-bootstrap))))
263 (build-system cmake-build-system)
264 (arguments
265 `(#:configure-flags
266 (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
267 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
268 ,(version-major+minor (package-version
269 cmake-bootstrap))))
270
271 ;; This is the CMake used in cmake-build-system. Ensure compiler
272 ;; optimizations are enabled to save size and CPU cycles.
273 #:build-type "Release"
274 #:phases
275 (modify-phases %standard-phases
276 ,@%common-build-phases
277 (replace 'check
278 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
279 (let ((skipped-tests (list ,@%common-disabled-tests
280 ;; This test requires the bundled libuv.
281 "BootstrapTest")))
282 (if tests?
283 (begin
284 (invoke "ctest" "-j" (if parallel-tests?
285 (number->string (parallel-job-count))
286 "1")
287 "--exclude-regex"
288 (string-append "^(" (string-join skipped-tests "|") ")$")))
289 (format #t "test suite not run~%"))
290 #t))))
291 ,@(if (%current-target-system)
292 '()
293 `(#:cmake ,cmake-bootstrap))))))
294
295 ;;; The "user-facing" CMake, now with manuals and HTML documentation.
296 (define-public cmake
297 (package
298 (inherit cmake-minimal)
299 (name "cmake")
300 (arguments
301 (substitute-keyword-arguments (package-arguments cmake-minimal)
302 ;; Use cmake-minimal this time.
303 ((#:cmake _ #f)
304 (if (%current-target-system)
305 cmake-minimal-cross
306 cmake-minimal))
307
308 ;; Enable debugging information for convenience.
309 ((#:build-type _ #f) "RelWithDebInfo")
310
311 ((#:configure-flags flags ''())
312 `(append (list "-DSPHINX_INFO=ON" "-DSPHINX_MAN=ON" "-DSPHINX_HTML=ON"
313 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
314 ,(version-major+minor (package-version
315 cmake-minimal)))
316 "-DCMAKE_INFO_DIR=share/info"
317 "-DCMAKE_MAN_DIR=share/man")
318 ,flags))
319 ((#:phases phases)
320 `(modify-phases ,phases
321 (add-after 'install 'move-html-doc
322 (lambda* (#:key outputs #:allow-other-keys)
323 (let ((out (assoc-ref outputs "out"))
324 (doc (assoc-ref outputs "doc"))
325 (html (string-append "/share/doc/cmake-"
326 ,(version-major+minor
327 (package-version cmake-minimal))
328 "/html")))
329 (copy-recursively (string-append out html)
330 (string-append doc html))
331 (delete-file-recursively (string-append out html))
332 #t)))))))
333 ;; Extra inputs required to build the documentation.
334 (native-inputs
335 `(,@(package-native-inputs cmake-minimal)
336 ("python-sphinx" ,python-sphinx)
337 ("texinfo" ,texinfo)))
338 (outputs '("out" "doc"))
339 (properties (alist-delete 'hidden? (package-properties cmake-minimal)))))
340
341 (define-public cmake-minimal-cross
342 (package
343 (inherit cmake-minimal)
344 (name "cmake-minimal-cross")
345 (native-search-paths '())
346 (search-paths
347 (package-native-search-paths cmake-minimal))))
348
349 (define-public emacs-cmake-mode
350 (package
351 (inherit cmake)
352 (name "emacs-cmake-mode")
353 (native-inputs '())
354 (inputs '())
355 (outputs '("out"))
356 (build-system emacs-build-system)
357 (arguments
358 `(#:phases
359 (modify-phases %standard-phases
360 (add-after 'unpack 'chdir-elisp
361 ;; Elisp directory is not in root of the source.
362 (lambda _
363 (chdir "Auxiliary")
364 #t)))))
365 (synopsis "Emacs major mode for editing Cmake expressions")
366 (description "@code{cmakeos-mode} provides an Emacs major mode for editing
367 Cmake files. It supports syntax highlighting, indenting and refilling of
368 comments.")))