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-after 'unpack 'use-system-libarchive
64 ;; 'Source/cm_get_date.c' includes archive_getdate.c wholesale,
65 ;; so it needs to be available along with the header file.
66 (lambda* (#:key native-inputs inputs #:allow-other-keys)
67 (let ((libarchive-source (assoc-ref (or native-inputs inputs)
68 "libarchive:source"))
69 ;; XXX: We can not use ,(package-version libarchive) here due to
70 ;; a cyclic module reference at the top-level.
71 (libarchive-version "3.4.1")
72 (files-to-unpack '("libarchive/archive_getdate.c"
73 "libarchive/archive_getdate.h")))
74 (mkdir-p "Utilities/cmlibarchive")
75 (apply invoke "tar" "-xvf" libarchive-source
76 "--strip-components=1"
77 "-C" "Utilities/cmlibarchive"
78 (map (lambda (file)
79 (string-append "libarchive-" libarchive-version
80 "/" file))
81 files-to-unpack))
82 #t)))
83 (add-before 'configure 'patch-bin-sh
84 (lambda _
85 ;; Replace "/bin/sh" by the right path in... a lot of
86 ;; files.
87 (substitute*
88 '("Modules/CompilerId/Xcode-3.pbxproj.in"
89 "Modules/Internal/CPack/CPack.RuntimeScript.in"
90 "Source/cmGlobalXCodeGenerator.cxx"
91 "Source/cmLocalUnixMakefileGenerator3.cxx"
92 "Source/cmExecProgramCommand.cxx"
93 "Utilities/Release/release_cmake.cmake"
94 "Tests/CMakeLists.txt"
95 "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
96 (("/bin/sh") (which "sh")))
97 #t))))
98
99 (define %common-disabled-tests
100 '(;; This test copies libgcc_s.so.1 from GCC and tries to modify its RPATH,
101 ;; but does not cope with the file being read-only.
102 "BundleUtilities"
103 ;; This test requires network access.
104 "CTestTestUpload"
105 ;; This test requires 'ldconfig' which is not available in Guix.
106 "RunCMake.install"))
107
108 ;;; The "bootstrap" CMake. It is used to build 'cmake-minimal' below, as well
109 ;;; as any dependencies that need cmake-build-system.
110 (define-public cmake-bootstrap
111 (package
112 (name "cmake-bootstrap")
113 (version "3.16.3")
114 (source (origin
115 (method url-fetch)
116 (uri (string-append "https://www.cmake.org/files/v"
117 (version-major+minor version)
118 "/cmake-" version ".tar.gz"))
119 (sha256
120 (base32
121 "0s06wrp0jnw2l4yq94skj53hwnz7lqrmhh96sq7w7njkkggickz5"))
122 (modules '((guix build utils)
123 (ice-9 ftw)))
124 (snippet
125 '(begin
126 (with-directory-excursion "Utilities"
127 ;; CMake bundles its dependencies below "Utilities" with a
128 ;; "cm" prefix in the directory name. Delete those to ensure
129 ;; the system libraries are used.
130 (for-each delete-file-recursively
131 (scandir
132 "."
133 (lambda (file)
134 (and (string-prefix? "cm" file)
135 (eq? 'directory (stat:type (stat file)))
136
137 ;; These inputs are required to bootstrap
138 ;; the initial build system. They are
139 ;; deleted in 'cmake-minimal' below.
140 ;; TODO: Consider building jsoncpp with
141 ;; Meson instead, once meson-build-system
142 ;; learns cross-compilation.
143 (not (string=? "cmjsoncpp" file))
144 (not (string=? "cmlibuv" file)))))))
145 #t))
146 (patches (search-patches "cmake-curl-certificates.patch"))))
147 (build-system gnu-build-system)
148 (arguments
149 `(#:test-target "test"
150 #:configure-flags
151 (let ((out (assoc-ref %outputs "out"))
152 (parallel-job-count (number->string (parallel-job-count))))
153 (list "--verbose"
154 (string-append "--parallel=" parallel-job-count)
155 (string-append "--prefix=" out)
156 "--system-libs"
157 "--no-system-jsoncpp"
158 ;; By default, the man pages and other docs land
159 ;; in PREFIX/man and PREFIX/doc, but we want them
160 ;; in share/{man,doc}. Note that unlike
161 ;; autoconf-generated configure scripts, cmake's
162 ;; configure prepends "PREFIX/" to what we pass
163 ;; to --mandir and --docdir.
164 "--mandir=share/man"
165 ,(string-append "--docdir=share/doc/cmake-"
166 (version-major+minor version))
167
168 ;; By default CMake is built without any optimizations. Use
169 ;; the recommended Release target for a ~2.5x speedup.
170 "--" "-DCMAKE_BUILD_TYPE=Release"))
171 #:make-flags
172 (let ((skipped-tests
173 (list ,@%common-disabled-tests
174 "CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
175 ;; This test fails when ARGS (below) is in use, see
176 ;; <https://gitlab.kitware.com/cmake/cmake/issues/17165>.
177 "CTestCoverageCollectGCOV")))
178 (list
179 (string-append
180 ;; These arguments apply for the tests only.
181 "ARGS=-j " (number->string (parallel-job-count))
182 " --output-on-failure"
183 " --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
184 #:phases
185 (modify-phases %standard-phases
186 ,@%common-build-phases
187 (add-before 'configure 'set-paths
188 (lambda _
189 ;; Help cmake's bootstrap process to find system libraries
190 (begin
191 (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
192 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
193 (getenv "C_INCLUDE_PATH")))
194 #t)))
195 ;; CMake uses its own configure script.
196 (replace 'configure
197 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
198 (apply invoke "./configure" configure-flags))))))
199 (native-inputs
200 `(("libarchive:source" ,(package-source libarchive))))
201 (inputs
202 `(("bzip2" ,bzip2)
203 ("curl" ,curl-minimal)
204 ("expat" ,expat)
205 ("file" ,file)
206 ("libarchive" ,libarchive)
207 ("libuv" ,libuv)
208 ("ncurses" ,ncurses) ;required for ccmake
209 ("rhash" ,rhash)
210 ("zlib" ,zlib)))
211 (native-search-paths
212 (list (search-path-specification
213 (variable "CMAKE_PREFIX_PATH")
214 (files '("")))
215 ;; "cmake-curl-certificates.patch" changes CMake to honor 'SSL_CERT_DIR'
216 ;; and 'SSL_CERT_FILE', hence these search path entries.
217 (search-path-specification
218 (variable "SSL_CERT_DIR")
219 (separator #f) ;single entry
220 (files '("etc/ssl/certs")))
221 (search-path-specification
222 (variable "SSL_CERT_FILE")
223 (file-type 'regular)
224 (separator #f) ;single entry
225 (files '("etc/ssl/certs/ca-certificates.crt")))))
226 (home-page "https://cmake.org/")
227 (synopsis "Cross-platform build system")
228 (description
229 "CMake is a family of tools designed to build, test and package software.
230 CMake is used to control the software compilation process using simple platform
231 and compiler independent configuration files. CMake generates native makefiles
232 and workspaces that can be used in the compiler environment of your choice.")
233 (properties '((hidden? . #t)))
234 (license (list license:bsd-3 ; cmake
235 license:expat ; cmjsoncpp is dual MIT/public domain
236 license:public-domain)))) ; cmlibarchive/archive_getdate.c
237
238 ;;; This minimal variant of CMake does not include the documentation. It is
239 ;;; used by the cmake-build-system.
240 (define-public cmake-minimal
241 (package
242 (inherit cmake-bootstrap)
243 (name "cmake-minimal")
244 (source (origin
245 (inherit (package-source cmake-bootstrap))
246 (snippet
247 (match (origin-snippet (package-source cmake-bootstrap))
248 ((begin exp ...)
249 ;; Now we can delete the remaining software bundles.
250 (append '(begin
251 (for-each delete-file-recursively
252 '("Utilities/cmjsoncpp"
253 "Utilities/cmlibuv")))
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.")))