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, 2021 Marius Bakke <marius@gnu.org>
9 ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
10 ;;; Copyright © 2018, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
11 ;;; Copyright © 2019, 2020, 2021, 2022 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>
14 ;;; Copyright © 2021 Ricardo Wurmus <rekado@elephly.net>
16 ;;; This file is part of GNU Guix.
18 ;;; GNU Guix is free software; you can redistribute it and/or modify it
19 ;;; under the terms of the GNU General Public License as published by
20 ;;; the Free Software Foundation; either version 3 of the License, or (at
21 ;;; your option) any later version.
23 ;;; GNU Guix is distributed in the hope that it will be useful, but
24 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;;; GNU General Public License for more details.
28 ;;; You should have received a copy of the GNU General Public License
29 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
31 (define-module (gnu packages cmake)
32 #:use-module ((guix licenses) #:prefix license:)
33 #:use-module (guix packages)
34 #:use-module (guix download)
35 #:use-module (guix git-download)
36 #:use-module (guix utils)
37 #:use-module (guix deprecation)
38 #:use-module (guix build-system gnu)
39 #:use-module (guix build-system cmake)
40 #:use-module (guix build-system emacs)
41 #:use-module ((guix search-paths) #:select ($SSL_CERT_DIR $SSL_CERT_FILE))
42 #:use-module (gnu packages)
43 #:use-module (gnu packages backup)
44 #:use-module (gnu packages compression)
45 #:use-module (gnu packages crypto)
46 #:use-module (gnu packages curl)
47 #:use-module (gnu packages file)
48 #:use-module (gnu packages hurd)
49 #:use-module (gnu packages kde-frameworks)
50 #:use-module (gnu packages libevent)
51 #:use-module (gnu packages ncurses)
52 #:use-module (gnu packages serialization)
53 #:use-module (gnu packages sphinx)
54 #:use-module (gnu packages texinfo)
55 #:use-module (gnu packages xml)
56 #:use-module (ice-9 match)
57 #:use-module (srfi srfi-1))
59 (define-public cmake-shared
60 (let ((commit "8122f2b96c8da38ea41b653cf69958e75fe2129d")
65 (git-version "1.1.0" revision commit))
71 (url "https://github.com/lirios/cmake-shared.git")
74 (git-file-name name version))
76 (base32 "05avwzqcnliwx9h7qi1kl0iz4smqmxc4vkavyjbmlc6h2b97i58g"))
77 (modules '((guix build utils)
82 (delete-file-recursively "3rdparty")))))
83 (build-system cmake-build-system)
85 `(#:tests? #f)) ; No target
87 (list extra-cmake-modules))
88 (synopsis "Shared CMake functions and macros")
89 (description "CMake-Shared are shared functions and macros for projects
90 using the CMake build system.")
91 (home-page "https://github.com/lirios/cmake-shared/")
92 (license license:bsd-3))))
94 ;;; Build phases shared between 'cmake-bootstrap' and the later variants
95 ;;; that use cmake-build-system.
96 (define (%common-build-phases)
97 `((add-after 'unpack 'split-package
98 ;; Remove files that have been packaged in other package recipes.
100 (delete-file "Auxiliary/cmake-mode.el")
101 (substitute* "Auxiliary/CMakeLists.txt"
102 ((".*cmake-mode.el.*") ""))
104 ,@(if (target-x86-32?)
105 '((add-after 'unpack 'skip-cpack-txz-test
107 ;; In 'RunCMake.CPack_TXZ', the 'TXZ/THREADED_ALL' test
108 ;; would occasionally fail on i686 with "Internal error
109 ;; initializing compression library: Cannot allocate
110 ;; memory": <https://issues.guix.gnu.org/50617>. Skip it.
111 (substitute* "Tests/RunCMake/CPack/RunCMakeTest.cmake"
112 (("THREADED_ALL \"TXZ;DEB\"")
113 "THREADED_ALL \"DEB\"")))))
115 (add-before 'configure 'patch-bin-sh
117 ;; Replace "/bin/sh" by the right path in... a lot of
120 '("Modules/CompilerId/Xcode-3.pbxproj.in"
121 "Modules/Internal/CPack/CPack.RuntimeScript.in"
122 "Source/cmGlobalXCodeGenerator.cxx"
123 "Source/cmLocalUnixMakefileGenerator3.cxx"
124 "Source/cmExecProgramCommand.cxx"
125 "Tests/CMakeLists.txt"
126 "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
127 (("/bin/sh") (which "sh")))
130 (define %common-disabled-tests
131 '(;; This test copies libgcc_s.so.1 from GCC and tries to modify its RPATH,
132 ;; but does not cope with the file being read-only.
134 ;; These tests require network access.
135 "CTestTestUpload" "CMake.FileDownload"
136 ;; This test requires 'ldconfig' which is not available in Guix.
138 ;; This test fails for unknown reason.
139 "RunCMake.file-GET_RUNTIME_DEPENDENCIES"))
141 (define %preserved-third-party-files
142 '(;; 'Source/cm_getdate.c' includes archive_getdate.c wholesale, so it must
143 ;; be available along with the required headers.
144 "Utilities/cmlibarchive/libarchive/archive_getdate.c"
145 "Utilities/cmlibarchive/libarchive/archive_getdate.h"
146 ;; CMake header wrappers.
149 ;;; The "bootstrap" CMake. It is used to build 'cmake-minimal' below, as well
150 ;;; as any dependencies that need cmake-build-system.
151 (define-public cmake-bootstrap
153 (name "cmake-bootstrap")
157 (uri (string-append "https://cmake.org/files/v"
158 (version-major+minor version)
159 "/cmake-" version ".tar.gz"))
162 "0y2rk316j9m1iqimgwah0z1ii3ggli65dw6hdn4ckx0mqaahlmyr"))
163 (patches (search-patches "cmake-curl-certificates.patch"))))
164 (build-system gnu-build-system)
166 `(#:test-target "test"
168 (let ((out (assoc-ref %outputs "out"))
169 (parallel-job-count (number->string (parallel-job-count))))
171 (string-append "--parallel=" parallel-job-count)
172 (string-append "--prefix=" out)
174 "--no-system-jsoncpp"
175 ;; By default, the man pages and other docs land
176 ;; in PREFIX/man and PREFIX/doc, but we want them
177 ;; in share/{man,doc}. Note that unlike
178 ;; autoconf-generated configure scripts, cmake's
179 ;; configure prepends "PREFIX/" to what we pass
180 ;; to --mandir and --docdir.
182 ,(string-append "--docdir=share/doc/cmake-"
183 (version-major+minor version))
185 ;; By default CMake is built without any optimizations. Use
186 ;; the recommended Release target for a ~2.5x speedup.
187 "--" "-DCMAKE_BUILD_TYPE=Release"))
190 (list ,@%common-disabled-tests
191 "CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
192 ;; This test fails when ARGS (below) is in use, see
193 ;; <https://gitlab.kitware.com/cmake/cmake/issues/17165>.
194 "CTestCoverageCollectGCOV")))
197 ;; These arguments apply for the tests only.
198 "ARGS=-j " (number->string (parallel-job-count))
199 " --output-on-failure"
200 " --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
202 (modify-phases %standard-phases
203 ,@(%common-build-phases)
204 (add-before 'configure 'set-paths
206 ;; Help cmake's bootstrap process to find system libraries
208 (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
209 (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
210 (getenv "C_INCLUDE_PATH")))
212 ;; CMake uses its own configure script.
214 (lambda* (#:key (configure-flags '()) #:allow-other-keys)
215 (apply invoke "./configure" configure-flags))))))
221 ("libarchive" ,libarchive)
224 `(("libuv" ,libuv))) ;not supported on the Hurd
228 (list (search-path-specification
229 (variable "CMAKE_PREFIX_PATH")
231 ;; "cmake-curl-certificates.patch" changes CMake to honor 'SSL_CERT_DIR'
232 ;; and 'SSL_CERT_FILE', hence these search path entries.
235 (home-page "https://cmake.org/")
236 (synopsis "Cross-platform build system")
238 "CMake is a family of tools designed to build, test and package software.
239 CMake is used to control the software compilation process using simple platform
240 and compiler independent configuration files. CMake generates native makefiles
241 and workspaces that can be used in the compiler environment of your choice.")
242 (properties '((hidden? . #t)))
243 (license (list license:bsd-3 ; cmake
244 license:expat ; cmjsoncpp is dual MIT/public domain
245 license:public-domain)))) ; cmlibarchive/archive_getdate.c
247 ;;; This minimal variant of CMake does not include the documentation. It is
248 ;;; used by the cmake-build-system.
249 (define-public cmake-minimal
251 (inherit cmake-bootstrap)
252 (name "cmake-minimal")
254 (inherit (package-source cmake-bootstrap))
255 ;; Purge CMakes bundled dependencies as they are no longer needed.
256 (modules '((ice-9 ftw)))
259 (define preserved-files ',%preserved-third-party-files)
261 (file-system-fold (lambda (dir stat result) ;enter?
262 (or (string=? "Utilities" dir) ;init
263 ;; The bundled dependencies are
264 ;; distinguished by having a "cm"
265 ;; prefix to their upstream names.
266 (and (string-prefix? "Utilities/cm" dir)
267 (not (member dir preserved-files)))))
268 (lambda (file stat result) ;leaf
269 (unless (or (member file preserved-files)
270 ;; Preserve top-level files.
271 (string=? "Utilities"
275 (lambda (dir stat result) ;up
276 (when (equal? (scandir dir) '("." ".."))
279 (lambda (file stat errno result)
280 (format (current-error-port)
281 "warning: failed to delete ~a: ~a~%"
282 file (strerror errno)))
288 (modify-inputs (package-inputs cmake-bootstrap)
290 (build-system cmake-build-system)
293 (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
294 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
295 ,(version-major+minor (package-version
298 ;; This is the CMake used in cmake-build-system. Ensure compiler
299 ;; optimizations are enabled to save size and CPU cycles.
300 #:build-type "Release"
302 (modify-phases %standard-phases
303 ,@(%common-build-phases)
304 (add-after 'install 'delete-help-documentation
305 (lambda* (#:key outputs #:allow-other-keys)
306 (delete-file-recursively
307 (string-append (assoc-ref outputs "out")
309 ,(version-major+minor
310 (package-version cmake-bootstrap))
314 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
315 (let ((skipped-tests (list ,@%common-disabled-tests
316 ;; This test requires the bundled libuv.
320 (invoke "ctest" "-j" (if parallel-tests?
321 (number->string (parallel-job-count))
324 (string-append "^(" (string-join skipped-tests "|") ")$")))
325 (format #t "test suite not run~%"))
327 ,@(if (%current-target-system)
329 `(#:cmake ,cmake-bootstrap))))))
331 ;;; The "user-facing" CMake, now with manuals and HTML documentation.
334 (inherit cmake-minimal)
338 (inherit (package-source cmake-minimal))
340 (uri (string-append "https://cmake.org/files/v"
341 (version-major+minor version)
342 "/cmake-" version ".tar.gz"))
343 (snippet (match (origin-snippet (package-source cmake-minimal))
344 (('begin ('define 'preserved-files ('quote x))
346 `(begin (define preserved-files
347 ',(cons "Utilities/cmelf" x))
351 "1ny8y2dzc6fww9gzb1ml0vjpx4kclphjihkxagxigprxdzq2140d"))
352 (patches (search-patches "cmake-curl-certificates-3.24.patch"))))
353 (outputs '("out" "doc"))
355 (substitute-keyword-arguments (package-arguments cmake-minimal)
356 ;; Use cmake-minimal this time.
358 (if (%current-target-system)
362 ;; Enable debugging information for convenience.
363 ((#:build-type _ #f) "RelWithDebInfo")
365 ((#:configure-flags flags ''())
366 `(append (list "-DSPHINX_INFO=ON" "-DSPHINX_MAN=ON" "-DSPHINX_HTML=ON"
367 (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
368 ,(version-major+minor (package-version
370 "-DCMAKE_INFO_DIR=share/info"
371 "-DCMAKE_MAN_DIR=share/man")
374 `(modify-phases ,phases
375 (delete 'delete-help-documentation)
376 (add-after 'install 'move-html-doc
377 (lambda* (#:key outputs #:allow-other-keys)
378 (let ((out (assoc-ref outputs "out"))
379 (doc (assoc-ref outputs "doc"))
380 (html (string-append "/share/doc/cmake-"
381 ,(version-major+minor
382 (package-version cmake-minimal))
384 (copy-recursively (string-append out html)
385 (string-append doc html))
386 (delete-file-recursively (string-append out html)))))))))
388 (modify-inputs (package-inputs cmake-minimal)
389 (prepend ncurses))) ;required for ccmake
390 ;; Extra inputs required to build the documentation.
392 (modify-inputs (package-native-inputs cmake-minimal)
393 (append python-sphinx
395 (properties (alist-delete 'hidden? (package-properties cmake-minimal)))))
397 (define-public cmake-minimal-cross
399 (inherit cmake-minimal)
400 (name "cmake-minimal-cross")
401 (native-search-paths '())
403 (package-native-search-paths cmake-minimal))))
405 (define-public emacs-cmake-mode
408 (name "emacs-cmake-mode")
412 (build-system emacs-build-system)
415 (modify-phases %standard-phases
416 (add-after 'unpack 'chdir-elisp
417 ;; Elisp directory is not in root of the source.
421 (synopsis "Emacs major mode for editing Cmake expressions")
422 (description "@code{cmakeos-mode} provides an Emacs major mode for editing
423 Cmake files. It supports syntax highlighting, indenting and refilling of