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>
14 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
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.
59 (delete-file "Auxiliary/cmake-mode.el")
60 (substitute* "Auxiliary/CMakeLists.txt"
61 ((".*cmake-mode.el.*") ""))
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)
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"
79 (string-append "libarchive-" libarchive-version
83 (add-before 'configure 'patch-bin-sh
85 ;; Replace "/bin/sh" by the right path in... a lot of
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")))
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.
103 ;; This test requires network access.
105 ;; This test requires 'ldconfig' which is not available in Guix.
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
112 (name "cmake-bootstrap")
116 (uri (string-append "https://www.cmake.org/files/v"
117 (version-major+minor version)
118 "/cmake-" version ".tar.gz"))
121 "0s06wrp0jnw2l4yq94skj53hwnz7lqrmhh96sq7w7njkkggickz5"))
122 (modules '((guix build utils)
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
134 (and (string-prefix? "cm" file)
135 (eq? 'directory (stat:type (stat file)))
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)))))))
146 (patches (search-patches "cmake-curl-certificates.patch"))))
147 (build-system gnu-build-system)
149 `(#:test-target "test"
151 (let ((out (assoc-ref %outputs "out"))
152 (parallel-job-count (number->string (parallel-job-count))))
154 (string-append "--parallel=" parallel-job-count)
155 (string-append "--prefix=" out)
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.
165 ,(string-append "--docdir=share/doc/cmake-"
166 (version-major+minor version))
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"))
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")))
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 "\\|") "\\)$")))
185 (modify-phases %standard-phases
186 ,@%common-build-phases
187 (add-before 'configure 'set-paths
189 ;; Help cmake's bootstrap process to find system libraries
191 (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
192 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
193 (getenv "C_INCLUDE_PATH")))
195 ;; CMake uses its own configure script.
197 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
198 (apply invoke "./configure" configure-flags))))))
200 `(("libarchive:source" ,(package-source libarchive))))
203 ("curl" ,curl-minimal)
206 ("libarchive" ,libarchive)
208 ("ncurses" ,ncurses) ;required for ccmake
212 (list (search-path-specification
213 (variable "CMAKE_PREFIX_PATH")
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")
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")
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
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
242 (inherit cmake-bootstrap)
243 (name "cmake-minimal")
245 (inherit (package-source cmake-bootstrap))
247 (match (origin-snippet (package-source cmake-bootstrap))
249 ;; Now we can delete the remaining software bundles.
251 (for-each delete-file-recursively
252 '("Utilities/cmjsoncpp"
253 "Utilities/cmlibuv")))
258 ,@(alist-delete "curl" (package-inputs cmake-bootstrap))))
259 (build-system cmake-build-system)
262 (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
263 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
264 ,(version-major+minor (package-version
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"
271 (modify-phases %standard-phases
272 ,@%common-build-phases
274 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
275 (let ((skipped-tests (list ,@%common-disabled-tests
276 ;; This test requires the bundled libuv.
280 (invoke "ctest" "-j" (if parallel-tests?
281 (number->string (parallel-job-count))
284 (string-append "^(" (string-join skipped-tests "|") ")$")))
285 (format #t "test suite not run~%"))
287 ,@(if (%current-target-system)
289 `(#:cmake ,cmake-bootstrap))))))
291 ;;; The "user-facing" CMake, now with manuals and HTML documentation.
294 (inherit cmake-minimal)
297 (substitute-keyword-arguments (package-arguments cmake-minimal)
298 ;; Use cmake-minimal this time.
300 (if (%current-target-system)
304 ;; Enable debugging information for convenience.
305 ((#:build-type _ #f) "RelWithDebInfo")
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
312 "-DCMAKE_INFO_DIR=share/info"
313 "-DCMAKE_MAN_DIR=share/man")
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))
325 (copy-recursively (string-append out html)
326 (string-append doc html))
327 (delete-file-recursively (string-append out html))
329 ;; Extra inputs required to build the documentation.
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)))))
337 (define-public cmake-minimal-cross
339 (inherit cmake-minimal)
340 (name "cmake-minimal-cross")
341 (native-search-paths '())
343 (package-native-search-paths cmake-minimal))))
345 (define-public emacs-cmake-mode
348 (name "emacs-cmake-mode")
352 (build-system emacs-build-system)
355 (modify-phases %standard-phases
356 (add-after 'unpack 'chdir-elisp
357 ;; Elisp directory is not in root of the source.
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