cmake-build-system.scm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2018 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
  4. ;;; Copyright © 2014, 2015 Andreas Enge <andreas@enge.fr>
  5. ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
  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. (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))
  27. ;; Commentary:
  28. ;;
  29. ;; Builder-side code of the standard cmake build procedure.
  30. ;;
  31. ;; Code:
  32. (define* (configure #:key outputs (configure-flags '()) (out-of-source? #t)
  33. build-type target
  34. #:allow-other-keys)
  35. "Configure the given package."
  36. (let* ((out (assoc-ref outputs "out"))
  37. (abs-srcdir (getcwd))
  38. (srcdir (if out-of-source?
  39. (string-append "../" (basename abs-srcdir))
  40. ".")))
  41. (format #t "source directory: ~s (relative from build: ~s)~%"
  42. abs-srcdir srcdir)
  43. (when out-of-source?
  44. (mkdir "../build")
  45. (chdir "../build"))
  46. (format #t "build directory: ~s~%" (getcwd))
  47. (let ((args `(,srcdir
  48. ,@(if build-type
  49. (list (string-append "-DCMAKE_BUILD_TYPE="
  50. build-type))
  51. '())
  52. ,(string-append "-DCMAKE_INSTALL_PREFIX=" out)
  53. ;; ensure that the libraries are installed into /lib
  54. "-DCMAKE_INSTALL_LIBDIR=lib"
  55. ;; add input libraries to rpath
  56. "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE"
  57. ;; add (other) libraries of the project itself to rpath
  58. ,(string-append "-DCMAKE_INSTALL_RPATH=" out "/lib")
  59. ;; enable verbose output from builds
  60. "-DCMAKE_VERBOSE_MAKEFILE=ON"
  61. ;; Cross-build
  62. ,@(if target
  63. (list (string-append "-DCMAKE_C_COMPILER="
  64. target "-gcc")
  65. (if (string-contains target "mingw")
  66. "-DCMAKE_SYSTEM_NAME=Windows"
  67. "-DCMAKE_SYSTEM_NAME=Linux"))
  68. '())
  69. ,@configure-flags)))
  70. (format #t "running 'cmake' with arguments ~s~%" args)
  71. (apply invoke "cmake" args))))
  72. (define* (check #:key (tests? #t) (parallel-tests? #t) (test-target "test")
  73. #:allow-other-keys)
  74. (let ((gnu-check (assoc-ref gnu:%standard-phases 'check)))
  75. (setenv "CTEST_OUTPUT_ON_FAILURE" "1")
  76. (gnu-check #:tests? tests? #:test-target test-target
  77. #:parallel-tests? parallel-tests?)))
  78. (define %standard-phases
  79. ;; Everything is as with the GNU Build System except for the `configure'
  80. ;; and 'check' phases.
  81. (modify-phases gnu:%standard-phases
  82. (delete 'bootstrap)
  83. (replace 'check check)
  84. (replace 'configure configure)))
  85. (define* (cmake-build #:key inputs (phases %standard-phases)
  86. #:allow-other-keys #:rest args)
  87. "Build the given package, applying all of PHASES in order."
  88. (apply gnu:gnu-build #:inputs inputs #:phases phases args))
  89. ;;; cmake-build-system.scm ends here