Commit | Line | Data |
---|---|---|
c6bded8a | 1 | ;;; GNU Guix --- Functional package management for GNU |
189be331 | 2 | ;;; Copyright © 2013, 2014, 2015, 2018 Ludovic Courtès <ludo@gnu.org> |
c6bded8a | 3 | ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com> |
0d6f9360 | 4 | ;;; Copyright © 2014, 2015 Andreas Enge <andreas@enge.fr> |
5857a065 | 5 | ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il> |
c6bded8a CR |
6 | ;;; |
7 | ;;; This file is part of GNU Guix. | |
8 | ;;; | |
9 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
10 | ;;; under the terms of the GNU General Public License as published by | |
11 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
12 | ;;; your option) any later version. | |
13 | ;;; | |
14 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
15 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;;; GNU General Public License for more details. | |
18 | ;;; | |
19 | ;;; You should have received a copy of the GNU General Public License | |
20 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
21 | ||
22 | (define-module (guix build cmake-build-system) | |
b5b73a82 | 23 | #:use-module ((guix build gnu-build-system) #:prefix gnu:) |
c6bded8a CR |
24 | #:use-module (guix build utils) |
25 | #:use-module (ice-9 match) | |
26 | #:export (%standard-phases | |
27 | cmake-build)) | |
28 | ||
29 | ;; Commentary: | |
30 | ;; | |
31 | ;; Builder-side code of the standard cmake build procedure. | |
32 | ;; | |
33 | ;; Code: | |
34 | ||
977f03ff | 35 | (define* (configure #:key outputs (configure-flags '()) (out-of-source? #t) |
d2ac5e29 | 36 | build-type target |
c6bded8a CR |
37 | #:allow-other-keys) |
38 | "Configure the given package." | |
977f03ff LC |
39 | (let* ((out (assoc-ref outputs "out")) |
40 | (abs-srcdir (getcwd)) | |
41 | (srcdir (if out-of-source? | |
42 | (string-append "../" (basename abs-srcdir)) | |
43 | "."))) | |
44 | (format #t "source directory: ~s (relative from build: ~s)~%" | |
45 | abs-srcdir srcdir) | |
46 | (when out-of-source? | |
47 | (mkdir "../build") | |
48 | (chdir "../build")) | |
49 | (format #t "build directory: ~s~%" (getcwd)) | |
50 | ||
51 | (let ((args `(,srcdir | |
9849cfc1 LC |
52 | ,@(if build-type |
53 | (list (string-append "-DCMAKE_BUILD_TYPE=" | |
54 | build-type)) | |
55 | '()) | |
977f03ff | 56 | ,(string-append "-DCMAKE_INSTALL_PREFIX=" out) |
5857a065 EF |
57 | ;; ensure that the libraries are installed into /lib |
58 | "-DCMAKE_INSTALL_LIBDIR=lib" | |
06ed5982 AE |
59 | ;; add input libraries to rpath |
60 | "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE" | |
61 | ;; add (other) libraries of the project itself to rpath | |
62 | ,(string-append "-DCMAKE_INSTALL_RPATH=" out "/lib") | |
50915d2c SB |
63 | ;; enable verbose output from builds |
64 | "-DCMAKE_VERBOSE_MAKEFILE=ON" | |
d2ac5e29 RW |
65 | |
66 | ;; Cross-build | |
67 | ,@(if target | |
68 | (list (string-append "-DCMAKE_C_COMPILER=" | |
69 | target "-gcc") | |
38746d02 MB |
70 | (string-append "-DCMAKE_CXX_COMPILER=" |
71 | target "-g++") | |
d2ac5e29 RW |
72 | (if (string-contains target "mingw") |
73 | "-DCMAKE_SYSTEM_NAME=Windows" | |
74 | "-DCMAKE_SYSTEM_NAME=Linux")) | |
75 | '()) | |
977f03ff | 76 | ,@configure-flags))) |
977f03ff | 77 | (format #t "running 'cmake' with arguments ~s~%" args) |
0f308fe8 | 78 | (apply invoke "cmake" args)))) |
c6bded8a CR |
79 | |
80 | (define* (check #:key (tests? #t) (parallel-tests? #t) (test-target "test") | |
81 | #:allow-other-keys) | |
82 | (let ((gnu-check (assoc-ref gnu:%standard-phases 'check))) | |
caa9b834 | 83 | (setenv "CTEST_OUTPUT_ON_FAILURE" "1") |
c6bded8a CR |
84 | (gnu-check #:tests? tests? #:test-target test-target |
85 | #:parallel-tests? parallel-tests?))) | |
86 | ||
87 | (define %standard-phases | |
88 | ;; Everything is as with the GNU Build System except for the `configure' | |
89 | ;; and 'check' phases. | |
f84218ac | 90 | (modify-phases gnu:%standard-phases |
189be331 | 91 | (delete 'bootstrap) |
f8503e2b LC |
92 | (replace 'check check) |
93 | (replace 'configure configure))) | |
c6bded8a CR |
94 | |
95 | (define* (cmake-build #:key inputs (phases %standard-phases) | |
96 | #:allow-other-keys #:rest args) | |
97 | "Build the given package, applying all of PHASES in order." | |
98 | (apply gnu:gnu-build #:inputs inputs #:phases phases args)) | |
99 | ||
100 | ;;; cmake-build-system.scm ends here |