qt.scm 11 KB

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