build-system: Introduce "bags" as an intermediate representation.
[jackhill/guix/guix.git] / guix / build-system / cmake.scm
CommitLineData
c6bded8a 1;;; GNU Guix --- Functional package management for GNU
bdb36958 2;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
c6bded8a
CR
3;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (guix build-system cmake)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix derivations)
24 #:use-module (guix build-system)
25 #:use-module (guix build-system gnu)
26 #:use-module (guix packages)
27 #:use-module (ice-9 match)
28 #:export (cmake-build
29 cmake-build-system))
30
31;; Commentary:
32;;
33;; Standard build procedure for packages using CMake. This is implemented as an
34;; extension of `gnu-build-system'.
35;;
36;; Code:
37
0a2873e5
LC
38(define (default-cmake)
39 "Return the default CMake package."
40
41 ;; Do not use `@' to avoid introducing circular dependencies.
42 (let ((module (resolve-interface '(gnu packages cmake))))
8badfc55 43 (module-ref module 'cmake)))
0a2873e5 44
0d5a559f
LC
45(define* (lower name
46 #:key source inputs native-inputs outputs target
47 (cmake (default-cmake))
48 #:allow-other-keys
49 #:rest arguments)
50 "Return a bag for NAME."
51 (define private-keywords
52 '(#:source #:target #:cmake #:inputs #:native-inputs))
53
54 (and (not target) ;XXX: no cross-compilation
55 (bag
56 (name name)
57 (host-inputs `(,@(if source
58 `(("source" ,source))
59 '())
60 ,@inputs
61
62 ;; Keep the standard inputs of 'gnu-build-system'.
63 ,@(standard-packages)))
64 (build-inputs `(("cmake" ,cmake)
65 ,@native-inputs))
66 (outputs outputs)
67 (build cmake-build)
68 (arguments (strip-keyword-arguments private-keywords arguments)))))
69
70(define* (cmake-build store name inputs
71 #:key (guile #f)
72 (outputs '("out")) (configure-flags ''())
73 (search-paths '())
74 (make-flags ''())
75 (out-of-source? #t)
76 (build-type "RelWithDebInfo")
77 (tests? #t)
78 (test-target "test")
79 (parallel-build? #t) (parallel-tests? #f)
80 (patch-shebangs? #t)
81 (strip-binaries? #t)
82 (strip-flags ''("--strip-debug"))
83 (strip-directories ''("lib" "lib64" "libexec"
84 "bin" "sbin"))
85 (phases '(@ (guix build cmake-build-system)
86 %standard-phases))
87 (system (%current-system))
88 (imported-modules '((guix build cmake-build-system)
89 (guix build gnu-build-system)
90 (guix build utils)))
91 (modules '((guix build cmake-build-system)
92 (guix build utils))))
c6bded8a
CR
93 "Build SOURCE using CMAKE, and with INPUTS. This assumes that SOURCE
94provides a 'CMakeLists.txt' file as its build system."
95 (define builder
96 `(begin
97 (use-modules ,@modules)
0d5a559f
LC
98 (cmake-build #:source ,(match (assoc-ref inputs "source")
99 (((? derivation? source))
100 (derivation->output-path source))
101 ((source)
102 source)
103 (source
104 source))
c6bded8a
CR
105 #:system ,system
106 #:outputs %outputs
107 #:inputs %build-inputs
a18eda27 108 #:search-paths ',(map search-path-specification->sexp
0d5a559f 109 search-paths)
c6bded8a
CR
110 #:phases ,phases
111 #:configure-flags ,configure-flags
112 #:make-flags ,make-flags
113 #:out-of-source? ,out-of-source?
9849cfc1 114 #:build-type ,build-type
c6bded8a
CR
115 #:tests? ,tests?
116 #:test-target ,test-target
117 #:parallel-build? ,parallel-build?
118 #:parallel-tests? ,parallel-tests?
119 #:patch-shebangs? ,patch-shebangs?
120 #:strip-binaries? ,strip-binaries?
121 #:strip-flags ,strip-flags
122 #:strip-directories ,strip-directories)))
123
124 (define guile-for-build
125 (match guile
126 ((? package?)
127 (package-derivation store guile system))
c6bded8a 128 (#f ; the default
bdb36958 129 (let* ((distro (resolve-interface '(gnu packages commencement)))
c6bded8a
CR
130 (guile (module-ref distro 'guile-final)))
131 (package-derivation store guile system)))))
132
0d5a559f
LC
133 (build-expression->derivation store name builder
134 #:system system
135 #:inputs inputs
136 #:modules imported-modules
137 #:outputs outputs
138 #:guile-for-build guile-for-build))
c6bded8a
CR
139
140(define cmake-build-system
0d5a559f
LC
141 (build-system
142 (name 'cmake)
143 (description "The standard CMake build system")
144 (lower lower)))
c6bded8a
CR
145
146;;; cmake.scm ends here