Subject: [bug#30596] [PATCH 5/6] gnu: Add [email-masked].

From: Marius Bakke <[email-masked]>
Date: Sat, 24 Feb 2018 20:03:48 +0100

* gnu/packages/patches/cmake-3.11-pthread-fix.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/cmake.scm (cmake-3.11): New public variable.
---
 gnu/local.mk                                      |  1 +
 gnu/packages/cmake.scm                            | 63 +++++++++++++++++++++++
 gnu/packages/patches/cmake-3.11-pthread-fix.patch | 30 +++++++++++
 3 files changed, 94 insertions(+)
 create mode 100644 gnu/packages/patches/cmake-3.11-pthread-fix.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index a10f3150e..75f275928 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -591,6 +591,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/clucene-pkgconfig.patch			\
   %D%/packages/patches/clx-remove-demo.patch			\
   %D%/packages/patches/cmake-fix-tests.patch			\
+  %D%/packages/patches/cmake-3.11-pthread-fix.patch		\
   %D%/packages/patches/coda-use-system-libs.patch		\
   %D%/packages/patches/cool-retro-term-dont-check-uninit-member.patch	\
   %D%/packages/patches/cool-retro-term-fix-array-size.patch	\
diff --git a/gnu/packages/cmake.scm b/gnu/packages/cmake.scm
index a4e2d38e3..801323c72 100644
--- a/gnu/packages/cmake.scm
+++ b/gnu/packages/cmake.scm
@@ -31,6 +31,7 @@
   #:use-module (gnu packages)
   #:use-module (gnu packages backup)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages crypto)
   #:use-module (gnu packages curl)
   #:use-module (gnu packages file)
   #:use-module (gnu packages libevent)
@@ -149,3 +150,65 @@ and workspaces that can be used in the compiler environment of your choice.")
                    license:bsd-2             ; cmlibarchive
                    license:expat             ; cmjsoncpp is dual MIT/public domain
                    license:public-domain)))) ; cmlibarchive/archive_getdate.c
+
+;; Recent Ceph requires Boost 1.66, which in turn requires CMake 3.11 for
+;; its updated "FindBoost.cmake" facility.
+(define-public cmake-3.11
+  (package
+    (inherit cmake)
+    (version "3.11.0-rc1")
+    (source (origin
+              (inherit (package-source cmake))
+              (uri (string-append "https://www.cmake.org/files/v"
+                                  (version-major+minor version)
+                                  "/cmake-" version ".tar.gz"))
+              (sha256
+               (base32
+                "0yz79h2yvqyhyzhr889mfadqq20am5g1z0aqz22kdia9jnxwl13g"))
+              (patches (append (origin-patches (package-source cmake))
+                               (search-patches "cmake-3.11-pthread-fix.patch")))
+              (snippet
+               '(begin
+                  ;; Drop bundled software.
+                  (with-directory-excursion "Utilities"
+                    (for-each delete-file-recursively
+                              '("cmbzip2"
+                                "cmcurl"
+                                "cmexpat"
+                                "cmliblzma"
+                                "cmzlib"))
+                    #t)))))
+    (build-system gnu-build-system)
+    (arguments
+     `(,@(substitute-keyword-arguments (package-arguments cmake)
+           ((#:phases phases)
+            `(modify-phases ,phases
+               (replace 'patch-bin-sh
+                 (lambda _
+                   ;; Replace "/bin/sh" by the right path in... a lot of
+                   ;; files.
+                   (substitute*
+                       '("Modules/CompilerId/Xcode-3.pbxproj.in"
+                         "Modules/CPack.RuntimeScript.in"
+                         "Source/cmakexbuild.cxx"
+                         "Source/cmGlobalXCodeGenerator.cxx"
+                         "Source/cmLocalUnixMakefileGenerator3.cxx"
+                         "Source/cmExecProgramCommand.cxx"
+                         "Utilities/Release/release_cmake.cmake"
+                         "Utilities/cmlibarchive/libarchive/archive_write_set_format_shar.c"
+                         "Tests/CMakeLists.txt"
+                         "Tests/RunCMake/File_Generate/RunCMakeTest.cmake")
+                     (("/bin/sh") (which "sh")))
+                   #t))
+               ;; Parallel tests are unsupported in newer releases.
+               (delete 'set-test-environment)
+               (add-before 'check 'disable-broken-test
+                 (lambda _
+                   ;; This test is broken with SOURCE_DATE_EPOCH since CMake 3.8.
+                   ;; https://gitlab.kitware.com/cmake/cmake/issues/17762
+                   (substitute* "Tests/CMakeTests/StringTest.cmake.in"
+                     ((".*TIMESTAMP-UnixTime.*") "\n"))
+                   #t)))))))
+    (inputs
+     `(("rhash" ,rhash)
+       ,@(package-inputs cmake)))))
diff --git a/gnu/packages/patches/cmake-3.11-pthread-fix.patch b/gnu/packages/patches/cmake-3.11-pthread-fix.patch
new file mode 100644
index 000000000..4f5ae5add
--- /dev/null
+++ b/gnu/packages/patches/cmake-3.11-pthread-fix.patch
@@ -0,0 +1,30 @@
+Fix pthread link failure when using system libuv.
+
+Copied from upstream source repository:
+https://gitlab.kitware.com/cmake/cmake/commit/94eee5e683b80e0ffd8e0c4fd3a45b03f0f37b18
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index e4d2a9a0a2..66239595ef 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -310,6 +310,8 @@ endmacro()
+ # Simply to improve readability of the main script.
+ #-----------------------------------------------------------------------
+ macro (CMAKE_BUILD_UTILITIES)
++  find_package(Threads)
++
+   #---------------------------------------------------------------------
+   # Create the kwsys library for CMake.
+   set(KWSYS_NAMESPACE cmsys)
+diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
+index e7c0732675..a0010a292b 100644
+--- a/Source/CMakeLists.txt
++++ b/Source/CMakeLists.txt
+@@ -765,6 +765,7 @@ target_link_libraries(CMakeLib cmsys
+   ${CMAKE_LIBUV_LIBRARIES}
+   ${CMAKE_LIBRHASH_LIBRARIES}
+   ${CMake_KWIML_LIBRARIES}
++  ${CMAKE_THREAD_LIBS_INIT}
+   )
+ 
+ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
-- 
2.16.2