packages: 'package-grafts' trims native inputs.
[guix.git] / guix / build / cmake-build-system.scm
blob128ab28fe54cdd865417d0c8ead7af254b7dde04
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
4 ;;; Copyright © 2014, 2015 Andreas Enge <andreas@enge.fr>
5 ;;;
6 ;;; This file is part of GNU Guix.
7 ;;;
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
12 ;;;
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;;; GNU General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
21 (define-module (guix build cmake-build-system)
22   #:use-module ((guix build gnu-build-system) #:prefix gnu:)
23   #:use-module (guix build utils)
24   #:use-module (ice-9 match)
25   #:export (%standard-phases
26             cmake-build))
28 ;; Commentary:
30 ;; Builder-side code of the standard cmake build procedure.
32 ;; Code:
34 (define* (configure #:key outputs (configure-flags '()) (out-of-source? #t)
35                     build-type target
36                     #:allow-other-keys)
37   "Configure the given package."
38   (let* ((out        (assoc-ref outputs "out"))
39          (abs-srcdir (getcwd))
40          (srcdir     (if out-of-source?
41                          (string-append "../" (basename abs-srcdir))
42                          ".")))
43     (format #t "source directory: ~s (relative from build: ~s)~%"
44             abs-srcdir srcdir)
45     (when out-of-source?
46       (mkdir "../build")
47       (chdir "../build"))
48     (format #t "build directory: ~s~%" (getcwd))
50     (let ((args `(,srcdir
51                   ,@(if build-type
52                         (list (string-append "-DCMAKE_BUILD_TYPE="
53                                              build-type))
54                         '())
55                   ,(string-append "-DCMAKE_INSTALL_PREFIX=" out)
56                   ;; add input libraries to rpath
57                   "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE"
58                   ;; add (other) libraries of the project itself to rpath
59                   ,(string-append "-DCMAKE_INSTALL_RPATH=" out "/lib")
60                   ;; enable verbose output from builds
61                   "-DCMAKE_VERBOSE_MAKEFILE=ON"
63                   ;;  Cross-build
64                   ,@(if target
65                         (list (string-append "-DCMAKE_C_COMPILER="
66                                              target "-gcc")
67                               (if (string-contains target "mingw")
68                                   "-DCMAKE_SYSTEM_NAME=Windows"
69                                   "-DCMAKE_SYSTEM_NAME=Linux"))
70                         '())
71                   ,@configure-flags)))
72       (format #t "running 'cmake' with arguments ~s~%" args)
73       (zero? (apply system* "cmake" args)))))
75 (define* (check #:key (tests? #t) (parallel-tests? #t) (test-target "test")
76                 #:allow-other-keys)
77   (let ((gnu-check (assoc-ref gnu:%standard-phases 'check)))
78     (setenv "CTEST_OUTPUT_ON_FAILURE" "1")
79     (gnu-check #:tests? tests? #:test-target test-target
80               #:parallel-tests? parallel-tests?)))
82 (define %standard-phases
83   ;; Everything is as with the GNU Build System except for the `configure'
84   ;; and 'check' phases.
85   (modify-phases gnu:%standard-phases
86     (replace 'check check)
87     (replace 'configure configure)))
89 (define* (cmake-build #:key inputs (phases %standard-phases)
90                       #:allow-other-keys #:rest args)
91   "Build the given package, applying all of PHASES in order."
92   (apply gnu:gnu-build #:inputs inputs #:phases phases args))
94 ;;; cmake-build-system.scm ends here