From 67d432470ad49850b22079538f4273948aabd818 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 13 Jun 2024 13:17:08 +0200 Subject: [PATCH] Full CMake based build chain (#19) --- .github/workflows/macos_cmake.yml | 526 ++++++++++++++++++++++++++++++ CMakeLists.txt | 330 +++++++++++++++++++ dependencies.sh | 17 + pythia8-forward-decl.patch | 37 +++ 4 files changed, 910 insertions(+) create mode 100644 .github/workflows/macos_cmake.yml create mode 100644 CMakeLists.txt create mode 100755 dependencies.sh create mode 100644 pythia8-forward-decl.patch diff --git a/.github/workflows/macos_cmake.yml b/.github/workflows/macos_cmake.yml new file mode 100644 index 0000000..ec92768 --- /dev/null +++ b/.github/workflows/macos_cmake.yml @@ -0,0 +1,526 @@ +name: macOS_cmake + +on: [push, pull_request] + +env: + BUILD_DIR: ${{ github.workspace }}/build + INSTALL_DIR: ${{ github.workspace }}/install + + CCACHE_DIR: ${{ github.workspace }}/ccache + CCACHE_MAXSIZE: 10G + +jobs: + + build_python: + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Cache build + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ github.job }}-python + restore-keys: | + ccache-${{ runner.os }}-${{ github.job }}-python + ccache-${{ runner.os }}-${{ github.job }}- + + - run: ls -al /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ + + + - name: Initial configure + run: cmake -S ${{ github.workspace }} -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_PARALLEL_LEVEL=3 + + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- python + + - name: Remove .pyc files and tests from install directory + run: | + find ${INSTALL_DIR} -type f -name *.pyc -delete + rm -rf ${INSTALL_DIR}/python/3.12.2/lib/python3.12/test + + - name: Package build + run: | + tar czf build.tar.gz -C ${BUILD_DIR} . + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_1 + path: | + build.tar.gz + install.tar.gz + + # can run in parallel, not needed by anything else + build_boost_eigen: + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Initial configure + run: cmake -S ${{ github.workspace }} -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=${{ env.INSTALL_DIR }} -DCMAKE_BUILD_PARALLEL_LEVEL=3 + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- boost eigen + + - name: Package build + run: | + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_boost_eigen + path: | + install.tar.gz + + build_tbb: + runs-on: macos-14 + needs: [build_python] + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Cache build + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ github.job }}-tbb + restore-keys: | + ccache-${{ runner.os }}-${{ github.job }}-tbb + ccache-${{ runner.os }}-${{ github.job }}- + + - uses: actions/download-artifact@v4 + with: + name: build_1 + path: . + + - run: | + mkdir ${BUILD_DIR} + tar xf build.tar.gz -C ${BUILD_DIR} + mkdir ${INSTALL_DIR} + tar xf install.tar.gz -C ${INSTALL_DIR} + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- tbb + + - name: Package build + run: | + tar czf build.tar.gz -C ${BUILD_DIR} . + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_2 + path: | + build.tar.gz + install.tar.gz + + build_nlohmann_json: + runs-on: macos-14 + needs: [build_tbb] + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Cache build + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ github.job }}-nlohmann_json + restore-keys: | + ccache-${{ runner.os }}-${{ github.job }}-nlohmann_json + ccache-${{ runner.os }}-${{ github.job }}- + + - uses: actions/download-artifact@v4 + with: + name: build_2 + path: . + + - run: | + mkdir ${BUILD_DIR} + tar xf build.tar.gz -C ${BUILD_DIR} + mkdir ${INSTALL_DIR} + tar xf install.tar.gz -C ${INSTALL_DIR} + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- nlohmann_json + + - name: Package build + run: | + tar czf build.tar.gz -C ${BUILD_DIR} . + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_3 + path: | + build.tar.gz + install.tar.gz + + build_root: + runs-on: macos-14 + + needs: [build_nlohmann_json] + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Cache build + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ github.job }}-root + restore-keys: | + ccache-${{ runner.os }}-${{ github.job }}-root + ccache-${{ runner.os }}-${{ github.job }}- + + - uses: actions/download-artifact@v4 + with: + name: build_3 + path: . + + - run: | + mkdir ${BUILD_DIR} + tar xf build.tar.gz -C ${BUILD_DIR} + mkdir ${INSTALL_DIR} + tar xf install.tar.gz -C ${INSTALL_DIR} + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- root + + - name: Package build + run: | + tar czf build.tar.gz -C ${BUILD_DIR} . + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_4 + path: | + build.tar.gz + install.tar.gz + + build_podio_edm4hep: + runs-on: macos-14 + + needs: [build_root] + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Cache build + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ github.job }}-podio + restore-keys: | + ccache-${{ runner.os }}-${{ github.job }}-podio + ccache-${{ runner.os }}-${{ github.job }}- + + - uses: actions/download-artifact@v4 + with: + name: build_4 + path: . + + - run: | + mkdir ${BUILD_DIR} + tar xf build.tar.gz -C ${BUILD_DIR} + mkdir ${INSTALL_DIR} + tar xf install.tar.gz -C ${INSTALL_DIR} + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- podio edm4hep + + - name: Package build + run: | + tar czf build.tar.gz -C ${BUILD_DIR} . + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_5 + path: | + build.tar.gz + install.tar.gz + + build_geant4: + runs-on: macos-14 + + needs: [build_podio_edm4hep] + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Cache build + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ github.job }}-geant4 + restore-keys: | + ccache-${{ runner.os }}-${{ github.job }}-geant4 + ccache-${{ runner.os }}-${{ github.job }}- + + - uses: actions/download-artifact@v4 + with: + name: build_5 + path: . + + - run: | + mkdir ${BUILD_DIR} + tar xf build.tar.gz -C ${BUILD_DIR} + mkdir ${INSTALL_DIR} + tar xf install.tar.gz -C ${INSTALL_DIR} + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- geant4 + + - name: Package build + run: | + tar czf build.tar.gz -C ${BUILD_DIR} . + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_6 + path: | + build.tar.gz + install.tar.gz + + build_dd4hep: + runs-on: macos-14 + + needs: [build_geant4] + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Cache build + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ github.job }}-dd4hep + restore-keys: | + ccache-${{ runner.os }}-${{ github.job }}-dd4hep + ccache-${{ runner.os }}-${{ github.job }}- + + - uses: actions/download-artifact@v4 + with: + name: build_6 + path: . + + - run: | + mkdir ${BUILD_DIR} + tar xf build.tar.gz -C ${BUILD_DIR} + mkdir ${INSTALL_DIR} + tar xf install.tar.gz -C ${INSTALL_DIR} + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- dd4hep + + - name: Package build + run: | + tar czf build.tar.gz -C ${BUILD_DIR} . + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_7 + path: | + build.tar.gz + install.tar.gz + + build_hepmc3: + runs-on: macos-14 + + needs: [build_dd4hep] + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Cache build + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ github.job }}-hepmc3 + restore-keys: | + ccache-${{ runner.os }}-${{ github.job }}-hepmc3 + ccache-${{ runner.os }}-${{ github.job }}- + + - uses: actions/download-artifact@v4 + with: + name: build_7 + path: . + + - run: | + mkdir ${BUILD_DIR} + tar xf build.tar.gz -C ${BUILD_DIR} + mkdir ${INSTALL_DIR} + tar xf install.tar.gz -C ${INSTALL_DIR} + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- hepmc3 + + - name: Package build + run: | + tar czf build.tar.gz -C ${BUILD_DIR} . + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_8 + path: | + build.tar.gz + install.tar.gz + + build_pythia8: + runs-on: macos-14 + + needs: [build_hepmc3] + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./dependencies.sh + + - name: Cache build + uses: actions/cache@v4 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ runner.os }}-${{ github.job }}-pythia8 + restore-keys: | + ccache-${{ runner.os }}-${{ github.job }}-pythia8 + ccache-${{ runner.os }}-${{ github.job }}- + + - uses: actions/download-artifact@v4 + with: + name: build_8 + path: . + + - run: | + mkdir ${BUILD_DIR} + tar xf build.tar.gz -C ${BUILD_DIR} + mkdir ${INSTALL_DIR} + tar xf install.tar.gz -C ${INSTALL_DIR} + + - name: Build + run: > + cmake --build ${BUILD_DIR} -- hepmc3 + + - name: Package build + run: | + tar czf build.tar.gz -C ${BUILD_DIR} . + tar czf install.tar.gz -C ${INSTALL_DIR} . + + - uses: actions/upload-artifact@v4 + with: + name: build_9 + path: | + build.tar.gz + install.tar.gz + + make_tarball: + runs-on: ubuntu-latest # we don't need macOS here + needs: + - build_pythia8 + - build_boost_eigen + steps: + - uses: actions/download-artifact@v4 + with: + name: build_9 + path: . + + - name: Unpack full bundle + run: | + mkdir -p ${INSTALL_DIR} + tar xf install.tar.gz -C ${INSTALL_DIR} + rm install.tar.gz + + - uses: actions/download-artifact@v4 + with: + name: build_boost_eigen + path: . + + - name: Unpack boost/eigen bundle + run: | + mkdir -p install_boost_eigen + tar xf install.tar.gz -C install_boost_eigen + rm install.tar.gz + + - name: Merge directories + run: cp -r install_boost_eigen/* ${INSTALL_DIR} + + - name: Package merged directory + run: | + tar cf - -C ${INSTALL_DIR} . | zstd -o install.tar.zst -19 -T$(nproc) + + - name: Upload merged install directory + uses: actions/upload-artifact@v4 + with: + name: deps + path: | + install.tar.zst + + deploy_to_eos: + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + runs-on: ubuntu-latest # we don't need macOS here + needs: + - make_tarball + env: + DEPLOY_USER: ${{ secrets.DEPLOY_USER }} + DEPLOY_PWD: ${{ secrets.DEPLOY_PWD }} + steps: + - uses: actions/checkout@v4 + + - name: Install prerequisites + run: > + sudo apt-get install -y krb5-user krb5-config + + - uses: actions/download-artifact@v4 + with: + name: deps + path: . + + - name: Upload + run: > + echo "$DEPLOY_PWD" | kinit $DEPLOY_USER@CERN.CH 2>&1 >/dev/null + && sha=$(echo $GITHUB_SHA | head -c 7) + && name=deps.$sha.tar.gz + && mv deps.tar.gz $name + && scp -F ssh_config $name $DEPLOY_USER@lxplus.cern.ch:/eos/user/a/atsjenkins/www/ACTS/ci/macOS/cmake + && ssh -F ssh_config $DEPLOY_USER@lxplus.cern.ch ln -f -s $name /eos/user/a/atsjenkins/www/ACTS/ci/macOS/cmake/deps.latest.tar.gz diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9a9ec3c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,330 @@ +cmake_minimum_required(VERSION 3.20) +project(ActsDependencies) + +include(ExternalProject) +include(GNUInstallDirs) + +set(PYTHON_VERSION 3.12.2) +set(TBB_VERSION 2021.11.0) +set(GEANT4_VERSION 11.1.3) +set(HEPMC3_VERSION 3.2.5) +set(PYTHIA8_VERSION 311) +set(JSON_VERSION 3.11.2) +set(ROOT_VERSION 6.30.06) +set(ROOT_HASH SHA1=dd95462386e27c205fe8e3396daa9c169627fbf1) +set(PODIO_VERSION 00-17-02) +set(EDM4HEP_VERSION 00-10-01) +set(DD4HEP_VERSION 01-27) +set(BOOST_VERSION 1.84.0) +set(EIGEN_VERSION 3.4.0) + +if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif() + +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() + +set(CMAKE_BUILD_TYPE RelWithDebInfo) + +if(NOT CMAKE_BUILD_PARALLEL_LEVEL) + set(CMAKE_BUILD_PARALLEL_LEVEL 1) +endif() + +# Packages required to build a working python version +find_package(OpenSSL REQUIRED) +find_package(Curses REQUIRED) + +set(openssl_option "") +if(APPLE) + execute_process(COMMAND brew --prefix openssl + OUTPUT_VARIABLE OPENSSL_DIR) + set(openssl_option "--with-openssl=${OPENSSL_DIR}") +endif() + + +message(STATUS ${CMAKE_OSX_SYSROOT}) + +# Determine current platform as minimum from SYSROOT +if(APPLE) + execute_process(COMMAND jq -r .MinimalDisplayName ${CMAKE_OSX_SYSROOT}/SDKSettings.json + COMMAND_ERROR_IS_FATAL ANY + OUTPUT_VARIABLE CMAKE_OSX_DEPLOYMENT_TARGET + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(STATUS "Minimal macOS Deployment Target determined to: ${CMAKE_OSX_DEPLOYMENT_TARGET}") +endif() + +set(python_sdkroot "") +set(python_deployment_target "") +set(python_cflags "-fPIC") +if(APPLE) + set(python_sdkroot "SDKROOT=${CMAKE_OSX_SYSROOT}") + set(python_deployment_target "MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}") +endif() + + +ExternalProject_Add(python + PREFIX python + URL https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz + URL_HASH SHA1=459959e7dbeb89931db03457ea1f012353e34bce + BUILD_IN_SOURCE ON + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env "CFLAGS=${python_cflags}" ${python_sdkroot} ${python_deployment_target} ./configure --prefix=${CMAKE_INSTALL_PREFIX}/python/${PYTHON_VERSION} --enable-optimizations --with-lto ${openssl_option} + BUILD_COMMAND make -j${CMAKE_BUILD_PARALLEL_LEVEL} +) + +string(REGEX MATCH "^([0-9]+\\.[0-9]+)\\.[0-9]+$" _temp ${PYTHON_VERSION}) +set(PYTHON_VERSION_MAJOR_MINOR ${CMAKE_MATCH_1}) + +# We're guessing / expecting this file to be there when it's needed +set(Python_EXECUTABLE "${CMAKE_INSTALL_PREFIX}/python/${PYTHON_VERSION}/bin/python${PYTHON_VERSION_MAJOR_MINOR}") +set(_python_stamp_file "${CMAKE_CURRENT_BINARY_DIR}/python_exe_exists.stamp") + +message(STATUS "Python executable: ${Python_EXECUTABLE}") + +add_custom_command(OUTPUT ${_python_stamp_file} + COMMAND ${CMAKE_COMMAND} -E env sh -c "( test -e ${Python_EXECUTABLE} && touch ${_python_stamp_file} ) || ( echo 'Python executable not found at ${Python_EXECUTABLE}!' && exit 1 )" + VERBATIM + COMMENT "Checking for Python executable" + DEPENDS python) +add_custom_target(PythonExeExists DEPENDS ${_python_stamp_file}) + +ExternalProject_Add(boost + PREFIX boost + URL https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}.tar.gz + URL_HASH SHA1=75366b414f6d0f34533af9ea43acd58bb886e953 + CMAKE_ARGS + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/boost/${BOOST_VERSION} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} +) + +ExternalProject_Add(eigen + PREFIX eigen + URL https://gitlab.com/libeigen/eigen/-/archive/${EIGEN_VERSION}/eigen-${EIGEN_VERSION}.tar.gz + URL_HASH SHA1=d222db69a9e87d9006608e029d1039039f360b52 + CMAKE_ARGS + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/eigen/${EIGEN_VERSION} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} +) + +ExternalProject_Add(tbb + PREFIX tbb + URL https://github.com/oneapi-src/oneTBB/archive/refs/tags/v${TBB_VERSION}.tar.gz + URL_HASH SHA1=740e86b703f42446ddde392b73a9db3dc0f5f4cd + CMAKE_ARGS + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/tbb/${TBB_VERSION} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DTBB_TEST=OFF + BUILD_COMMAND ${CMAKE_COMMAND} -E env CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL} ${CMAKE_COMMAND} --build +) + +ExternalProject_Add(geant4 + PREFIX geant4 + URL https://gitlab.cern.ch/geant4/geant4/-/archive/v${GEANT4_VERSION}/geant4-v${GEANT4_VERSION}.tar.gz + URL_HASH SHA1=69119e8a29d3bd79b70886dc7ae78e6d008e1753 + CMAKE_ARGS + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/geant4/${GEANT4_VERSION} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DGEANT4_BUILD_TLS_MODEL=global-dynamic + -DGEANT4_INSTALL_DATA=OFF + -DGEANT4_USE_GDML=ON + -DGEANT4_USE_SYSTEM_EXPAT=ON + -DGEANT4_USE_SYSTEM_ZLIB=ON + BUILD_COMMAND ${CMAKE_COMMAND} -E env CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL} ${CMAKE_COMMAND} --build +) + +ExternalProject_Add(hepmc3 + PREFIX hepmc3 + URL https://gitlab.cern.ch/hepmc/HepMC3/-/archive/${HEPMC3_VERSION}/HepMC3-${HEPMC3_VERSION}.tar.gz + URL_HASH SHA1=d4c12f5d50a507cd60cf2377286cbd23f59f1f84 + CMAKE_ARGS + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/hepmc3/${HEPMC3_VERSION} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DHEPMC3_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DHEPMC3_BUILD_STATIC_LIBS=OFF + -DHEPMC3_ENABLE_PYTHON=OFF + -DHEPMC3_ENABLE_ROOTIO=OFF + -DHEPMC3_ENABLE_SEARCH=OFF + BUILD_COMMAND ${CMAKE_COMMAND} -E env CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL} ${CMAKE_COMMAND} --build +) + +# Hard-coding the compile flags is not ideal, but seems needed +set(pythia_configure "./configure") +set(pythia_cxx_common "-O2 -std=c++${CMAKE_CXX_STANDARD} -pedantic -W -Wall -Wshadow -fPIC -pthread") +if(APPLE) + list(APPEND pythia_configure "--cxx-common='-isysroot ${CMAKE_OSX_SYSROOT} ${pythia_cxx_common}'") +else() + list(APPEND pythia_configure "${pythia_cxx_common}") +endif() + +ExternalProject_Add(pythia8 + PREFIX pythia8 + DEPENDS PythonExeExists + URL https://pythia.org/download/pythia83/pythia8${PYTHIA8_VERSION}.tgz + URL_HASH SHA1=3186d9c289914896838f1050610121870854eb36 + BUILD_IN_SOURCE ON + PATCH_COMMAND patch -p1 -i ${CMAKE_CURRENT_SOURCE_DIR}/pythia8-forward-decl.patch + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env CXX=${CMAKE_CXX_COMPILER} ${pythia_configure} + BUILD_COMMAND make -j${CMAKE_BUILD_PARALLEL_LEVEL} +) + +ExternalProject_Add(nlohmann_json + PREFIX nlohmann_json + URL https://github.com/nlohmann/json/archive/refs/tags/v${JSON_VERSION}.tar.gz + URL_HASH SHA1=1b0701dc7fdc068aad8ce68fc3e019a038232437 + CMAKE_ARGS + -DJSON_BuildTests=OFF + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/nlohmann_json/${JSON_VERSION} +) + +ExternalProject_Add(root + PREFIX root + DEPENDS nlohmann_json PythonExeExists tbb + URL https://root.cern/download/root_v${ROOT_VERSION}.source.tar.gz + URL_HASH ${ROOT_HASH} + LIST_SEPARATOR | + CMAKE_ARGS + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/root/${ROOT_VERSION} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/nlohmann_json/${JSON_VERSION}|${CMAKE_INSTALL_PREFIX}/tbb/${TBB_VERSION} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DPython_EXECUTABLE=${Python_EXECUTABLE} + -DPython3_EXECUTABLE=${Python_EXECUTABLE} + -Dfail-on-missing=ON + -Dgdml=ON + -Dx11=ON + -Dpyroot=ON + -Ddataframe=ON + -Dmysql=OFF + -Doracle=OFF + -Dpgsql=OFF + -Dsqlite=OFF + -Dpythia6=OFF + -Dpythia8=OFF + -Dfftw3=OFF + -Dbuiltin_tbb=OFF + -Dbuiltin_cfitsio=ON + -Dbuiltin_xxhash=ON + -Dbuiltin_afterimage=ON + -Dbuiltin_openssl=OFF + -Dbuiltin_ftgl=ON + -Dbuiltin_gsl=ON + -Dbuiltin_gl2ps=ON + -Dbuiltin_glew=ON + -Dbuiltin_pcre=ON + -Dgfal=OFF + -Ddavix=OFF + -Dbuiltin_vdt=ON + -Dxrootd=OFF + -Dtmva=OFF + BUILD_COMMAND ${CMAKE_COMMAND} -E env CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL} ${CMAKE_COMMAND} --build +) + + +ExternalProject_Add(podio + PREFIX podio + DEPENDS root PythonExeExists + URL https://github.com/AIDASoft/podio/archive/refs/tags/v${PODIO_VERSION}.tar.gz + URL_HASH SHA1=600b99000f0c7a6c25c04a8b32bebf70413c9f57 + LIST_SEPARATOR | + CMAKE_ARGS + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/podio/${PODIO_VERSION} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DPython_EXECUTABLE=${Python_EXECUTABLE} + -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/root/${ROOT_VERSION}|${CMAKE_INSTALL_PREFIX}/nlohmann_json/${JSON_VERSION} + -DBUILD_TESTING=OFF + -DUSE_EXTERNAL_CATCH2=OFF + BUILD_COMMAND ${CMAKE_COMMAND} -E env CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL} ${CMAKE_COMMAND} --build +) + +set(venv_dir ${CMAKE_CURRENT_BINARY_DIR}/venv) +set(venv_python_exe ${venv_dir}/bin/python) + +add_custom_command(OUTPUT ${venv_python_exe} + COMMAND ${Python_EXECUTABLE} -m venv ${venv_dir} && ${venv_python_exe} -m pip install --upgrade pip jinja2 pyyaml + COMMENT "Creating virtualenv for edm4hep build" + DEPENDS PythonExeExists) + +add_custom_target(PythonVenv DEPENDS ${venv_python_exe}) + +ExternalProject_Add(edm4hep + PREFIX edm4hep + DEPENDS podio PythonVenv + URL https://github.com/key4hep/EDM4hep/archive/refs/tags/v${EDM4HEP_VERSION}.tar.gz + URL_HASH SHA1=7781f6c85bd2e88480b699a3a554182fd8bb75bf + LIST_SEPARATOR | + CMAKE_ARGS + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/edm4hep/${EDM4HEP_VERSION} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/root/${ROOT_VERSION}|${CMAKE_INSTALL_PREFIX}/podio/${PODIO_VERSION}|${CMAKE_INSTALL_PREFIX}/nlohmann_json/${JSON_VERSION} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DPython_EXECUTABLE=${venv_python_exe} + -DBUILD_TESTING=OFF + -DUSE_EXTERNAL_CATCH2=OFF + BUILD_COMMAND ${CMAKE_COMMAND} -E env CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL} ${CMAKE_COMMAND} --build +) + +ExternalProject_Add(dd4hep + PREFIX dd4hep + DEPENDS edm4hep geant4 PythonExeExists boost + URL https://github.com/AIDASoft/DD4hep/archive/v${DD4HEP_VERSION}.tar.gz + URL_HASH SHA1=3e8a1d07a72689a24db04466b263094bbe16240f + LIST_SEPARATOR | + PATCH_COMMAND patch -p1 -i ${CMAKE_CURRENT_SOURCE_DIR}/dd4hep-python.patch + BUILD_COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/geant4/${GEANT4_VERSION}/lib CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL} ${CMAKE_COMMAND} --build + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/geant4/${GEANT4_VERSION}/lib ${CMAKE_COMMAND} -S -B + -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/dd4hep/${DD4HEP_VERSION} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/root/${ROOT_VERSION}|${CMAKE_INSTALL_PREFIX}/podio/${PODIO_VERSION}|${CMAKE_INSTALL_PREFIX}/edm4hep/${EDM4HEP_VERSION}|${CMAKE_INSTALL_PREFIX}/geant4/${GEANT4_VERSION}|${CMAKE_INSTALL_PREFIX}/nlohmann_json/${JSON_VERSION}|${CMAKE_INSTALL_PREFIX}/boost/${BOOST_VERSION} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DPython_EXECUTABLE=${Python_EXECUTABLE} + -DBUILD_TESTING=OFF + -DDD4HEP_BUILD_PACKAGES=DDG4|DDDetectors|DDRec|UtilityApps + -DDD4HEP_USE_GEANT4=ON + -DDD4HEP_USE_XERCESC=ON + -DDD4HEP_USE_EDM4HEP=ON +) + + diff --git a/dependencies.sh b/dependencies.sh new file mode 100755 index 0000000..178760e --- /dev/null +++ b/dependencies.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +# @TODO Only on macos + +function run() { + set -x + "$@" + { set +x; } 2> /dev/null +} + + +run brew update +run brew install ccache xerces-c +run brew reinstall cmake + +brew unlink r || true \ No newline at end of file diff --git a/pythia8-forward-decl.patch b/pythia8-forward-decl.patch new file mode 100644 index 0000000..447e73c --- /dev/null +++ b/pythia8-forward-decl.patch @@ -0,0 +1,37 @@ +diff --git a/src/FJcore.cc b/src/FJcore.cc +index c60108e2..afd32eee 100644 +--- a/src/FJcore.cc ++++ b/src/FJcore.cc +@@ -730,14 +730,10 @@ FJCORE_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh + class ClosestPair2D : public ClosestPair2DBase { + public: + ClosestPair2D(const std::vector & positions, +- const Coord2D & left_corner, const Coord2D & right_corner) { +- _initialize(positions, left_corner, right_corner, positions.size()); +- }; ++ const Coord2D & left_corner, const Coord2D & right_corner); + ClosestPair2D(const std::vector & positions, + const Coord2D & left_corner, const Coord2D & right_corner, +- const unsigned int max_size) { +- _initialize(positions, left_corner, right_corner, max_size); +- }; ++ const unsigned int max_size); + void closest_pair(unsigned int & ID1, unsigned int & ID2, + double & distance2) const; + void remove(unsigned int ID); +@@ -808,6 +804,15 @@ public: + return coord.distance2(other.coord); + }; + }; ++inline ClosestPair2D::ClosestPair2D(const std::vector & positions, ++ const Coord2D & left_corner, const Coord2D & right_corner) { ++ _initialize(positions, left_corner, right_corner, positions.size()); ++}; ++inline ClosestPair2D::ClosestPair2D(const std::vector & positions, ++ const Coord2D & left_corner, const Coord2D & right_corner, ++ const unsigned int max_size) { ++ _initialize(positions, left_corner, right_corner, max_size); ++}; + inline bool floor_ln2_less(unsigned x, unsigned y) { + if (x>y) return false; + return (x < (x^y)); // beware of operator precedence...