cmake.scm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. (add-before 'configure 'patch-bin-sh
  101. (lambda _
  102. ;; Replace "/bin/sh" by the right path in... a lot of
  103. ;; files.
  104. (substitute*
  105. '("Modules/CompilerId/Xcode-3.pbxproj.in"
  106. "Modules/Internal/CPack/CPack.RuntimeScript.in"
  107. "Source/cmGlobalXCodeGenerator.cxx"
  108. "Source/cmLocalUnixMakefileGenerator3.cxx"
  109. "Source/cmExecProgramCommand.cxx"
  110. "Tests/CMakeLists.txt"
  111. "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
  112. (("/bin/sh") (which "sh")))
  113. #t))))
  114. (define %common-disabled-tests
  115. '(;; This test copies libgcc_s.so.1 from GCC and tries to modify its RPATH,
  116. ;; but does not cope with the file being read-only.
  117. "BundleUtilities"
  118. ;; This test requires network access.
  119. "CTestTestUpload"
  120. ;; This test requires 'ldconfig' which is not available in Guix.
  121. "RunCMake.install"
  122. ;; This test fails for unknown reason.
  123. "RunCMake.file-GET_RUNTIME_DEPENDENCIES"))
  124. (define %preserved-third-party-files
  125. '(;; 'Source/cm_getdate.c' includes archive_getdate.c wholesale, so it must
  126. ;; be available along with the required headers.
  127. "Utilities/cmlibarchive/libarchive/archive_getdate.c"
  128. "Utilities/cmlibarchive/libarchive/archive_getdate.h"
  129. ;; CMake header wrappers.
  130. "Utilities/cm3p"))
  131. ;;; The "bootstrap" CMake. It is used to build 'cmake-minimal' below, as well
  132. ;;; as any dependencies that need cmake-build-system.
  133. (define-public cmake-bootstrap
  134. (package
  135. (name "cmake-bootstrap")
  136. (version "3.20.2")
  137. (source (origin
  138. (method url-fetch)
  139. (uri (string-append "https://cmake.org/files/v"
  140. (version-major+minor version)
  141. "/cmake-" version ".tar.gz"))
  142. (sha256
  143. (base32
  144. "0kjlb7sxbwg8z4027c3jjcmyjh9d36p0r9d4nqxynyaijz5nxkxf"))
  145. (patches (search-patches "cmake-curl-certificates.patch"))))
  146. (build-system gnu-build-system)
  147. (arguments
  148. `(#:test-target "test"
  149. #:configure-flags
  150. (let ((out (assoc-ref %outputs "out"))
  151. (parallel-job-count (number->string (parallel-job-count))))
  152. (list "--verbose"
  153. (string-append "--parallel=" parallel-job-count)
  154. (string-append "--prefix=" out)
  155. "--system-libs"
  156. "--no-system-jsoncpp"
  157. ;; By default, the man pages and other docs land
  158. ;; in PREFIX/man and PREFIX/doc, but we want them
  159. ;; in share/{man,doc}. Note that unlike
  160. ;; autoconf-generated configure scripts, cmake's
  161. ;; configure prepends "PREFIX/" to what we pass
  162. ;; to --mandir and --docdir.
  163. "--mandir=share/man"
  164. ,(string-append "--docdir=share/doc/cmake-"
  165. (version-major+minor version))
  166. ;; By default CMake is built without any optimizations. Use
  167. ;; the recommended Release target for a ~2.5x speedup.
  168. "--" "-DCMAKE_BUILD_TYPE=Release"))
  169. #:make-flags
  170. (let ((skipped-tests
  171. (list ,@%common-disabled-tests
  172. "CTestTestSubdir" ; This test fails to build 2 of the 3 tests.
  173. ;; This test fails when ARGS (below) is in use, see
  174. ;; <https://gitlab.kitware.com/cmake/cmake/issues/17165>.
  175. "CTestCoverageCollectGCOV")))
  176. (list
  177. (string-append
  178. ;; These arguments apply for the tests only.
  179. "ARGS=-j " (number->string (parallel-job-count))
  180. " --output-on-failure"
  181. " --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
  182. #:phases
  183. (modify-phases %standard-phases
  184. ,@%common-build-phases
  185. (add-before 'configure 'set-paths
  186. (lambda _
  187. ;; Help cmake's bootstrap process to find system libraries
  188. (begin
  189. (setenv "CMAKE_LIBRARY_PATH" (getenv "LIBRARY_PATH"))
  190. (setenv "CMAKE_INCLUDE_PATH" (or (getenv "CPATH")
  191. (getenv "C_INCLUDE_PATH")))
  192. #t)))
  193. ;; CMake uses its own configure script.
  194. (replace 'configure
  195. (lambda* (#:key (configure-flags '()) #:allow-other-keys)
  196. (apply invoke "./configure" configure-flags))))))
  197. (inputs
  198. `(("bzip2" ,bzip2)
  199. ("curl" ,curl)
  200. ("expat" ,expat)
  201. ("file" ,file)
  202. ("libarchive" ,libarchive)
  203. ,@(if (hurd-target?)
  204. '()
  205. `(("libuv" ,libuv))) ;not supported on the Hurd
  206. ("rhash" ,rhash)
  207. ("zlib" ,zlib)))
  208. (native-search-paths
  209. (list (search-path-specification
  210. (variable "CMAKE_PREFIX_PATH")
  211. (files '("")))
  212. ;; "cmake-curl-certificates.patch" changes CMake to honor 'SSL_CERT_DIR'
  213. ;; and 'SSL_CERT_FILE', hence these search path entries.
  214. (search-path-specification
  215. (variable "SSL_CERT_DIR")
  216. (separator #f) ;single entry
  217. (files '("etc/ssl/certs")))
  218. (search-path-specification
  219. (variable "SSL_CERT_FILE")
  220. (file-type 'regular)
  221. (separator #f) ;single entry
  222. (files '("etc/ssl/certs/ca-certificates.crt")))))
  223. (home-page "https://cmake.org/")
  224. (synopsis "Cross-platform build system")
  225. (description
  226. "CMake is a family of tools designed to build, test and package software.
  227. CMake is used to control the software compilation process using simple platform
  228. and compiler independent configuration files. CMake generates native makefiles
  229. and workspaces that can be used in the compiler environment of your choice.")
  230. (properties '((hidden? . #t)))
  231. (license (list license:bsd-3 ; cmake
  232. license:expat ; cmjsoncpp is dual MIT/public domain
  233. license:public-domain)))) ; cmlibarchive/archive_getdate.c
  234. ;;; This minimal variant of CMake does not include the documentation. It is
  235. ;;; used by the cmake-build-system.
  236. (define-public cmake-minimal
  237. (package
  238. (inherit cmake-bootstrap)
  239. (name "cmake-minimal")
  240. (source (origin
  241. (inherit (package-source cmake-bootstrap))
  242. ;; Purge CMakes bundled dependencies as they are no longer needed.
  243. (modules '((ice-9 ftw)))
  244. (snippet
  245. `(begin
  246. (define preserved-files ',%preserved-third-party-files)
  247. (file-system-fold (lambda (dir stat result) ;enter?
  248. (or (string=? "Utilities" dir) ;init
  249. ;; The bundled dependencies are
  250. ;; distinguished by having a "cm"
  251. ;; prefix to their upstream names.
  252. (and (string-prefix? "Utilities/cm" dir)
  253. (not (member dir preserved-files)))))
  254. (lambda (file stat result) ;leaf
  255. (unless (or (member file preserved-files)
  256. ;; Preserve top-level files.
  257. (string=? "Utilities"
  258. (dirname file)))
  259. (delete-file file)))
  260. (const #t) ;down
  261. (lambda (dir stat result) ;up
  262. (when (equal? (scandir dir) '("." ".."))
  263. (rmdir dir)))
  264. (const #t) ;skip
  265. (lambda (file stat errno result)
  266. (format (current-error-port)
  267. "warning: failed to delete ~a: ~a~%"
  268. file (strerror errno)))
  269. #t
  270. "Utilities"
  271. lstat)
  272. #t))))
  273. (inputs
  274. `(("jsoncpp" ,jsoncpp)
  275. ,@(package-inputs cmake-bootstrap)))
  276. (build-system cmake-build-system)
  277. (arguments
  278. `(#:configure-flags
  279. (list "-DCMAKE_USE_SYSTEM_LIBRARIES=ON"
  280. (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
  281. ,(version-major+minor (package-version
  282. cmake-bootstrap))))
  283. ;; This is the CMake used in cmake-build-system. Ensure compiler
  284. ;; optimizations are enabled to save size and CPU cycles.
  285. #:build-type "Release"
  286. #:phases
  287. (modify-phases %standard-phases
  288. ,@%common-build-phases
  289. (add-after 'install 'delete-help-documentation
  290. (lambda* (#:key outputs #:allow-other-keys)
  291. (delete-file-recursively
  292. (string-append (assoc-ref outputs "out")
  293. "/share/cmake-"
  294. ,(version-major+minor
  295. (package-version cmake-bootstrap))
  296. "/Help"))
  297. #t))
  298. (replace 'check
  299. (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
  300. (let ((skipped-tests (list ,@%common-disabled-tests
  301. ;; This test requires the bundled libuv.
  302. "BootstrapTest")))
  303. (if tests?
  304. (begin
  305. (invoke "ctest" "-j" (if parallel-tests?
  306. (number->string (parallel-job-count))
  307. "1")
  308. "--exclude-regex"
  309. (string-append "^(" (string-join skipped-tests "|") ")$")))
  310. (format #t "test suite not run~%"))
  311. #t))))
  312. ,@(if (%current-target-system)
  313. '()
  314. `(#:cmake ,cmake-bootstrap))))))
  315. ;;; The "user-facing" CMake, now with manuals and HTML documentation.
  316. (define-public cmake
  317. (package
  318. (inherit cmake-minimal)
  319. (name "cmake")
  320. (version "3.21.1")
  321. (source (origin
  322. (inherit (package-source cmake-bootstrap))
  323. (uri (string-append "https://cmake.org/files/v"
  324. (version-major+minor version)
  325. "/cmake-" version ".tar.gz"))
  326. (sha256
  327. (base32
  328. "1m7y9j5lafkrfswsg2vkpx2fz6p6fqpp2pcp2dcz5pylf58r3hzs"))))
  329. (arguments
  330. (substitute-keyword-arguments (package-arguments cmake-minimal)
  331. ;; Use cmake-minimal this time.
  332. ((#:cmake _ #f)
  333. (if (%current-target-system)
  334. cmake-minimal-cross
  335. cmake-minimal))
  336. ;; Enable debugging information for convenience.
  337. ((#:build-type _ #f) "RelWithDebInfo")
  338. ((#:configure-flags flags ''())
  339. `(append (list "-DSPHINX_INFO=ON" "-DSPHINX_MAN=ON" "-DSPHINX_HTML=ON"
  340. (string-append "-DCMAKE_DOC_DIR=share/doc/cmake-"
  341. ,(version-major+minor (package-version
  342. cmake-minimal)))
  343. "-DCMAKE_INFO_DIR=share/info"
  344. "-DCMAKE_MAN_DIR=share/man")
  345. ,flags))
  346. ((#:phases phases)
  347. `(modify-phases ,phases
  348. (delete 'delete-help-documentation)
  349. (add-after 'install 'move-html-doc
  350. (lambda* (#:key outputs #:allow-other-keys)
  351. (let ((out (assoc-ref outputs "out"))
  352. (doc (assoc-ref outputs "doc"))
  353. (html (string-append "/share/doc/cmake-"
  354. ,(version-major+minor
  355. (package-version cmake-minimal))
  356. "/html")))
  357. (copy-recursively (string-append out html)
  358. (string-append doc html))
  359. (delete-file-recursively (string-append out html))
  360. #t)))))))
  361. (inputs
  362. `(("ncurses" ,ncurses) ;required for ccmake
  363. ,@(package-inputs cmake-minimal)))
  364. ;; Extra inputs required to build the documentation.
  365. (native-inputs
  366. `(,@(package-native-inputs cmake-minimal)
  367. ("python-sphinx" ,python-sphinx)
  368. ("texinfo" ,texinfo)))
  369. (outputs '("out" "doc"))
  370. (properties (alist-delete 'hidden? (package-properties cmake-minimal)))))
  371. (define-public cmake-minimal-cross
  372. (package
  373. (inherit cmake-minimal)
  374. (name "cmake-minimal-cross")
  375. (native-search-paths '())
  376. (search-paths
  377. (package-native-search-paths cmake-minimal))))
  378. (define-public emacs-cmake-mode
  379. (package
  380. (inherit cmake)
  381. (name "emacs-cmake-mode")
  382. (native-inputs '())
  383. (inputs '())
  384. (outputs '("out"))
  385. (build-system emacs-build-system)
  386. (arguments
  387. `(#:phases
  388. (modify-phases %standard-phases
  389. (add-after 'unpack 'chdir-elisp
  390. ;; Elisp directory is not in root of the source.
  391. (lambda _
  392. (chdir "Auxiliary")
  393. #t)))))
  394. (synopsis "Emacs major mode for editing Cmake expressions")
  395. (description "@code{cmakeos-mode} provides an Emacs major mode for editing
  396. Cmake files. It supports syntax highlighting, indenting and refilling of
  397. comments.")))