You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

368 lines
16 KiB

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013 Cyril Roelandt <>
;;; Copyright © 2014 Mark H Weaver <>
;;; Copyright © 2014 Eric Bavier <>
;;; Copyright © 2014 Ian Denhardt <>
;;; Copyright © 2015 Sou Bunnbu <>
;;; Copyright © 2016 Efraim Flashner <>
;;; Copyright © 2017, 2018, 2020 Marius Bakke <>
;;; Copyright © 2018 Arun Isaac <>
;;; Copyright © 2018 Tobias Geerinckx-Rice <>
;;; Copyright © 2019 Maxim Cournoyer <>
;;; Copyright © 2019 Pierre-Moana Levesque <>
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <>
;;; This file is part of GNU Guix.
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <>.
(define-module (gnu packages cmake)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix utils)
#:use-module (guix deprecation)
#:use-module (guix build-system gnu)
#:use-module (guix build-system cmake)
#:use-module (guix build-system emacs)
#:use-module (gnu packages)
#:use-module (gnu packages backup)
#:use-module (gnu packages compression)
#:use-module (gnu packages crypto)
#:use-module (gnu packages curl)
#:use-module (gnu packages file)
#:use-module (gnu packages hurd)
#:use-module (gnu packages libevent)
#:use-module (gnu packages ncurses)
#:use-module (gnu packages serialization)
#:use-module (gnu packages sphinx)
#:use-module (gnu packages texinfo)
#:use-module (gnu packages xml)
#:use-module (ice-9 match)
#:use-module (srfi srfi-1))
;;; Build phases shared between 'cmake-bootstrap' and the later variants
;;; that use cmake-build-system.
(define %common-build-phases
`((add-after 'unpack 'split-package
;; Remove files that have been packaged in other package recipes.
(lambda _
(delete-file "Auxiliary/cmake-mode.el")
(substitute* "Auxiliary/CMakeLists.txt"
((".*cmake-mode.el.*") ""))
(add-before 'configure 'patch-bin-sh
(lambda _
;; Replace "/bin/sh" by the right path in... a lot of
;; files.
(("/bin/sh") (which "sh")))
(define %common-disabled-tests
'(;; This test copies from GCC and tries to modify its RPATH,
;; but does not cope with the file being read-only.
;; This test requires network access.
;; This test requires 'ldconfig' which is not available in Guix.
(define %preserved-third-party-files
'(;; 'Source/cm_getdate.c' includes archive_getdate.c wholesale, so it must
;; be available along with the required headers.
;;; The "bootstrap" CMake. It is used to build 'cmake-minimal' below, as well
;;; as any dependencies that need cmake-build-system.
(define-public cmake-bootstrap
(name "cmake-bootstrap")
(version "3.16.5")
(source (origin
(method url-fetch)
(uri (string-append ""
(version-major+minor version)
"/cmake-" version ".tar.gz"))
(modules '((guix build utils)
(ice-9 ftw)))
;; CMake bundles its dependencies in the "Utilities" directory.
;; Delete those to ensure the system libraries are used.
(define preserved-files
;; Use the bundled JsonCpp during bootstrap to work around
;; a circular dependency. TODO: JsonCpp can be built with
;; Meson instead of CMake, but meson-build-system currently
;; does not support cross-compilation.
;; LibUV is required to bootstrap the initial build system.
(file-system-fold (lambda (dir stat result) ;enter?
(or (string=? "Utilities" dir) ;init
;; The bundled dependencies are
;; distinguished by having a "cm"
;; prefix to their upstream names.
(and (string-prefix? "Utilities/cm" dir)
(not (member dir preserved-files)))))
(lambda (file stat result) ;leaf
(unless (or (member file preserved-files)
;; Preserve top-level files.
(string=? "Utilities"
(dirname file)))
(delete-file file)))
(const #t) ;down
(lambda (dir stat result) ;up
(when (equal? (scandir dir) '("." ".."))
(rmdir dir)))
(const #t) ;skip
(lambda (file stat errno result)
(format (current-error-port)
"warning: failed to delete ~a: ~a~%"
file (strerror errno)))
(patches (search-patches "cmake-curl-certificates.patch"))))
(build-system gnu-build-system)
`(#:test-target "test"
(let ((out (assoc-ref %outputs "out"))
(parallel-job-count (number->string (parallel-job-count))))
(list "--verbose"
(string-append "--parallel=" parallel-job-count)
(string-append "--prefix=" out)
;; By default, the man pages and other docs land
;; in PREFIX/man and PREFIX/doc, but we want them
;; in share/{man,doc}. Note that unlike
;; autoconf-generated configure scripts, cmake's
;; configure prepends "PREFIX/" to what we pass
;; to --mandir and --docdir.
,(string-append "--docdir=share/doc/cmake-"
(version-major+minor version))
;; By default CMake is built without any optimizations. Use
;; the recommended Release target for a ~2.5x speedup.
"--" "-DCMAKE_BUILD_TYPE=Release"))
(let ((skipped-tests
(list ,@%common-disabled-tests
"CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
;; This test fails when ARGS (below) is in use, see
;; <>.
;; These arguments apply for the tests only.
"ARGS=-j " (number->string (parallel-job-count))
" --output-on-failure"
" --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
(modify-phases %standard-phases
(add-before 'configure 'set-paths
(lambda _
;; Help cmake's bootstrap process to find system libraries
(setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
(getenv "C_INCLUDE_PATH")))
;; CMake uses its own configure script.
(replace 'configure
(lambda* (#:key (configure-flags '()) #:allow-other-keys)
(apply invoke "./configure" configure-flags))))))
`(("bzip2" ,bzip2)
("curl" ,curl-minimal)
("expat" ,expat)
("file" ,file)
("libarchive" ,libarchive)
,@(if (hurd-target?)
`(("libuv" ,libuv))) ;not supported on the Hurd
("ncurses" ,ncurses) ;required for ccmake
("rhash" ,rhash)
("zlib" ,zlib)))
(list (search-path-specification
(variable "CMAKE_PREFIX_PATH")
(files '("")))
;; "cmake-curl-certificates.patch" changes CMake to honor 'SSL_CERT_DIR'
;; and 'SSL_CERT_FILE', hence these search path entries.
(variable "SSL_CERT_DIR")
(separator #f) ;single entry
(files '("etc/ssl/certs")))
(variable "SSL_CERT_FILE")
(file-type 'regular)
(separator #f) ;single entry
(files '("etc/ssl/certs/ca-certificates.crt")))))
(home-page "")
(synopsis "Cross-platform build system")
"CMake is a family of tools designed to build, test and package software.
CMake is used to control the software compilation process using simple platform
and compiler independent configuration files. CMake generates native makefiles
and workspaces that can be used in the compiler environment of your choice.")
(properties '((hidden? . #t)))
(license (list license:bsd-3 ; cmake
license:expat ; cmjsoncpp is dual MIT/public domain
license:public-domain)))) ; cmlibarchive/archive_getdate.c
;;; This minimal variant of CMake does not include the documentation. It is
;;; used by the cmake-build-system.
(define-public cmake-minimal
(inherit cmake-bootstrap)
(name "cmake-minimal")
(source (origin
(inherit (package-source cmake-bootstrap))
(match (origin-snippet (package-source cmake-bootstrap))
((_ _ exp ...)
;; Now we can delete the remaining software bundles.
(append `(begin
(define preserved-files ',%preserved-third-party-files))
`(("curl" ,curl)
("jsoncpp" ,jsoncpp)
,@(alist-delete "curl" (package-inputs cmake-bootstrap))))
(build-system cmake-build-system)
(string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
,(version-major+minor (package-version
;; This is the CMake used in cmake-build-system. Ensure compiler
;; optimizations are enabled to save size and CPU cycles.
#:build-type "Release"
(modify-phases %standard-phases
(replace 'check
(lambda* (#:key tests? parallel-tests? #:allow-other-keys)
(let ((skipped-tests (list ,@%common-disabled-tests
;; This test requires the bundled libuv.
(if tests?
(invoke "ctest" "-j" (if parallel-tests?
(number->string (parallel-job-count))
(string-append "^(" (string-join skipped-tests "|") ")$")))
(format #t "test suite not run~%"))
,@(if (%current-target-system)
`(#:cmake ,cmake-bootstrap))))))
;;; The "user-facing" CMake, now with manuals and HTML documentation.
(define-public cmake
(inherit cmake-minimal)
(name "cmake")
(substitute-keyword-arguments (package-arguments cmake-minimal)
;; Use cmake-minimal this time.
((#:cmake _ #f)
(if (%current-target-system)
;; Enable debugging information for convenience.
((#:build-type _ #f) "RelWithDebInfo")
((#:configure-flags flags ''())
(string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
,(version-major+minor (package-version
((#:phases phases)
`(modify-phases ,phases
(add-after 'install 'move-html-doc
(lambda* (#:key outputs #:allow-other-keys)
(let ((out (assoc-ref outputs "out"))
(doc (assoc-ref outputs "doc"))
(html (string-append "/share/doc/cmake-"
(package-version cmake-minimal))
(copy-recursively (string-append out html)
(string-append doc html))
(delete-file-recursively (string-append out html))
;; Extra inputs required to build the documentation.
`(,@(package-native-inputs cmake-minimal)
("python-sphinx" ,python-sphinx)
("texinfo" ,texinfo)))
(outputs '("out" "doc"))
(properties (alist-delete 'hidden? (package-properties cmake-minimal)))))
(define-public cmake-minimal-cross
(inherit cmake-minimal)
(name "cmake-minimal-cross")
(native-search-paths '())
(package-native-search-paths cmake-minimal))))
(define-public emacs-cmake-mode
(inherit cmake)
(name "emacs-cmake-mode")
(native-inputs '())
(inputs '())
(outputs '("out"))
(build-system emacs-build-system)
(modify-phases %standard-phases
(add-after 'unpack 'chdir-elisp
;; Elisp directory is not in root of the source.
(lambda _
(chdir "Auxiliary")
(synopsis "Emacs major mode for editing Cmake expressions")
(description "@code{cmakeos-mode} provides an Emacs major mode for editing
Cmake files. It supports syntax highlighting, indenting and refilling of