qt.scm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
  4. ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
  5. ;;; Copyright © 2019 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-system qt)
  22. #:use-module (guix store)
  23. #:use-module (guix utils)
  24. #:use-module (guix gexp)
  25. #:use-module (guix monads)
  26. #:use-module (guix search-paths)
  27. #:use-module (guix build-system)
  28. #:use-module (guix build-system cmake)
  29. #:use-module (guix build-system gnu)
  30. #:use-module (guix packages)
  31. #:use-module (ice-9 match)
  32. #:export (%qt-build-system-modules
  33. qt-build
  34. qt-build-system))
  35. ;; Commentary:
  36. ;;
  37. ;; This build system is an extension of the 'cmake-build-system'. It
  38. ;; accommodates the needs of Qt and KDE applications by adding a phase run
  39. ;; after the 'install' phase:
  40. ;;
  41. ;; 'qt-wrap' phase:
  42. ;;
  43. ;; This phase looks for Qt5 plugin paths, QML paths and some XDG paths as well
  44. ;; as the corresponding environment variables. If any of these is found in
  45. ;; the output or if respective environment variables are set, then all
  46. ;; programs in the output's "bin", "sbin", "libexec and "lib/libexec"
  47. ;; directories are wrapped in scripts defining the necessary environment
  48. ;; variables.
  49. ;;
  50. ;; Code:
  51. (define %qt-build-system-modules
  52. ;; Build-side modules imported and used by default.
  53. `((guix build qt-build-system)
  54. ,@%cmake-build-system-modules))
  55. (define (default-cmake)
  56. "Return the default CMake package."
  57. ;; Do not use `@' to avoid introducing circular dependencies.
  58. (let ((module (resolve-interface '(gnu packages cmake))))
  59. (module-ref module 'cmake-minimal)))
  60. ;; This barely is a copy from (guix build-system cmake), only adjusted to use
  61. ;; the variables defined here.
  62. (define* (lower name
  63. #:key source inputs native-inputs outputs system target
  64. (cmake (default-cmake))
  65. #:allow-other-keys
  66. #:rest arguments)
  67. "Return a bag for NAME."
  68. (define private-keywords
  69. `(#:cmake #:inputs #:native-inputs #:outputs
  70. ,@(if target '() '(#:target))))
  71. (bag
  72. (name name)
  73. (system system)
  74. (target target)
  75. (build-inputs `(,@(if source
  76. `(("source" ,source))
  77. '())
  78. ,@`(("cmake" ,cmake))
  79. ,@native-inputs
  80. ,@(if target
  81. ;; Use the standard cross inputs of
  82. ;; 'gnu-build-system'.
  83. (standard-cross-packages target 'host)
  84. '())
  85. ;; Keep the standard inputs of 'gnu-build-system'.
  86. ,@(standard-packages)))
  87. (host-inputs inputs)
  88. ;; The cross-libc is really a target package, but for bootstrapping
  89. ;; reasons, we can't put it in 'host-inputs'. Namely, 'cross-gcc' is a
  90. ;; native package, so it would end up using a "native" variant of
  91. ;; 'cross-libc' (built with 'gnu-build'), whereas all the other packages
  92. ;; would use a target variant (built with 'gnu-cross-build'.)
  93. (target-inputs (if target
  94. (standard-cross-packages target 'target)
  95. '()))
  96. (outputs outputs)
  97. (build (if target qt-cross-build qt-build))
  98. (arguments (strip-keyword-arguments private-keywords arguments))))
  99. (define* (qt-build name inputs
  100. #:key
  101. source (guile #f)
  102. (outputs '("out")) (configure-flags ''())
  103. (search-paths '())
  104. (make-flags ''())
  105. (out-of-source? #t)
  106. (build-type "RelWithDebInfo")
  107. (tests? #t)
  108. (test-target "test")
  109. (parallel-build? #t) (parallel-tests? #f)
  110. (validate-runpath? #t)
  111. (patch-shebangs? #t)
  112. (strip-binaries? #t)
  113. (strip-flags ''("--strip-debug"))
  114. (strip-directories ''("lib" "lib64" "libexec"
  115. "bin" "sbin"))
  116. (phases '%standard-phases)
  117. (qt-wrap-excluded-outputs ''())
  118. (system (%current-system))
  119. (imported-modules %qt-build-system-modules)
  120. (modules '((guix build qt-build-system)
  121. (guix build utils))))
  122. "Build SOURCE using CMAKE, and with INPUTS. This assumes that SOURCE
  123. provides a 'CMakeLists.txt' file as its build system."
  124. (define builder
  125. (with-imported-modules imported-modules
  126. #~(begin
  127. (use-modules #$@(sexp->gexp modules))
  128. (qt-build #:source #+source
  129. #:system #$system
  130. #:outputs #$(outputs->gexp outputs)
  131. #:inputs #$(input-tuples->gexp inputs)
  132. #:search-paths '#$(sexp->gexp
  133. (map search-path-specification->sexp
  134. search-paths))
  135. #:phases #$(if (pair? phases)
  136. (sexp->gexp phases)
  137. phases)
  138. #:qt-wrap-excluded-outputs #$qt-wrap-excluded-outputs
  139. #:configure-flags #$configure-flags
  140. #:make-flags #$make-flags
  141. #:out-of-source? #$out-of-source?
  142. #:build-type #$build-type
  143. #:tests? #$tests?
  144. #:test-target #$test-target
  145. #:parallel-build? #$parallel-build?
  146. #:parallel-tests? #$parallel-tests?
  147. #:validate-runpath? #$validate-runpath?
  148. #:patch-shebangs? #$patch-shebangs?
  149. #:strip-binaries? #$strip-binaries?
  150. #:strip-flags #$strip-flags
  151. #:strip-directories #$strip-directories))))
  152. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  153. system #:graft? #f)))
  154. (gexp->derivation name builder
  155. #:system system
  156. #:guile-for-build guile)))
  157. ;;;
  158. ;;; Cross-compilation.
  159. ;;;
  160. (define* (qt-cross-build name
  161. #:key
  162. source target
  163. build-inputs target-inputs host-inputs
  164. (guile #f)
  165. (outputs '("out"))
  166. (configure-flags ''())
  167. (search-paths '())
  168. (native-search-paths '())
  169. (make-flags ''())
  170. (out-of-source? #t)
  171. (build-type "RelWithDebInfo")
  172. (tests? #f) ; nothing can be done
  173. (test-target "test")
  174. (parallel-build? #t) (parallel-tests? #f)
  175. (validate-runpath? #t)
  176. (patch-shebangs? #t)
  177. (strip-binaries? #t)
  178. (strip-flags ''("--strip-debug"
  179. "--enable-deterministic-archives"))
  180. (strip-directories ''("lib" "lib64" "libexec"
  181. "bin" "sbin"))
  182. (phases '%standard-phases)
  183. (system (%current-system))
  184. (build (nix-system->gnu-triplet system))
  185. (imported-modules %qt-build-system-modules)
  186. (modules '((guix build qt-build-system)
  187. (guix build utils))))
  188. "Cross-build NAME using CMAKE for TARGET, where TARGET is a GNU triplet and
  189. with INPUTS. This assumes that SOURCE provides a 'CMakeLists.txt' file as its
  190. build system."
  191. (define builder
  192. (with-imported-modules imported-modules
  193. #~(begin
  194. (use-modules #$@(sexp->gexp modules))
  195. (define %build-host-inputs
  196. #+(input-tuples->gexp build-inputs))
  197. (define %build-target-inputs
  198. (append #$(input-tuples->gexp host-inputs)
  199. #+(input-tuples->gexp target-inputs)))
  200. (define %outputs
  201. #$(outputs->gexp outputs))
  202. (qt-build #:source #+source
  203. #:system #$system
  204. #:build #$build
  205. #:target #$target
  206. #:outputs %outputs
  207. #:inputs %build-target-inputs
  208. #:native-inputs %build-host-inputs
  209. #:search-paths '#$(sexp->gexp
  210. (map search-path-specification->sexp
  211. search-paths))
  212. #:native-search-paths '#$(map
  213. search-path-specification->sexp
  214. native-search-paths)
  215. #:phases #$phases
  216. #:configure-flags #$configure-flags
  217. #:make-flags #$make-flags
  218. #:out-of-source? #$out-of-source?
  219. #:build-type #$build-type
  220. #:tests? #$tests?
  221. #:test-target #$test-target
  222. #:parallel-build? #$parallel-build?
  223. #:parallel-tests? #$parallel-tests?
  224. #:validate-runpath? #$validate-runpath?
  225. #:patch-shebangs? #$patch-shebangs?
  226. #:strip-binaries? #$strip-binaries?
  227. #:strip-flags #$strip-flags
  228. #:strip-directories #$strip-directories))))
  229. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  230. system #:graft? #f)))
  231. (gexp->derivation name builder
  232. #:system system
  233. #:guile-for-build guile)))
  234. (define qt-build-system
  235. (build-system
  236. (name 'qt)
  237. (description
  238. "The CMake build system augmented with definition of suitable environment
  239. variables for Qt and KDE in program wrappers.")
  240. (lower lower)))