Skip to content
Snippets Groups Projects
Commit 0c04b80a authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Get Geant4 sources from git instead of tarfiles

parent 9562515a
Branches
Tags
No related merge requests found
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
set(Geant4_version 4.9.6.p04)
if(DEFINED ENV{G4_NATIVE_VERSION})
# Override the version of Geant4 from the variable
set(Geant4_version $ENV{G4_NATIVE_VERSION})
if(NOT Geant4_version MATCHES "^4\\.")
# G4_NATIVE_VERSION might not contain the initial '4.' that we need
# see https://its.cern.ch/jira/browse/LHCBGAUSS-43
set(Geant4_version 4.${Geant4_version})
endif()
endif()
find_package(GaudiProject)
gaudi_project(Geant4 v96r4p3
DATA Geant4Files VERSION v96r*)
......
......@@ -21,11 +21,22 @@ else()
set(G4DATA ../share)
endif()
if(DEFINED ENV{G4_NATIVE_VERSION})
set(Geant4_tag $ENV{G4_NATIVE_VERSION})
if(NOT Geant4_tag MATCHES "^4\\.")
# G4_NATIVE_VERSION might not contain the initial '4.' that we need
# see https://its.cern.ch/jira/browse/LHCBGAUSS-43
set(Geant4_tag 4.${Geant4_version})
endif()
else()
set(Geant4_tag ${CMAKE_PROJECT_VERSION})
endif()
include(ExternalProject)
ExternalProject_Add(Geant4
URL http://geant4.cern.ch/support/source/geant${Geant4_version}.tar.gz
PATCH_COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/patches/patch_g4_sources.py ${CMAKE_SOURCE_DIR} ${Geant4_version}
GIT_REPOSITORY https://gitlab.cern.ch/lhcb/Geant4-srcs.git
GIT_TAG ${Geant4_tag}
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_SOURCE_DIR}/toolchain.cmake
-DGEANT4_BUILD_CXXSTD=${GAUDI_CXX_STANDARD}
-DGEANT4_INSTALL_DATA=OFF
......
# - Try to find CLHEP
# Defines:
#
# CLHEP_FOUND
# CLHEP_VERSION
# CLHEP_INCLUDE_DIR
# CLHEP_INCLUDE_DIRS (not cached)
# CLHEP_<component>_LIBRARY
# CLHEP_<component>_FOUND
# CLHEP_LIBRARIES (not cached)
# CLHEP_LIBRARY_DIRS (not cached)
#
# Note: version detection inspired by FindBoost.cmake
find_path(CLHEP_INCLUDE_DIR CLHEP/ClhepVersion.h
HINTS $ENV{CLHEP_ROOT_DIR}/include ${CLHEP_ROOT_DIR}/include)
if(CLHEP_INCLUDE_DIR)
if(NOT DEFINED CLHEP_VERSION)
file(READ "${CLHEP_INCLUDE_DIR}/CLHEP/ClhepVersion.h" _CLHEP_VERSION_H_CONTENTS)
string(REGEX REPLACE ".*static std::string String\\(\\)[^\"]*return \"([^\"]*)\".*" "\\1" CLHEP_VERSION "${_CLHEP_VERSION_H_CONTENTS}")
set(CLHEP_VERSION ${CLHEP_VERSION} CACHE INTERNAL "Detected version of CLHEP")
message(STATUS "CLHEP version: ${CLHEP_VERSION}")
endif()
endif()
set(_CLHEP_COMPONENTS Cast Evaluator Exceptions GenericFunctions Geometry Random RandomObjects RefCount Vector Matrix)
foreach(component ${_CLHEP_COMPONENTS})
find_library(CLHEP_${component}_LIBRARY NAMES CLHEP-${component}-${CLHEP_VERSION}
HINTS $ENV{CLHEP_ROOT_DIR}/lib ${CLHEP_ROOT_DIR}/lib)
if (CLHEP_${component}_LIBRARY)
set(CLHEP_${component}_FOUND 1)
list(APPEND CLHEP_LIBRARIES ${CLHEP_${component}_LIBRARY})
get_filename_component(libdir ${CLHEP_${component}_LIBRARY} PATH)
list(APPEND CLHEP_LIBRARY_DIRS ${libdir})
else()
set(CLHEP_${component}_FOUND 0)
endif()
mark_as_advanced(CLHEP_${component}_LIBRARY)
endforeach()
if(CLHEP_LIBRARY_DIRS)
list(REMOVE_DUPLICATES CLHEP_LIBRARY_DIRS)
endif()
set(CLHEP_INCLUDE_DIRS ${CLHEP_INCLUDE_DIR})
# handle the QUIETLY and REQUIRED arguments and set CLHEP_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CLHEP DEFAULT_MSG CLHEP_INCLUDE_DIR CLHEP_LIBRARIES)
mark_as_advanced(CLHEP_FOUND CLHEP_INCLUDE_DIR)
# Hack for Geeant4 compatibility (we choose a random library)
set(CLHEP_LIBRARY ${CLHEP_Random_LIBRARY})
This diff is collapsed.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Script to patch Geant 4 sources for LHCb.
'''
import sys
import os
import shutil
import logging
from subprocess import call
from os.path import join, basename, exists
logging.basicConfig(level=logging.INFO)
log = logging.getLogger()
# root directory of the project and Geant4 version
root_dir, g4vers = sys.argv[1:]
script_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
# apply patch to CMake configuration
log.info('patching Geant4 CMake configuration')
call(['patch', '-p2', '-i', join(script_dir, 'geant4.cmake.patch')])
# copy physics lists
def copydir(src, dst):
if not os.path.exists(dst):
log.info('creating directory %s', dst)
os.makedirs(dst)
for f in os.listdir(src):
if f in ('.', '..', '.svn'):
continue
if os.path.isdir(join(src, f)):
copydir(join(src, f), join(dst, f))
else:
log.info('copying %s -> %s', join(src, f), join(dst, f))
shutil.copy(join(src, f), join(dst, f))
copydir(join(root_dir, 'Geant4', 'G4LHCblists', 'G4LHCblists'),
join('source', 'physics_lists', 'LHCb', 'include'))
copydir(join(root_dir, 'Geant4', 'G4LHCblists', 'src'),
join('source', 'physics_lists', 'LHCb', 'src'))
# replace fixed files
fixes_root = join(root_dir, 'Geant4', 'G4processes', 'srcnew')
fixes_dst_root = join('source', 'processes', 'hadronic')
# (fixes is a list of pairs, src+dst)
fixes = [(join('cross_sections', 'G4ElectroNuclearCrossSection.cc'), join(fixes_dst_root, 'cross_sections', 'src'))]
for src, dst in fixes:
log.info('copying %s to dir %s', join(fixes_root, src), dst)
# bkup
old = join(dst, basename(src))
if exists(old):
shutil.copy(old, old + '.orig')
shutil.copy(join(fixes_root, src), dst)
# override Geant4 cmake modules
copydir(join(script_dir, 'cmake', 'Modules'),
join('cmake', 'Modules'))
# patches to examples
for proc_type, ex_name, patch_map in [('electromagnetic', 'TestEm3', [('srcnew', 'src')]),
('electromagnetic', 'TestEm5', [('incnew', 'include'),
('srcnew', '.')])]:
for patches, orig in patch_map:
src = join(root_dir, 'Geant4', 'G4examples', 'extended', proc_type, 'G4' + ex_name, patches)
dst = join('examples', 'extended', proc_type, ex_name, orig)
#print src, dst
if exists(src):
copydir(src, dst)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment