qt-build-system.scm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 Federico Beffa <beffa@fbengineering.ch>
  3. ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
  5. ;;; Copyright © 2019, 2020 Hartmut Goebel <h.goebel@crazy-compilers.com>
  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 qt-build-system)
  22. #:use-module ((guix build cmake-build-system) #:prefix cmake:)
  23. #:use-module (guix build utils)
  24. #:use-module (ice-9 match)
  25. #:use-module (ice-9 regex)
  26. #:use-module (ice-9 ftw)
  27. #:use-module (srfi srfi-1)
  28. #:use-module (srfi srfi-26)
  29. #:export (%standard-phases
  30. qt-build))
  31. ;; Commentary:
  32. ;;
  33. ;; Builder-side code of the standard Qt build procedure.
  34. ;;
  35. ;; Code:
  36. (define* (check-setup #:rest args)
  37. ;; Make Qt render "offscreen". In many cases this allows to run tests
  38. ;; without starting a X11 server.
  39. (setenv "QT_QPA_PLATFORM" "offscreen")
  40. ;; Qt/KDE tests often need dbus (`dbus-launch …`) which is not fully
  41. ;; set-up the the build container.
  42. (setenv "DBUS_FATAL_WARNINGS" "0")
  43. ;; Set here to ease overwriting 'check (even if set there, too)
  44. (setenv "CTEST_OUTPUT_ON_FAILURE" "1")
  45. #t)
  46. (define (variables-for-wrapping base-directories)
  47. (define (collect-sub-dirs base-directories subdirectory)
  48. (filter-map
  49. (lambda (dir)
  50. (let ((directory (string-append dir subdirectory)))
  51. (if (directory-exists? directory) directory #f)))
  52. base-directories))
  53. (filter
  54. (lambda (var-to-wrap) (not (null? (last var-to-wrap))))
  55. (map
  56. (lambda (var-spec)
  57. `(,(first var-spec) = ,(collect-sub-dirs base-directories (last var-spec))))
  58. (list
  59. ;; these shall match the search-path-specification for Qt and KDE
  60. ;; libraries
  61. '("XDG_DATA_DIRS" "/share")
  62. '("XDG_CONFIG_DIRS" "/etc/xdg")
  63. '("QT_PLUGIN_PATH" "/lib/qt5/plugins")
  64. '("QML2_IMPORT_PATH" "/lib/qt5/qml")))))
  65. (define* (wrap-all-programs #:key inputs outputs
  66. (qt-wrap-excluded-outputs '())
  67. #:allow-other-keys)
  68. "Implement phase \"qt-wrap\": look for GSettings schemas and
  69. gtk+-v.0 libraries and create wrappers with suitably set environment variables
  70. if found.
  71. Wrapping is not applied to outputs whose name is listed in
  72. QT-WRAP-EXCLUDED-OUTPUTS. This is useful when an output is known not
  73. to contain any Qt binaries, and where wrapping would gratuitously
  74. add a dependency of that output on Qt."
  75. (define (find-files-to-wrap directory)
  76. (append-map
  77. (lambda (dir)
  78. (if (directory-exists? dir) (find-files dir ".*") (list)))
  79. (list (string-append directory "/bin")
  80. (string-append directory "/sbin")
  81. (string-append directory "/libexec")
  82. (string-append directory "/lib/libexec"))))
  83. (define input-directories
  84. ;; FIXME: Filter out unwanted inputs, e.g. cmake
  85. (match inputs
  86. (((_ . dir) ...)
  87. dir)))
  88. (define handle-output
  89. (match-lambda
  90. ((output . directory)
  91. (unless (member output qt-wrap-excluded-outputs)
  92. (let ((bin-list (find-files-to-wrap directory))
  93. (vars-to-wrap (variables-for-wrapping
  94. (append (list directory)
  95. input-directories))))
  96. (when (not (null? vars-to-wrap))
  97. (for-each (cut apply wrap-program <> vars-to-wrap)
  98. bin-list)))))))
  99. (for-each handle-output outputs)
  100. #t)
  101. (define %standard-phases
  102. (modify-phases cmake:%standard-phases
  103. (add-before 'check 'check-setup check-setup)
  104. (add-after 'install 'qt-wrap wrap-all-programs)))
  105. (define* (qt-build #:key inputs (phases %standard-phases)
  106. #:allow-other-keys #:rest args)
  107. "Build the given package, applying all of PHASES in order."
  108. (apply cmake:cmake-build #:inputs inputs #:phases phases args))