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>
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 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))
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.
61 (delete-file "Auxiliary/cmake-mode.el")
62 (substitute* "Auxiliary/CMakeLists.txt"
63 ((".*cmake-mode.el.*") ""))
65 (add-before 'configure 'patch-bin-sh
67 ;; Replace "/bin/sh" by the right path in... a lot of
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")))
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.
85 ;; This test requires network access.
87 ;; This test requires 'ldconfig' which is not available in Guix.
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"))
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
100 (name "cmake-bootstrap")
104 (uri (string-append "https://cmake.org/files/v"
105 (version-major+minor version)
106 "/cmake-" version ".tar.gz"))
109 "1z4bb8z6b4dvq5hrvajrf1hyybqay3xybyimf71w1jgcp180nxjz"))
110 (modules '((guix build utils)
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"))
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"
140 (lambda (dir stat result) ;up
141 (when (equal? (scandir dir) '("." ".."))
144 (lambda (file stat errno result)
145 (format (current-error-port)
146 "warning: failed to delete ~a: ~a~%"
147 file (strerror errno)))
152 (patches (search-patches "cmake-curl-certificates.patch"))))
153 (build-system gnu-build-system)
155 `(#:test-target "test"
157 (let ((out (assoc-ref %outputs "out"))
158 (parallel-job-count (number->string (parallel-job-count))))
160 (string-append "--parallel=" parallel-job-count)
161 (string-append "--prefix=" out)
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.
171 ,(string-append "--docdir=share/doc/cmake-"
172 (version-major+minor version))
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"))
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")))
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 "\\|") "\\)$")))
191 (modify-phases %standard-phases
192 ,@%common-build-phases
193 (add-before 'configure 'set-paths
195 ;; Help cmake's bootstrap process to find system libraries
197 (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
198 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
199 (getenv "C_INCLUDE_PATH")))
201 ;; CMake uses its own configure script.
203 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
204 (apply invoke "./configure" configure-flags))))))
207 ("curl" ,curl-minimal)
210 ("libarchive" ,libarchive)
213 `(("libuv" ,libuv))) ;not supported on the Hurd
214 ("ncurses" ,ncurses) ;required for ccmake
218 (list (search-path-specification
219 (variable "CMAKE_PREFIX_PATH")
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")
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")
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
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
248 (inherit cmake-bootstrap)
249 (name "cmake-minimal")
251 (inherit (package-source cmake-bootstrap))
253 (match (origin-snippet (package-source cmake-bootstrap))
255 ;; Now we can delete the remaining software bundles.
257 (define preserved-files ',%preserved-third-party-files))
262 ,@(alist-delete "curl" (package-inputs cmake-bootstrap))))
263 (build-system cmake-build-system)
266 (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
267 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
268 ,(version-major+minor (package-version
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"
275 (modify-phases %standard-phases
276 ,@%common-build-phases
278 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
279 (let ((skipped-tests (list ,@%common-disabled-tests
280 ;; This test requires the bundled libuv.
284 (invoke "ctest" "-j" (if parallel-tests?
285 (number->string (parallel-job-count))
288 (string-append "^(" (string-join skipped-tests "|") ")$")))
289 (format #t "test suite not run~%"))
291 ,@(if (%current-target-system)
293 `(#:cmake ,cmake-bootstrap))))))
295 ;;; The "user-facing" CMake, now with manuals and HTML documentation.
298 (inherit cmake-minimal)
301 (substitute-keyword-arguments (package-arguments cmake-minimal)
302 ;; Use cmake-minimal this time.
304 (if (%current-target-system)
308 ;; Enable debugging information for convenience.
309 ((#:build-type _ #f) "RelWithDebInfo")
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
316 "-DCMAKE_INFO_DIR=share/info"
317 "-DCMAKE_MAN_DIR=share/man")
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))
329 (copy-recursively (string-append out html)
330 (string-append doc html))
331 (delete-file-recursively (string-append out html))
333 ;; Extra inputs required to build the documentation.
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)))))
341 (define-public cmake-minimal-cross
343 (inherit cmake-minimal)
344 (name "cmake-minimal-cross")
345 (native-search-paths '())
347 (package-native-search-paths cmake-minimal))))
349 (define-public emacs-cmake-mode
352 (name "emacs-cmake-mode")
356 (build-system emacs-build-system)
359 (modify-phases %standard-phases
360 (add-after 'unpack 'chdir-elisp
361 ;; Elisp directory is not in root of the source.
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