From d8c105a7b1f882f6a25f6c590d31e94a891220e0 Mon Sep 17 00:00:00 2001
From: Benedikt Riedel <benedikt.riedel@gmail.com>
Date: Tue, 23 Jan 2018 03:13:08 -0600
Subject: [PATCH] Fix GEANT4 and make more portable and flexible (#6956)

* Turning off default Qt support. Restricting Qt version to <= 4.9 else geant4 won't build

* Making vecgeom optional

* Differentiating between cxx11 and cxx14 support

* Making vecgeom optional. Part 2. forgot to move usolids option

* Adding explicit CXX11 and CXX14 support

* Adding more clhep version to support newer GEANT4 versions

* Adding GEANT4 versions 10.03.p03 and 10.04

* Checkpoint. Adding opengl and x11 variant. Lead up to more changes to enable X11 support

* Adding dependency on fixesproto for newer versions

* Making the X11 dependent pieces work without requiring X11 on the system

* Adding motif
---
 .../repos/builtin/packages/clhep/package.py   |  3 ++
 .../repos/builtin/packages/geant4/package.py  | 54 ++++++++++++++-----
 .../builtin/packages/libxcomposite/package.py |  2 +-
 .../repos/builtin/packages/motif/package.py   | 45 ++++++++++++++++
 4 files changed, 90 insertions(+), 14 deletions(-)
 create mode 100644 var/spack/repos/builtin/packages/motif/package.py

diff --git a/var/spack/repos/builtin/packages/clhep/package.py b/var/spack/repos/builtin/packages/clhep/package.py
index f1f1d2db96..22fcb659c8 100644
--- a/var/spack/repos/builtin/packages/clhep/package.py
+++ b/var/spack/repos/builtin/packages/clhep/package.py
@@ -33,6 +33,9 @@ class Clhep(CMakePackage):
     list_url = "https://proj-clhep.web.cern.ch/proj-clhep/"
     list_depth = 1
 
+    version('2.4.0.1', 'f06aa2924abbfee0afd5a9beaaa883cf')
+    version('2.4.0.0', '9af6644e4e04d6807f53956512b7396a')
+    version('2.3.4.5', '31b4785b40706ff7503bb9ffd412487a')
     version('2.3.4.4', '8b8a33d0d19213b60d6c22ce5fc93761')
     version('2.3.4.3', '6941279f70d69492fff1aa955f3f2562')
     version('2.3.4.2', '1e7a9046c9ad0b347d6812f8031191da')
diff --git a/var/spack/repos/builtin/packages/geant4/package.py b/var/spack/repos/builtin/packages/geant4/package.py
index d6391eb688..96498905a3 100644
--- a/var/spack/repos/builtin/packages/geant4/package.py
+++ b/var/spack/repos/builtin/packages/geant4/package.py
@@ -36,21 +36,45 @@ class Geant4(CMakePackage):
     homepage = "http://geant4.cern.ch/"
     url = "http://geant4.cern.ch/support/source/geant4.10.01.p03.tar.gz"
 
+    version('10.04', 'b84beeb756821d0c61f7c6c93a2b83de')
+    version('10.03.p03', 'ccae9fd18e3908be78784dc207f2d73b')
+    version('10.02.p03', '2b887e66f0d41174016160707662a77b')
     version('10.02.p02', '6aae1d0fc743b0edc358c5c8fbe48657')
     version('10.02.p01', 'b81f7082a15f6a34b720b6f15c6289cfe4ddbbbdcef0dc52719f71fac95f7f1c')
     version('10.01.p03', '4fb4175cc0dabcd517443fbdccd97439')
 
     variant('qt', default=False, description='Enable Qt support')
+    variant('vecgeom', default=False, description='Enable vecgeom support')
+    variant('cxx11', default=True, description='Enable CXX11 support')
+    variant('cxx14', default=False, description='Enable CXX14 support')
+    variant('opengl', default=False, description='Optional OpenGL support')
+    variant('x11', default=False, description='Optional X11 support')
+    variant('motif', default=False, description='Optional motif support')
 
     depends_on('cmake@3.5:', type='build')
 
-    depends_on("clhep@2.3.1.1~cxx11+cxx14", when="@10.02.p02")
-    depends_on("clhep@2.3.1.1~cxx11+cxx14", when="@10.02.p01")
-    depends_on("clhep@2.2.0.4~cxx11+cxx14", when="@10.01.p03")
+    # C++11 support
+    depends_on("clhep@2.4.0.0+cxx11~cxx14", when="@10.04+cxx11~cxx14")
+    depends_on("clhep@2.3.4.3+cxx11~cxx14", when="@10.03.p03+cxx11~cxx14")
+    depends_on("clhep@2.3.1.1+cxx11~cxx14", when="@10.02.p01+cxx11~cxx14")
+    depends_on("clhep@2.3.1.1+cxx11~cxx14", when="@10.02.p01+cxx11~cxx14")
+    depends_on("clhep@2.2.0.4+cxx11~cxx14", when="@10.01.p03+cxx11~cxx14")
+
+    # C++14 support
+    depends_on("clhep@2.4.0.0+cxx11~cxx14", when="@10.04~cxx11+cxx14")
+    depends_on("clhep@2.3.4.3+cxx11~cxx14", when="@10.03.p03~cxx11+cxx14")
+    depends_on("clhep@2.3.1.1~cxx11+cxx14", when="@10.02.p02~cxx11+cxx14")
+    depends_on("clhep@2.3.1.1~cxx11+cxx14", when="@10.02.p01~cxx11+cxx14")
+    depends_on("clhep@2.2.0.4~cxx11+cxx14", when="@10.01.p03~cxx11+cxx14")
+
     depends_on("expat")
     depends_on("zlib")
-    depends_on("vecgeom")
     depends_on("xerces-c")
+    depends_on("mesa", when='+opengl')
+    depends_on("libx11", when='+x11')
+    depends_on("libxmu", when='+x11')
+    depends_on("motif", when='+motif')
+    depends_on("vecgeom", when="+vecgeom")
     depends_on("qt@4.8:4.999", when="+qt")
 
     def cmake_args(self):
@@ -63,19 +87,19 @@ def cmake_args(self):
             '-DGEANT4_INSTALL_DATA=ON',
             '-DGEANT4_BUILD_TLS_MODEL=global-dynamic',
             '-DGEANT4_BUILD_MULTITHREADED=ON',
-            '-DGEANT4_USE_USOLIDS=ON',
             '-DGEANT4_USE_SYSTEM_EXPAT=ON',
             '-DGEANT4_USE_SYSTEM_ZLIB=ON',
             '-DXERCESC_ROOT_DIR:STRING=%s' %
-            spec['xerces-c'].prefix,
-            '-DUSolids_DIR=%s' %
-            join_path(spec['vecgeom'].prefix, 'lib/CMake/USolids')]
+            spec['xerces-c'].prefix, ]
 
         arch = platform.system().lower()
         if arch is not 'darwin':
