cmake.scm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com>
  3. ;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
  5. ;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
  6. ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
  7. ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
  8. ;;; Copyright © 2017, 2018, 2020, 2021 Marius Bakke <marius@gnu.org>
  9. ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
  10. ;;; Copyright © 2018, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
  11. ;;; Copyright © 2019, 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  12. ;;; Copyright © 2019 Pierre-Moana Levesque <pierre.moana.levesque@gmail.com>
  13. ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  14. ;;; Copyright © 2021 Ricardo Wurmus <rekado@elephly.net>
  15. ;;;
  16. ;;; This file is part of GNU Guix.
  17. ;;;
  18. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  19. ;;; under the terms of the GNU General Public License as published by
  20. ;;; the Free Software Foundation; either version 3 of the License, or (at
  21. ;;; your option) any later version.
  22. ;;;
  23. ;;; GNU Guix is distributed in the hope that it will be useful, but
  24. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  25. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. ;;; GNU General Public License for more details.
  27. ;;;
  28. ;;; You should have received a copy of the GNU General Public License
  29. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  30. (define-module (gnu packages cmake)
  31. #:use-module ((guix licenses) #:prefix license:)
  32. #:use-module (guix packages)
  33. #:use-module (guix download)
  34. #:use-module (guix git-download)
  35. #:use-module (guix utils)
  36. #:use-module (guix deprecation)
  37. #:use-module (guix build-system gnu)
  38. #:use-module (guix build-system cmake)
  39. #:use-module (guix build-system emacs)
  40. #:use-module (gnu packages)
  41. #:use-module (gnu packages backup)
  42. #:use-module (gnu packages compression)
  43. #:use-module (gnu packages crypto)
  44. #:use-module (gnu packages curl)
  45. #:use-module (gnu packages file)
  46. #:use-module (gnu packages hurd)
  47. #:use-module (gnu packages kde-frameworks)
  48. #:use-module (gnu packages libevent)
  49. #:use-module (gnu packages ncurses)
  50. #:use-module (gnu packages serialization)
  51. #:use-module (gnu packages sphinx)
  52. #:use-module (gnu packages texinfo)
  53. #:use-module (gnu packages xml)
  54. #:use-module (ice-9 match)
  55. #:use-module (srfi srfi-1))
  56. (define-public cmake-shared
  57. (let ((commit "8122f2b96c8da38ea41b653cf69958e75fe2129d")
  58. (revision "32"))
  59. (package
  60. (name "cmake-shared")
  61. (version
  62. (git-version "1.1.0" revision commit))
  63. (source
  64. (origin
  65. (method git-fetch)
  66. (uri
  67. (git-reference
  68. (url "https://github.com/lirios/cmake-shared.git")
  69. (commit commit)))
  70. (file-name
  71. (git-file-name name version))
  72. (sha256
  73. (base32 "05avwzqcnliwx9h7qi1kl0iz4smqmxc4vkavyjbmlc6h2b97i58g"))
  74. (modules '((guix build utils)
  75. (ice-9 ftw)
  76. (srfi srfi-1)))
  77. (snippet
  78. `(begin
  79. (delete-file-recursively "3rdparty")))))
  80. (build-system cmake-build-system)
  81. (arguments
  82. `(#:tests? #f)) ; No target
  83. (native-inputs
  84. `(("extra-cmake-modules" ,extra-cmake-modules)))
  85. (synopsis "Shared CMake functions and macros")
  86. (description "CMake-Shared are shared functions and macros for projects
  87. using the CMake build system.")
  88. (home-page "https://github.com/lirios/cmake-shared/")
  89. (license license:bsd-3))))
  90. ;;; Build phases shared between 'cmake-bootstrap' and the later variants
  91. ;;; that use cmake-build-system.
  92. (define (%common-build-phases)
  93. `((add-after 'unpack 'split-package
  94. ;; Remove files that have been packaged in other package recipes.
  95. (lambda _
  96. (delete-file "Auxiliary/cmake-mode.el")
  97. (substitute* "Auxiliary/CMakeLists.txt"
  98. ((".*cmake-mode.el.*") ""))
  99. #t))
  100. ,@(if (target-x86-32?)
  101. '((add-after 'unpack 'skip-cpack-txz-test
  102. (lambda _
  103. ;; In 'RunCMake.CPack_TXZ', the 'TXZ/THREADED_ALL' test
  104. ;; would occasionally fail on i686 with "Internal error
  105. ;; initializing compression library: Cannot allocate
  106. ;; memory": <https://issues.guix.gnu.org/50617>. Skip it.
  107. (substitute* "Tests/RunCMake/CPack/RunCMakeTest.cmake"
  108. (("THREADED_ALL \"TXZ;DEB\"")
  109. "THREADED_ALL \"DEB\"")))))
  110. '())
  111. (add-before 'configure 'patch-bin-sh
  112. (lambda _
  113. ;; Replace "/bin/sh" by the right path in... a lot of
  114. ;; files.
  115. (substitute*
  116. '("Modules/CompilerId/Xcode-3.pbxproj.in"
  117. "Modules/Internal/CPack/CPack.RuntimeScript.in"
  118. "Source/cmGlobalXCodeGenerator.cxx"
  119. "Source/cmLocalUnixMakefileGenerator3.cxx"
  120. "Source/cmExecProgramCommand.cxx"
  121. "Tests/CMakeLists.txt"
  122. "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
  123. (("/bin/sh") (which "sh")))
  124. #t))))
  125. (define %common-disabled-tests
  126. '(;; This test copies libgcc_s.so.1 from GCC and tries to modify its RPATH,
  127. ;; but does not cope with the file being read-only.
  128. "BundleUtilities"
  129. ;; This test requires network access.
  130. "CTestTestUpload"
  131. ;; This test requires 'ldconfig' which is not available in Guix.
  132. "RunCMake.install"
  133. ;; This test fails for unknown reason.
  134. "RunCMake.file-GET_RUNTIME_DEPENDENCIES"))
  135. (define %preserved-third-party-files
  136. '(;; 'Source/cm_getdate.c' includes archive_getdate.c wholesale, so it must
  137. ;; be available along with the required headers.
  138. "Utilities/cmlibarchive/libarchive/archive_getdate.c"
  139. "Utilities/cmlibarchive/libarchive/archive_getdate.h"
  140. ;; CMake header wrappers.
  141. "Utilities/cm3p"))
  142. ;;; The "bootstrap" CMake. It is used to build 'cmake-minimal' below, as well
  143. ;;; as any dependencies that need cmake-build-system.
  144. (define-public cmake-bootstrap
  145. (package
  146. (name "cmake-bootstrap")
  147. (version "3.20.2")
  148. (source (origin
  149. (method url-fetch)
  150. (uri (string-append "https://cmake.org/files/v"
  151. (version-major+minor version)
  152. "/cmake-" version ".tar.gz"))
  153. (sha256
  154. (base32
  155. "0kjlb7sxbwg8z4027c3jjcmyjh9d36p0r9d4nqxynyaijz5nxkxf"))
  156. (patches (search-patches "cmake-curl-certificates.patch"))))
  157. (build-system gnu-build-system)
  158. (arguments
  159. `(#:test-target "test"
  160. #:configure-flags
  161. (let ((out (assoc-ref %outputs "out"))
  162. (parallel-job-count (number->string (parallel-job-count))))
  163. (list "--verbose"
  164. (string-append "--parallel=" parallel-job-count)
  165. (string-append "--prefix=" out)
  166. "--system-libs"
  167. "--no-system-jsoncpp"
  168. ;; By default, the man pages and other docs land
  169. ;; in PREFIX/man and PREFIX/doc, but we want them
  170. ;; in share/{man,doc}. Note that unlike
  171. ;; autoconf-generated configure scripts, cmake's
  172. ;; configure prepends "PREFIX/" to what we pass
  173. ;; to --mandir and --docdir.
  174. "--mandir=share/man"
  175. ,(string-append "--docdir=share/doc/cmake-"
  176. (version-major+minor version))
  177. ;; By default CMake is built without any optimizations. Use
  178. ;; the recommended Release target for a ~2.5x speedup.
  179. "--" "-DCMAKE_BUILD_TYPE=Release"))
  180. #:make-flags
  181. (let ((skipped-tests
  182. (list ,@%common-disabled-tests
  183. "CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
  184. ;; This test fails when ARGS (below) is in use, see
  185. ;; <https://gitlab.kitware.com/cmake/cmake/issues/17165>.
  186. "CTestCoverageCollectGCOV")))
  187. (list
  188. (string-append
  189. ;; These arguments apply for the tests only.
  190. "ARGS=-j " (number->string (parallel-job-count))
  191. " --output-on-failure"
  192. " --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
  193. #:phases
  194. (modify-phases %standard-phases
  195. ,@(%common-build-phases)
  196. (add-before 'configure 'set-paths
  197. (lambda _
  198. ;; Help cmake's bootstrap process to find system libraries
  199. (begin
  200. (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
  201. (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
  202. (getenv "C_INCLUDE_PATH")))
  203. #t)))
  204. ;; CMake uses its own configure script.
  205. (replace 'configure
  206. (lambda* (#:key (configure-flags '()) #:allow-other-keys)
  207. (apply invoke "./configure" configure-flags))))))
  208. (inputs
  209. `(("bzip2" ,bzip2)
  210. ("curl" ,curl)
  211. ("expat" ,expat)
  212. ("file" ,file)
  213. ("libarchive" ,libarchive)
  214. ,@(if (hurd-target?)
  215. '()
  216. `(("libuv" ,libuv))) ;not supported on the Hurd
  217. ("rhash" ,rhash)
  218. ("zlib" ,zlib)))
  219. (native-search-paths
  220. (list (search-path-specification
  221. (variable "CMAKE_PREFIX_PATH")
  222. (files '("")))
  223. ;; "cmake-curl-certificates.patch" changes CMake to honor 'SSL_CERT_DIR'
  224. ;; and 'SSL_CERT_FILE', hence these search path entries.
  225. (search-path-specification
  226. (variable "SSL_CERT_DIR")
  227. (separator #f) ;single entry
  228. (files '("etc/ssl/certs")))
  229. (search-path-specification
  230. (variable "SSL_CERT_FILE")
  231. (file-type 'regular)
  232. (separator #f) ;single entry
  233. (files '("etc/ssl/certs/ca-certificates.crt")))))
  234. (home-page "https://cmake.org/")
  235. (synopsis "Cross-platform build system")
  236. (description
  237. "CMake is a family of tools designed to build, test and package software.
  238. CMake is used to control the software compilation process using simple platform
  239. and compiler independent configuration files. CMake generates native makefiles
  240. and workspaces that can be used in the compiler environment of your choice.")
  241. (properties '((hidden? . #t)))
  242. (license (list license:bsd-3 ; cmake
  243. license:expat ; cmjsoncpp is dual MIT/public domain
  244. license:public-domain)))) ; cmlibarchive/archive_getdate.c
  245. ;;; This minimal variant of CMake does not include the documentation. It is
  246. ;;; used by the cmake-build-system.
  247. (define-public cmake-minimal
  248. (package
  249. (inherit cmake-bootstrap)
  250. (name "cmake-minimal")
  251. (source (origin
  252. (inherit (package-source cmake-bootstrap))
  253. ;; Purge CMakes bundled dependencies as they are no longer needed.
  254. (modules '((ice-9 ftw)))
  255. (snippet
  256. `(begin
  257. (define preserved-files ',%preserved-third-party-files)
  258. (file-system-fold (lambda (dir stat result) ;enter?
  259. (or (string=? "Utilities" dir) ;init
  260. ;; The bundled dependencies are
  261. ;; distinguished by having a "cm"
  262. ;; prefix to their upstream names.
  263. (and (string-prefix? "Utilities/cm" dir)
  264. (not (member dir preserved-files)))))
  265. (lambda (file stat result) ;leaf
  266. (unless (or (member file preserved-files)
  267. ;; Preserve top-level files.
  268. (string=? "Utilities"
  269. (dirname file)))
  270. (delete-file file)))
  271. (const #t) ;down
  272. (lambda (dir stat result) ;up
  273. (when (equal? (scandir dir) '("." ".."))
  274. (rmdir dir)))
  275. (const #t) ;skip
  276. (lambda (file stat errno result)
  277. (format (current-error-port)
  278. "warning: failed to delete ~a: ~a~%"
  279. file (strerror errno)))
  280. #t
  281. "Utilities"
  282. lstat)
  283. #t))))
  284. (inputs
  285. `(("jsoncpp" ,jsoncpp)
  286. ,@(package-inputs cmake-bootstrap)))
  287. (build-system cmake-build-system)
  288. (arguments
  289. `(#:configure-flags
  290. (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
  291. (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
  292. ,(version-major+minor (package-version
  293. cmake-bootstrap))))
  294. ;; This is the CMake used in cmake-build-system. Ensure compiler
  295. ;; optimizations are enabled to save size and CPU cycles.
  296. #:build-type "Release"
  297. #:phases
  298. (modify-phases %standard-phases
  299. ,@(%common-build-phases)
  300. (add-after 'install 'delete-help-documentation
  301. (lambda* (#:key outputs #:allow-other-keys)
  302. (delete-file-recursively
  303. (string-append (assoc-ref outputs "out")
  304. "/share/cmake-"
  305. ,(version-major+minor
  306. (package-version cmake-bootstrap))
  307. "/Help"))
  308. #t))
  309. (replace 'check
  310. (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
  311. (let ((skipped-tests (list ,@%common-disabled-tests
  312. ;; This test requires the bundled libuv.
  313. "BootstrapTest")))
  314. (if tests?
  315. (begin
  316. (invoke "ctest" "-j" (if parallel-tests?
  317. (number->string (parallel-job-count))
  318. "1")
  319. "--exclude-regex"
  320. (string-append "^(" (string-join skipped-tests "|") ")$")))
  321. (format #t "test suite not run~%"))
  322. #t))))
  323. ,@(if (%current-target-system)
  324. '()
  325. `(#:cmake ,cmake-bootstrap))))))
  326. ;;; The "user-facing" CMake, now with manuals and HTML documentation.
  327. (define-public cmake
  328. (package
  329. (inherit cmake-minimal)
  330. (name "cmake")
  331. (version "3.21.1")
  332. (source (origin
  333. (inherit (package-source cmake-bootstrap))
  334. (uri (string-append "https://cmake.org/files/v"
  335. (version-major+minor version)
  336. "/cmake-" version ".tar.gz"))
  337. (sha256
  338. (base32
  339. "1m7y9j5lafkrfswsg2vkpx2fz6p6fqpp2pcp2dcz5pylf58r3hzs"))))
  340. (arguments
  341. (substitute-keyword-arguments (package-arguments cmake-minimal)
  342. ;; Use cmake-minimal this time.
  343. ((#:cmake _ #f)
  344. (if (%current-target-system)
  345. cmake-minimal-cross
  346. cmake-minimal))
  347. ;; Enable debugging information for convenience.
  348. ((#:build-type _ #f) "RelWithDebInfo")
  349. ((#:configure-flags flags ''())
  350. `(append (list "-DSPHINX_INFO=ON" "-DSPHINX_MAN=ON" "-DSPHINX_HTML=ON"
  351. (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
  352. ,(version-major+minor (package-version
  353. cmake-minimal)))
  354. "-DCMAKE_INFO_DIR=share/info"
  355. "-DCMAKE_MAN_DIR=share/man")
  356. ,flags))
  357. ((#:phases phases)
  358. `(modify-phases ,phases
  359. (delete 'delete-help-documentation)
  360. (add-after 'install 'move-html-doc
  361. (lambda* (#:key outputs #:allow-other-keys)
  362. (let ((out (assoc-ref outputs "out"))
  363. (doc (assoc-ref outputs "doc"))
  364. (html (string-append "/share/doc/cmake-"
  365. ,(version-major+minor
  366. (package-version cmake-minimal))
  367. "/html")))
  368. (copy-recursively (string-append out html)
  369. (string-append doc html))
  370. (delete-file-recursively (string-append out html))
  371. #t)))))))
  372. (inputs
  373. `(("ncurses" ,ncurses) ;required for ccmake
  374. ,@(package-inputs cmake-minimal)))
  375. ;; Extra inputs required to build the documentation.
  376. (native-inputs
  377. `(,@(package-native-inputs cmake-minimal)
  378. ("python-sphinx" ,python-sphinx)
  379. ("texinfo" ,texinfo)))
  380. (outputs '("out" "doc"))
  381. (properties (alist-delete 'hidden? (package-properties cmake-minimal)))))
  382. (define-public cmake-minimal-cross
  383. (package
  384. (inherit cmake-minimal)
  385. (name "cmake-minimal-cross")
  386. (native-search-paths '())
  387. (search-paths
  388. (package-native-search-paths cmake-minimal))))
  389. (define-public emacs-cmake-mode
  390. (package
  391. (inherit cmake)
  392. (name "emacs-cmake-mode")
  393. (native-inputs '())
  394. (inputs '())
  395. (outputs '("out"))
  396. (build-system emacs-build-system)
  397. (arguments
  398. `(#:phases
  399. (modify-phases %standard-phases
  400. (add-after 'unpack 'chdir-elisp
  401. ;; Elisp directory is not in root of the source.
  402. (lambda _
  403. (chdir "Auxiliary")
  404. #t)))))
  405. (synopsis "Emacs major mode for editing Cmake expressions")
  406. (description "@code{cmakeos-mode} provides an Emacs major mode for editing
  407. Cmake files. It supports syntax highlighting, indenting and refilling of
  408. comments.")))