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, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
11 ;;; Copyright © 2019, 2020 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>
15 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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 git-download)
35 #:use-module (guix utils)
36 #:use-module (guix deprecation)
37 #:use-module (guix build-system gnu)
38 #:use-module (guix build-system cmake)
39 #:use-module (guix build-system emacs)
40 #:use-module (gnu packages)
41 #:use-module (gnu packages backup)
42 #:use-module (gnu packages compression)
43 #:use-module (gnu packages crypto)
44 #:use-module (gnu packages curl)
45 #:use-module (gnu packages file)
46 #:use-module (gnu packages hurd)
47 #:use-module (gnu packages kde-frameworks)
48 #:use-module (gnu packages libevent)
49 #:use-module (gnu packages ncurses)
50 #:use-module (gnu packages serialization)
51 #:use-module (gnu packages sphinx)
52 #:use-module (gnu packages texinfo)
53 #:use-module (gnu packages xml)
54 #:use-module (ice-9 match)
55 #:use-module (srfi srfi-1))
57 (define-public cmake-shared
58 (let ((commit "8122f2b96c8da38ea41b653cf69958e75fe2129d")
63 (git-version "1.1.0" revision commit))
69 (url "https://github.com/lirios/cmake-shared.git")
72 (git-file-name name version))
74 (base32 "05avwzqcnliwx9h7qi1kl0iz4smqmxc4vkavyjbmlc6h2b97i58g"))
75 (modules '((guix build utils)
80 (delete-file-recursively "3rdparty")))))
81 (build-system cmake-build-system)
83 `(#:tests? #f)) ; No target
85 `(("extra-cmake-modules" ,extra-cmake-modules)))
86 (synopsis "Shared CMake functions and macros")
87 (description "CMake-Shared are shared functions and macros for projects
88 using the CMake build system.")
89 (home-page "https://github.com/lirios/cmake-shared/")
90 (license license:bsd-3))))
92 ;;; Build phases shared between 'cmake-bootstrap' and the later variants
93 ;;; that use cmake-build-system.
94 (define %common-build-phases
95 `((add-after 'unpack 'split-package
96 ;; Remove files that have been packaged in other package recipes.
98 (delete-file "Auxiliary/cmake-mode.el")
99 (substitute* "Auxiliary/CMakeLists.txt"
100 ((".*cmake-mode.el.*") ""))
102 (add-before 'configure 'patch-bin-sh
104 ;; Replace "/bin/sh" by the right path in... a lot of
107 '("Modules/CompilerId/Xcode-3.pbxproj.in"
108 "Modules/Internal/CPack/CPack.RuntimeScript.in"
109 "Source/cmGlobalXCodeGenerator.cxx"
110 "Source/cmLocalUnixMakefileGenerator3.cxx"
111 "Source/cmExecProgramCommand.cxx"
112 "Utilities/Release/release_cmake.cmake"
113 "Tests/CMakeLists.txt"
114 "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
115 (("/bin/sh") (which "sh")))
118 (define %common-disabled-tests
119 '(;; This test copies libgcc_s.so.1 from GCC and tries to modify its RPATH,
120 ;; but does not cope with the file being read-only.
122 ;; This test requires network access.
124 ;; This test requires 'ldconfig' which is not available in Guix.
127 (define %preserved-third-party-files
128 '(;; 'Source/cm_getdate.c' includes archive_getdate.c wholesale, so it must
129 ;; be available along with the required headers.
130 "Utilities/cmlibarchive/libarchive/archive_getdate.c"
131 "Utilities/cmlibarchive/libarchive/archive_getdate.h"))
133 ;;; The "bootstrap" CMake. It is used to build 'cmake-minimal' below, as well
134 ;;; as any dependencies that need cmake-build-system.
135 (define-public cmake-bootstrap
137 (name "cmake-bootstrap")
141 (uri (string-append "https://cmake.org/files/v"
142 (version-major+minor version)
143 "/cmake-" version ".tar.gz"))
146 "1z4bb8z6b4dvq5hrvajrf1hyybqay3xybyimf71w1jgcp180nxjz"))
147 (modules '((guix build utils)
151 ;; CMake bundles its dependencies in the "Utilities" directory.
152 ;; Delete those to ensure the system libraries are used.
153 (define preserved-files
154 '(,@%preserved-third-party-files
155 ;; Use the bundled JsonCpp during bootstrap to work around
156 ;; a circular dependency. TODO: JsonCpp can be built with
157 ;; Meson instead of CMake, but meson-build-system currently
158 ;; does not support cross-compilation.
159 "Utilities/cmjsoncpp"
160 ;; LibUV is required to bootstrap the initial build system.
161 "Utilities/cmlibuv"))
163 (file-system-fold (lambda (dir stat result) ;enter?
164 (or (string=? "Utilities" dir) ;init
165 ;; The bundled dependencies are
166 ;; distinguished by having a "cm"
167 ;; prefix to their upstream names.
168 (and (string-prefix? "Utilities/cm" dir)
169 (not (member dir preserved-files)))))
170 (lambda (file stat result) ;leaf
171 (unless (or (member file preserved-files)
172 ;; Preserve top-level files.
173 (string=? "Utilities"
177 (lambda (dir stat result) ;up
178 (when (equal? (scandir dir) '("." ".."))
181 (lambda (file stat errno result)
182 (format (current-error-port)
183 "warning: failed to delete ~a: ~a~%"
184 file (strerror errno)))
189 (patches (search-patches "cmake-curl-certificates.patch"))))
190 (build-system gnu-build-system)
192 `(#:test-target "test"
194 (let ((out (assoc-ref %outputs "out"))
195 (parallel-job-count (number->string (parallel-job-count))))
197 (string-append "--parallel=" parallel-job-count)
198 (string-append "--prefix=" out)
200 "--no-system-jsoncpp"
201 ;; By default, the man pages and other docs land
202 ;; in PREFIX/man and PREFIX/doc, but we want them
203 ;; in share/{man,doc}. Note that unlike
204 ;; autoconf-generated configure scripts, cmake's
205 ;; configure prepends "PREFIX/" to what we pass
206 ;; to --mandir and --docdir.
208 ,(string-append "--docdir=share/doc/cmake-"
209 (version-major+minor version))
211 ;; By default CMake is built without any optimizations. Use
212 ;; the recommended Release target for a ~2.5x speedup.
213 "--" "-DCMAKE_BUILD_TYPE=Release"))
216 (list ,@%common-disabled-tests
217 "CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
218 ;; This test fails when ARGS (below) is in use, see
219 ;; <https://gitlab.kitware.com/cmake/cmake/issues/17165>.
220 "CTestCoverageCollectGCOV")))
223 ;; These arguments apply for the tests only.
224 "ARGS=-j " (number->string (parallel-job-count))
225 " --output-on-failure"
226 " --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
228 (modify-phases %standard-phases
229 ,@%common-build-phases
230 (add-before 'configure 'set-paths
232 ;; Help cmake's bootstrap process to find system libraries
234 (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
235 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
236 (getenv "C_INCLUDE_PATH")))
238 ;; CMake uses its own configure script.
240 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
241 (apply invoke "./configure" configure-flags))))))
244 ("curl" ,curl-minimal)
247 ("libarchive" ,libarchive)
250 `(("libuv" ,libuv))) ;not supported on the Hurd
251 ("ncurses" ,ncurses) ;required for ccmake
255 (list (search-path-specification
256 (variable "CMAKE_PREFIX_PATH")
258 ;; "cmake-curl-certificates.patch" changes CMake to honor 'SSL_CERT_DIR'
259 ;; and 'SSL_CERT_FILE', hence these search path entries.
260 (search-path-specification
261 (variable "SSL_CERT_DIR")
262 (separator #f) ;single entry
263 (files '("etc/ssl/certs")))
264 (search-path-specification
265 (variable "SSL_CERT_FILE")
267 (separator #f) ;single entry
268 (files '("etc/ssl/certs/ca-certificates.crt")))))
269 (home-page "https://cmake.org/")
270 (synopsis "Cross-platform build system")
272 "CMake is a family of tools designed to build, test and package software.
273 CMake is used to control the software compilation process using simple platform
274 and compiler independent configuration files. CMake generates native makefiles
275 and workspaces that can be used in the compiler environment of your choice.")
276 (properties '((hidden? . #t)))
277 (license (list license:bsd-3 ; cmake
278 license:expat ; cmjsoncpp is dual MIT/public domain
279 license:public-domain)))) ; cmlibarchive/archive_getdate.c
281 ;;; This minimal variant of CMake does not include the documentation. It is
282 ;;; used by the cmake-build-system.
283 (define-public cmake-minimal
285 (inherit cmake-bootstrap)
286 (name "cmake-minimal")
288 (inherit (package-source cmake-bootstrap))
290 (match (origin-snippet (package-source cmake-bootstrap))
292 ;; Now we can delete the remaining software bundles.
294 (define preserved-files ',%preserved-third-party-files))
299 ,@(alist-delete "curl" (package-inputs cmake-bootstrap))))
300 (build-system cmake-build-system)
303 (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
304 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
305 ,(version-major+minor (package-version
308 ;; This is the CMake used in cmake-build-system. Ensure compiler
309 ;; optimizations are enabled to save size and CPU cycles.
310 #:build-type "Release"
312 (modify-phases %standard-phases
313 ,@%common-build-phases
315 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
316 (let ((skipped-tests (list ,@%common-disabled-tests
317 ;; This test requires the bundled libuv.
321 (invoke "ctest" "-j" (if parallel-tests?
322 (number->string (parallel-job-count))
325 (string-append "^(" (string-join skipped-tests "|") ")$")))
326 (format #t "test suite not run~%"))
328 ,@(if (%current-target-system)
330 `(#:cmake ,cmake-bootstrap))))))
332 ;;; The "user-facing" CMake, now with manuals and HTML documentation.
335 (inherit cmake-minimal)
338 ;; TODO: Move the following source field to the cmake-bootstrap package in
339 ;; the next rebuild cycle.
341 (inherit (package-source cmake-bootstrap))
342 (uri (string-append "https://cmake.org/files/v"
343 (version-major+minor version)
344 "/cmake-" version ".tar.gz"))
347 "1w67w0ak6vf37501dlz9yhnzlvvpw1w10n2nm3hi7yxp4cxzvq73"))
349 (match (origin-snippet (package-source cmake-bootstrap))
351 ;; Now we can delete the remaining software bundles.
353 (define preserved-files
354 '(,@%preserved-third-party-files
355 ;; TODO: Move this file to the
356 ;; %preserved-third-party-files variable in
357 ;; the next rebuild cycle.
358 "Utilities/cm3p" ;CMake header wrappers
359 ;; Use the bundled JsonCpp during bootstrap
360 ;; to work around a circular dependency.
361 ;; TODO: JsonCpp can be built with Meson
362 ;; instead of CMake, but meson-build-system
363 ;; currently does not support
364 ;; cross-compilation.
365 "Utilities/cmjsoncpp"
366 ;; LibUV is required to bootstrap the initial
368 "Utilities/cmlibuv")))
371 (substitute-keyword-arguments (package-arguments cmake-minimal)
372 ;; Use cmake-minimal this time.
374 (if (%current-target-system)
378 ;; Enable debugging information for convenience.
379 ((#:build-type _ #f) "RelWithDebInfo")
381 ((#:configure-flags flags ''())
382 `(append (list "-DSPHINX_INFO=ON" "-DSPHINX_MAN=ON" "-DSPHINX_HTML=ON"
383 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
384 ,(version-major+minor (package-version
386 "-DCMAKE_INFO_DIR=share/info"
387 "-DCMAKE_MAN_DIR=share/man")
390 `(modify-phases ,phases
391 ;; TODO: Remove this override in the next rebuild cycle and adjust
392 ;; the %common-build-phases variable instead: the
393 ;; Utilities/Release/release_cmake.cmake file no longer exists in
395 (replace 'patch-bin-sh
397 ;; Replace "/bin/sh" by the right path in... a lot of
400 '("Modules/CompilerId/Xcode-3.pbxproj.in"
401 "Modules/Internal/CPack/CPack.RuntimeScript.in"
402 "Source/cmGlobalXCodeGenerator.cxx"
403 "Source/cmLocalUnixMakefileGenerator3.cxx"
404 "Source/cmExecProgramCommand.cxx"
405 "Tests/CMakeLists.txt"
406 "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
407 (("/bin/sh") (which "sh")))
409 ;; TODO: Remove this override in the next rebuild cycle and adjust
410 ;; the %common-disabled-tests variable instead.
412 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
413 (let ((skipped-tests (list ,@%common-disabled-tests
414 ;; This test fails for unknown reason.
415 "RunCMake.file-GET_RUNTIME_DEPENDENCIES"
416 ;; This test requires the bundled libuv.
420 (invoke "ctest" "-j" (if parallel-tests?
421 (number->string (parallel-job-count))
424 (string-append "^(" (string-join skipped-tests "|") ")$")))
425 (format #t "test suite not run~%"))
427 (add-after 'install 'move-html-doc
428 (lambda* (#:key outputs #:allow-other-keys)
429 (let ((out (assoc-ref outputs "out"))
430 (doc (assoc-ref outputs "doc"))
431 (html (string-append "/share/doc/cmake-"
432 ,(version-major+minor
433 (package-version cmake-minimal))
435 (copy-recursively (string-append out html)
436 (string-append doc html))
437 (delete-file-recursively (string-append out html))
439 ;; Extra inputs required to build the documentation.
441 `(,@(package-native-inputs cmake-minimal)
442 ("python-sphinx" ,python-sphinx)
443 ("texinfo" ,texinfo)))
444 (outputs '("out" "doc"))
445 (properties (alist-delete 'hidden? (package-properties cmake-minimal)))))
447 (define-public cmake-minimal-cross
449 (inherit cmake-minimal)
450 (name "cmake-minimal-cross")
451 (native-search-paths '())
453 (package-native-search-paths cmake-minimal))))
455 (define-public emacs-cmake-mode
458 (name "emacs-cmake-mode")
462 (build-system emacs-build-system)
465 (modify-phases %standard-phases
466 (add-after 'unpack 'chdir-elisp
467 ;; Elisp directory is not in root of the source.
471 (synopsis "Emacs major mode for editing Cmake expressions")
472 (description "@code{cmakeos-mode} provides an Emacs major mode for editing
473 Cmake files. It supports syntax highlighting, indenting and refilling of