-            options.append('-DGEANT4_USE_OPENGL_X11=ON')
-            options.append('-DGEANT4_USE_XM=ON')
-            options.append('-DGEANT4_USE_RAYTRACER_X11=ON')
+            if "+x11" in spec and "+opengl" in spec:
+                options.append('-DGEANT4_USE_OPENGL_X11=ON')
+            if "+motif" in spec and "+opengl" in spec:
+                options.append('-DGEANT4_USE_XM=ON')
+            if "+x11" in spec:
+                options.append('-DGEANT4_USE_RAYTRACER_X11=ON')
 
         if '+cxx11' in spec:
             options.append('-DGEANT4_BUILD_CXXSTD=c++11')
@@ -86,8 +110,12 @@ def cmake_args(self):
             options.append('-DGEANT4_USE_QT=ON')
             options.append(
                 '-DQT_QMAKE_EXECUTABLE=%s' %
-                spec['qt'].prefix + '/bin/qmake'
-            )
+                spec['qt'].prefix.bin.qmake)
+
+        if '+vecgeom' in spec:
+            options.append('-DGEANT4_USE_USOLIDS=ON')
+            options.append('-DUSolids_DIR=%s' % spec[
+                'vecgeom'].prefix.lib.CMake.USolids)
 
         return options
 
diff --git a/var/spack/repos/builtin/packages/libxcomposite/package.py b/var/spack/repos/builtin/packages/libxcomposite/package.py
index 840659b337..b2c5caae12 100644
--- a/var/spack/repos/builtin/packages/libxcomposite/package.py
+++ b/var/spack/repos/builtin/packages/libxcomposite/package.py
@@ -36,7 +36,7 @@ class Libxcomposite(AutotoolsPackage):
 
     depends_on('libx11')
     depends_on('libxfixes')
-
+    depends_on('fixesproto@0.4:', type='build')
     depends_on('compositeproto@0.4:', type='build')
     depends_on('pkgconfig', type='build')
     depends_on('util-macros', type='build')
diff --git a/var/spack/repos/builtin/packages/motif/package.py b/var/spack/repos/builtin/packages/motif/package.py
new file mode 100644
index 0000000000..466b1c69a6
--- /dev/null
+++ b/var/spack/repos/builtin/packages/motif/package.py
@@ -0,0 +1,45 @@
+##############################################################################
+# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://github.com/spack/spack
+# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License (as
+# published by the Free Software Foundation) version 2.1, February 1999.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
+# conditions of the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+from spack import *
+
+
+class Motif(AutotoolsPackage):
+    """"
+    Motif - Graphical user interface (GUI)
+    specification and the widget toolkit
+    """
+    homepage = "http://motif.ics.com/"
+    url = "http://cfhcable.dl.sourceforge.net/project/motif/Motif 2.3.8 Source Code/motif-2.3.8.tar.gz"
+
+    version('2.3.8', '7572140bb52ba21ec2f0c85b2605e2b1')
+
+    depends_on("flex")
+    depends_on("libx11")
+    depends_on("libxt")
+    depends_on("libxext")
+    depends_on("libxft")
+    depends_on("libxcomposite")
+    depends_on("libxfixes")
+    depends_on("xbitmaps")
-- 
GitLab