add superbuild to compile Geant4 from submodule source
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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=<INSTALL_DIR>
|
||||
-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 <BINARY_DIR> --parallel ${NPROC}
|
||||
INSTALL_COMMAND cmake --install <BINARY_DIR>
|
||||
)
|
||||
|
||||
# ── 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 <BINARY_DIR> --target run_pbwo4 --parallel ${NPROC}
|
||||
INSTALL_COMMAND ""
|
||||
DEPENDS geant4
|
||||
)
|
||||
Reference in New Issue
Block a user