Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / cmake.scm
CommitLineData
b6a64843
CR
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
6212b8e5 3;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
c824d34f 4;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
29a7c98a 5;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
477a752e 6;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
3b698589 7;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
ff5733d1 8;;; Copyright © 2017, 2018, 2020 Marius Bakke <mbakke@fastmail.com>
89db6c6d 9;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
4f3958da 10;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
2f33a732 11;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
a8446b40 12;;; Copyright © 2019 Pierre-Moana Levesque <pierre.moana.levesque@gmail.com>
b6a64843
CR
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)
db909bf2 30 #:use-module ((guix licenses) #:prefix license:)
b6a64843
CR
31 #:use-module (guix packages)
32 #:use-module (guix download)
29a7c98a 33 #:use-module (guix utils)
0de28f9e 34 #:use-module (guix deprecation)
b6a64843 35 #:use-module (guix build-system gnu)
013c5c23 36 #:use-module (guix build-system cmake)
aa4818c3 37 #:use-module (guix build-system emacs)
b6a64843 38 #:use-module (gnu packages)
c824d34f
EB
39 #:use-module (gnu packages backup)
40 #:use-module (gnu packages compression)
1568cc14 41 #:use-module (gnu packages crypto)
c824d34f 42 #:use-module (gnu packages curl)
6212b8e5 43 #:use-module (gnu packages file)
4bbb7d48 44 #:use-module (gnu packages libevent)
21e5e1e0 45 #:use-module (gnu packages ncurses)
b5fc075d 46 #:use-module (gnu packages serialization)
57df83e0 47 #:use-module (gnu packages sphinx)
2f33a732
MC
48 #:use-module (gnu packages texinfo)
49 #:use-module (gnu packages xml)
b5fc075d 50 #:use-module (ice-9 match)
2f33a732 51 #:use-module (srfi srfi-1))
b6a64843 52
013c5c23
MB
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.
7c1ea931 110(define-public cmake-bootstrap
b6a64843 111 (package
7c1ea931 112 (name "cmake-bootstrap")
848a3cdb 113 (version "3.16.3")
b6a64843 114 (source (origin
12420c80
AI
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
848a3cdb 121 "0s06wrp0jnw2l4yq94skj53hwnz7lqrmhh96sq7w7njkkggickz5"))
ed24dda7
MB
122 (modules '((guix build utils)
123 (ice-9 ftw)))
12420c80
AI
124 (snippet
125 '(begin
12420c80 126 (with-directory-excursion "Utilities"
ed24dda7
MB
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.
12420c80 130 (for-each delete-file-recursively
ed24dda7
MB
131 (scandir
132 "."
133 (lambda (file)
134 (and (string-prefix? "cm" file)
135 (eq? 'directory (stat:type (stat file)))
136
013c5c23
MB
137 ;; These inputs are required to bootstrap
138 ;; the initial build system. They are
139 ;; deleted in 'cmake-minimal' below.
ed24dda7
MB
140 ;; TODO: Consider building jsoncpp with
141 ;; Meson instead, once meson-build-system
142 ;; learns cross-compilation.
143 (not (string=? "cmjsoncpp" file))
ed24dda7
MB
144 (not (string=? "cmlibuv" file)))))))
145 #t))
a4de5cfd 146 (patches (search-patches "cmake-curl-certificates.patch"))))
b6a64843
CR
147 (build-system gnu-build-system)
148 (arguments
6212b8e5 149 `(#:test-target "test"
2f33a732
MC
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"
b5fc075d 157 "--no-system-jsoncpp"
2f33a732
MC
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-"
fa8e0a53
MB
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"))
89db6c6d
AI
171 #:make-flags
172 (let ((skipped-tests
013c5c23 173 (list ,@%common-disabled-tests
89db6c6d 174 "CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
013c5c23
MB
175 ;; This test fails when ARGS (below) is in use, see
176 ;; <https://gitlab.kitware.com/cmake/cmake/issues/17165>.
177 "CTestCoverageCollectGCOV")))
89db6c6d
AI
178 (list
179 (string-append
12cb6c31
MB
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 "\\|") "\\)$")))
6e261af1
EF
184 #:phases
185 (modify-phases %standard-phases
013c5c23 186 ,@%common-build-phases
6e261af1
EF
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"))
546bee40
MB
192 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
193 (getenv "C_INCLUDE_PATH")))
4bbb7d48 194 #t)))
2f33a732 195 ;; CMake uses its own configure script.
6e261af1 196 (replace 'configure
2f33a732
MC
197 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
198 (apply invoke "./configure" configure-flags))))))
a8446b40 199 (native-inputs
ac841750
MB
200 `(("libarchive:source" ,(package-source libarchive))))
201 (inputs
89db6c6d 202 `(("bzip2" ,bzip2)
7c1ea931 203 ("curl" ,curl-minimal)
89db6c6d
AI
204 ("expat" ,expat)
205 ("file" ,file)
206 ("libarchive" ,libarchive)
207 ("libuv" ,libuv)
ac841750 208 ("ncurses" ,ncurses) ;required for ccmake
89db6c6d
AI
209 ("rhash" ,rhash)
210 ("zlib" ,zlib)))
0d6f9360
AE
211 (native-search-paths
212 (list (search-path-specification
89db6c6d 213 (variable "CMAKE_PREFIX_PATH")
3cfe76be
MB
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")))))
89db6c6d 226 (home-page "https://cmake.org/")
749b90a5 227 (synopsis "Cross-platform build system")
b6a64843
CR
228 (description
229 "CMake is a family of tools designed to build, test and package software.
230CMake is used to control the software compilation process using simple platform
c824d34f 231and compiler independent configuration files. CMake generates native makefiles
b6a64843 232and workspaces that can be used in the compiler environment of your choice.")
2f33a732
MC
233 (properties '((hidden? . #t)))
234 (license (list license:bsd-3 ; cmake
2f33a732 235 license:expat ; cmjsoncpp is dual MIT/public domain
db909bf2 236 license:public-domain)))) ; cmlibarchive/archive_getdate.c
1568cc14 237
7c1ea931
MB
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")
b5fc075d
MB
244 (source (origin
245 (inherit (package-source cmake-bootstrap))
246 (snippet
247 (match (origin-snippet (package-source cmake-bootstrap))
248 ((begin exp ...)
11f4d877
MB
249 ;; Now we can delete the remaining software bundles.
250 (append '(begin
251 (for-each delete-file-recursively
252 '("Utilities/cmjsoncpp"
253 "Utilities/cmlibuv")))
b5fc075d 254 exp))))))
ac841750 255 (inputs
7c1ea931 256 `(("curl" ,curl)
b5fc075d 257 ("jsoncpp" ,jsoncpp)
ac841750 258 ,@(alist-delete "curl" (package-inputs cmake-bootstrap))))
013c5c23 259 (build-system cmake-build-system)
b5fc075d 260 (arguments
013c5c23
MB
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))))))
7c1ea931
MB
290
291;;; The "user-facing" CMake, now with manuals and HTML documentation.
2f33a732
MC
292(define-public cmake
293 (package
294 (inherit cmake-minimal)
295 (name "cmake")
296 (arguments
297 (substitute-keyword-arguments (package-arguments cmake-minimal)
013c5c23
MB
298 ;; Use cmake-minimal this time.
299 ((#:cmake _ #f)
300 (if (%current-target-system)
301 cmake-minimal-cross
302 cmake-minimal))
28ba01ae
MB
303
304 ;; Enable debugging information for convenience.
305 ((#:build-type _ #f) "RelWithDebInfo")
306
013c5c23
MB
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))
2f33a732
MC
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
534537e2
MO
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
bbdf3666
OP
345(define-public emacs-cmake-mode
346 (package
347 (inherit cmake)
348 (name "emacs-cmake-mode")
5a7c6d02
MB
349 (native-inputs '())
350 (inputs '())
351 (outputs '("out"))
bbdf3666
OP
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 _
5a7c6d02
MB
359 (chdir "Auxiliary")
360 #t)))))
bbdf3666
OP
361 (synopsis "Emacs major mode for editing Cmake expressions")
362 (description "@code{cmakeos-mode} provides an Emacs major mode for editing
363Cmake files. It supports syntax highlighting, indenting and refilling of
364comments.")))