From e265a6aa6308d0a72057559e3eed3e193d8f9f6a Mon Sep 17 00:00:00 2001 From: Lars Bogner Date: Thu, 11 Jun 2026 10:41:47 +0200 Subject: [PATCH] add superbuild to compile Geant4 from submodule source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit superbuild/CMakeLists.txt uses ExternalProject_Add to give three targets: cmake -B build -S superbuild/ cmake --build build --target geant4 # build Geant4 → build/geant4-install cmake --build build --target run_pbwo4 # build minicalosim against it cmake --build build # both The existing root CMakeLists.txt (find_package Geant4) is unchanged for the system-Geant4 workflow. Co-Authored-By: Claude Sonnet 4.6 --- superbuild/CMakeLists.txt | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 superbuild/CMakeLists.txt diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt new file mode 100644 index 0000000..4a64abe --- /dev/null +++ b/superbuild/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 3.16) +project(minicalosim-superbuild NONE) + +include(ExternalProject) +include(ProcessorCount) + +ProcessorCount(NPROC) +if(NOT NPROC OR NPROC EQUAL 0) + set(NPROC 4) +endif() +# Cap at 16 to avoid memory exhaustion on large machines (mirrors Dockerfile) +if(NPROC GREATER 16) + set(NPROC 16) +endif() + +set(G4_INSTALL ${CMAKE_BINARY_DIR}/geant4-install) +set(G4_SRC ${CMAKE_SOURCE_DIR}/../lib/geant4) +set(MINI_SRC ${CMAKE_SOURCE_DIR}/..) + +option(GEANT4_INSTALL_DATA "Download Geant4 physics data files (~2 GB)" ON) + +# ── Geant4 ──────────────────────────────────────────────────────────────────── +ExternalProject_Add(geant4 + SOURCE_DIR ${G4_SRC} + BINARY_DIR ${CMAKE_BINARY_DIR}/geant4-build + INSTALL_DIR ${G4_INSTALL} + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX= + -DCMAKE_BUILD_TYPE=Release + -DGEANT4_INSTALL_DATA=${GEANT4_INSTALL_DATA} + -DGEANT4_USE_GDML=ON + -DGEANT4_BUILD_MULTITHREADED=OFF + -DGEANT4_BUILD_TLS_MODEL=global-dynamic + BUILD_COMMAND cmake --build --parallel ${NPROC} + INSTALL_COMMAND cmake --install +) + +# ── minicalosim (run_pbwo4) ─────────────────────────────────────────────────── +ExternalProject_Add(run_pbwo4 + SOURCE_DIR ${MINI_SRC} + BINARY_DIR ${CMAKE_BINARY_DIR}/minicalosim-build + CMAKE_ARGS + -DCMAKE_PREFIX_PATH=${G4_INSTALL} + -DWITH_GEANT4_UIVIS=OFF + BUILD_COMMAND cmake --build --target run_pbwo4 --parallel ${NPROC} + INSTALL_COMMAND "" + DEPENDS geant4 +)