cmake-build-system.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. (string-append "-DCMAKE_CXX_COMPILER="
  66. target "-g++")
  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. (apply invoke "cmake" args))))
  74. (define* (check #:key (tests? #t) (parallel-tests? #t) (test-target "test")
  75. #:allow-other-keys)
  76. (let ((gnu-check (assoc-ref gnu:%standard-phases 'check)))
  77. (setenv "CTEST_OUTPUT_ON_FAILURE" "1")
  78. (gnu-check #:tests? tests? #:test-target test-target
  79. #:parallel-tests? parallel-tests?)))
  80. (define %standard-phases
  81. ;; Everything is as with the GNU Build System except for the `configure'
  82. ;; and 'check' phases.
  83. (modify-phases gnu:%standard-phases
  84. (delete 'bootstrap)
  85. (replace 'check check)
  86. (replace 'configure configure)))
  87. (define* (cmake-build #:key inputs (phases %standard-phases)
  88. #:allow-other-keys #:rest args)
  89. "Build the given package, applying all of PHASES in order."
  90. (apply gnu:gnu-build #:inputs inputs #:phases phases args))
  91. ;;; cmake-build-system.scm ends here