Manual installation on macOS (with M series chip)


The following procedure works with Sonoma (macOS version 14.* with M series chip), for Geant4 version 11.2.0.

We first explain how to install Geant4 in your "home" directory and then how to use the toolkit. We suggest to read the whole procedure first.
The steps described have been updated from the web site of Igor Semeniouk (LLR/IN2P3/CNRS, France, Geant4 version 10.7) whom we thank very much.

A) Installation of Geant4


Users (with root access) can install Geant4 (which includes Geant4-DNA) on a Mac M series chip computer following these instructions, once for each new fresh Geant4 installation.

If asked, make sure to allow the Terminal application to execute commands and tools.

Instructions in pink depend on user choice.

Instructions in purple depend on software version installed by the Homebrew package manager.

1) Make sure to run the last version of macOS

2) Install the Xcode development framework

3) Install Xcode command line tools by typing the following command in a terminal:

xcode-select --install

4) Install the Homebrew package manager by typing in a terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After installation, run the indicated commands to add Homebrew to your PATH. This is needed for the next steps that use brew.

5)
Install the CMake build system by typing in the terminal:

brew install cmake

Note that any
package installed with brew can be removed using brew uninstall package

6) Install the Qt version 5 application development framework by typing in the terminal:

brew install qt@5

7) Define the PKG_CONFIG_PATH environment variable for Qt 5 by typing in the terminal:

export PKG_CONFIG_PATH=/opt/homebrew/Cellar/qt@5/5.15.2_1/lib/pkgconfig/
export PATH=
/opt/homebrew/Cellar/qt@5/5.15.2_1/bin:$PATH

8) Install the Xerces-C++ XML parser (needed for the handling of GDML files) by typing in the terminal:

brew install xerces-c

9) Install the ROOT data analysis framework

brew install root

10) Download Geant4 version 11.2.0 using git (see Geant4 current version number X.Y.Z such as 11.2.0 at this link).

cd
git clone https://gitlab.cern.ch/geant4/geant4.git
cd geant4
git checkout v
11.2.0
cd ..

11) Create a build directory:

cd
mkdir build
cd build


and run CMake to configure the build:

cmake
-DCMAKE_INSTALL_PREFIX=
/Users/yourname/geant4-v11.2.0-install
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DGEANT4_USE_GDML=ON
-DGEANT4_BUILD_MULTITHREADED=ON
-DXERCESC_ROOT_DIR=
/opt/homebrew/Cellar/xerces-c/3.2.3
-DGEANT4_USE_QT=ON
-DGEANT4_INSTALL_EXAMPLES=ON
-DGEANT4_INSTALL_DATA=ON
-DGEANT4_USE_SYSTEM_EXPAT=OFF
-DGEANT4_BUILD_TLS_MODEL=auto
../geant4

Notes
  • the directory /Users/yourname is the "home" directory from which any terminal session starts (check it by typing pwd in the terminal).
  • this cmake command should be typed as a single line, with a space before each "-" and "..". You can get the full command as a text file here.
  • when the option -DGEANT4_INSTALL_DATA=ON is selected, Geant4 datasets are automatically downloaded, but the download can sometimes be very slow; instead, you can ignore this option and install all data files manually as explained in the installation instructions (uncompress each dataset file using tar -xvf filename.tar).

12)
Run the build with (e.g., using 10 cores):

cmake --build . --target install -- -j10


B) How to use Geant4


1)
Create a .zshrc file from the terminal in your "home" directory, using for example :

nano .zshrc

and add the following lines
:

#
#Qt5
#
export PKG_CONFIG_PATH=
/opt/homebrew/Cellar/qt@5/5.15.2_1/lib/pkgconfig/
export PATH=
/opt/homebrew/Cellar/qt@5/5.15.2_1/bin:$PATH
#
#ROOT
#
source
/opt/homebrew/Cellar/root/6.26.06_2/bin/thisroot.sh
#
#Geant4
#
cd
/Users/yourname/geant4-v11.2.0-install/bin
source geant4.sh
export G4COMP=
/Users/yourname/geant4-v11.2.0-install/lib/Geant4-11.2.0
export CMAKE_PREFIX_PATH=$G4COMP
alias comp='cmake -DGeant4_DIR=$G4COMP -DGEANT4_BUILD_MULTITHREADED=ON'
#
cd

Save your file with control X key combination and answer Y.

2) Source this file with source .zshrc or start a new terminal (from Monterey macOS, the .zshrc file will be read automatically each time you open a new terminal, making your computer fully configured to use Geant4).

3) As an illustration, if you want to test the dnaphysics extended example (with a build on 10 cores), do the following:

cd
cp -R geant4/examples/extended/medical/dna/dnaphysics .
cd dnaphysics
mkdir build
cd build
comp ..
make -j
10
./dnaphysics dnaphysics.in
root plot.C

C) Comments


a) After update of Xcode, if the cmake command fails, you may need to relink to MacOSX.sdk. For this, do as follows in a Terminal (assuming that you know your super user password and that you have authorized Terminal to modify Apps):

cd
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
sudo ln -s MacOSX.sdk MacOSX
Y.Z.sdk

where
Y and Z are given by the cmake command error message, for example :

sudo ln -s MacOSX.sdk MacOSX13.0.sdk

b) If for some reason
ROOT installation using brew is failing, an alternative solution is to install ROOT using Anaconda. See installation instructions using Conda here. More details on the issue here.


-
Updated on 16/03/2024

RapidWeaver Icon

Made in RapidWeaver