Merge branch 'master' into core-updates
[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 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
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.
20 ;;;
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.
25 ;;;
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/>.
28
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))
52
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.
58 (lambda _
59 (delete-file "Auxiliary/cmake-mode.el")
60 (substitute* "Auxiliary/CMakeLists.txt"
61 ((".*cmake-mode.el.*") ""))
62 #t))
63 (add-before 'configure 'patch-bin-sh
64 (lambda _
65 ;; Replace "/bin/sh" by the right path in... a lot of
66 ;; files.
67 (substitute*
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")))
77 #t))))
78
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.
82 "BundleUtilities"
83 ;; This test requires network access.
84 "CTestTestUpload"
85 ;; This test requires 'ldconfig' which is not available in Guix.
86 "RunCMake.install"))
87
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"))
93
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
97 (package
98 (name "cmake-bootstrap")
99 (version "3.16.5")
100 (source (origin
101 (method url-fetch)
102 (uri (string-append "https://www.cmake.org/files/v"
103 (version-major+minor version)
104 "/cmake-" version ".tar.gz"))
105 (sha256
106 (base32
107 "1z4bb8z6b4dvq5hrvajrf1hyybqay3xybyimf71w1jgcp180nxjz"))
108 (modules '((guix build utils)
109 (ice-9 ftw)))
110 (snippet
111 `(begin
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"))
123
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"
135 (dirname file)))
136 (delete-file file)))
137 (const #t) ;down
138 (lambda (dir stat result) ;up
139 (when (equal? (scandir dir) '("." ".."))
140 (rmdir dir)))
141 (const #t) ;skip
142 (lambda (file stat errno result)
143 (format (current-error-port)
144 "warning: failed to delete ~a: ~a~%"
145 file (strerror errno)))
146 #t
147 "Utilities"
148 lstat)
149 #t))
150 (patches (search-patches "cmake-curl-certificates.patch"))))
151 (build-system gnu-build-system)
152 (arguments
153 `(#:test-target "test"
154 #:configure-flags
155 (let ((out (assoc-ref %outputs "out"))
156 (parallel-job-count (number->string (parallel-job-count))))
157 (list "--verbose"
158 (string-append "--parallel=" parallel-job-count)
159 (string-append "--prefix=" out)
160 "--system-libs"
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.
168 "--mandir=share/man"
169 ,(string-append "--docdir=share/doc/cmake-"
170 (version-major+minor version))
171
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"))
175 #:make-flags
176 (let ((skipped-tests
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")))
182 (list
183 (string-append
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 "\\|") "\\)$")))
188 #:phases
189 (modify-phases %standard-phases
190 ,@%common-build-phases
191 (add-before 'configure 'set-paths
192 (lambda _
193 ;; Help cmake's bootstrap process to find system libraries
194 (begin
195 (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
196 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
197 (getenv "C_INCLUDE_PATH")))
198 #t)))
199 ;; CMake uses its own configure script.
200 (replace 'configure
201 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
202 (apply invoke "./configure" configure-flags))))))
203 (inputs
204 `(("bzip2" ,bzip2)
205 ("curl" ,curl-minimal)
206 ("expat" ,expat)
207 ("file" ,file)
208 ("libarchive" ,libarchive)
209 ("libuv" ,libuv)
210 ("ncurses" ,ncurses) ;required for ccmake
211 ("rhash" ,rhash)
212 ("zlib" ,zlib)))
213 (native-search-paths
214 (list (search-path-specification
215 (variable "CMAKE_PREFIX_PATH")
216 (files '("")))
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")
225 (file-type 'regular)
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")
230 (description
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
239
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
243 (package
244 (inherit cmake-bootstrap)
245 (name "cmake-minimal")
246 (source (origin
247 (inherit (package-source cmake-bootstrap))
248 (snippet
249 (match (origin-snippet (package-source cmake-bootstrap))
250 ((_ _ exp ...)
251 ;; Now we can delete the remaining software bundles.
252 (append `(begin
253 (define preserved-files ',%preserved-third-party-files))
254 exp))))))
255 (inputs
256 `(("curl" ,curl)
257 ("jsoncpp" ,jsoncpp)
258 ,@(alist-delete "curl" (package-inputs cmake-bootstrap))))
259 (build-system cmake-build-system)
260 (arguments
261 `(#:configure-flags
262 (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
263 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
264 ,(version-major+minor (package-version
265 cmake-bootstrap))))
266
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"
270 #:phases
271 (modify-phases %standard-phases
272 ,@%common-build-phases
273 (replace 'check
274 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
275 (let ((skipped-tests (list ,@%common-disabled-tests
276 ;; This test requires the bundled libuv.
277 "BootstrapTest")))
278 (if tests?
279 (begin
280 (invoke "ctest" "-j" (if parallel-tests?
281 (number->string (parallel-job-count))
282 "1")
283 "--exclude-regex"
284 (string-append "^(" (string-join skipped-tests "|") ")$")))
285 (format #t "test suite not run~%"))
286 #t))))
287 ,@(if (%current-target-system)
288 '()
289 `(#:cmake ,cmake-bootstrap))))))
290
291 ;;; The "user-facing" CMake, now with manuals and HTML documentation.
292 (define-public cmake
293 (package
294 (inherit cmake-minimal)
295 (name "cmake")
296 (arguments
297 (substitute-keyword-arguments (package-arguments cmake-minimal)
298 ;; Use cmake-minimal this time.
299 ((#:cmake _ #f)
300 (if (%current-target-system)
301 cmake-minimal-cross
302 cmake-minimal))
303
304 ;; Enable debugging information for convenience.
305 ((#:build-type _ #f) "RelWithDebInfo")
306
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
311 cmake-minimal)))
312 "-DCMAKE_INFO_DIR=share/info"
313 "-DCMAKE_MAN_DIR=share/man")
314 ,flags))
315 ((#:phases phases)
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))
324 "/html")))
325 (copy-recursively (string-append out html)
326 (string-append doc html))
327 (delete-file-recursively (string-append out html))
328 #t)))))))
329 ;; Extra inputs required to build the documentation.
330 (native-inputs
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)))))
336
337 (define-public cmake-minimal-cross
338 (package
339 (inherit cmake-minimal)
340 (name "cmake-minimal-cross")
341 (native-search-paths '())
342 (search-paths
343 (package-native-search-paths cmake-minimal))))
344
345 (define-public emacs-cmake-mode
346 (package
347 (inherit cmake)
348 (name "emacs-cmake-mode")
349 (native-inputs '())
350 (inputs '())
351 (outputs '("out"))
352 (build-system emacs-build-system)
353 (arguments
354 `(#:phases
355 (modify-phases %standard-phases
356 (add-after 'unpack 'chdir-elisp
357 ;; Elisp directory is not in root of the source.
358 (lambda _
359 (chdir "Auxiliary")
360 #t)))))
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
364 comments.")))