Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ option(MaCh3Tutorial_PROFILING_ENABLED "Will run with gperftools" OFF)
option(Use_External_MaCh3 "Use an externally installed MaCh3 instead of CPM" OFF)
option(MaCh3Tutorial_DEBUG_ENABLED "Use debug options" OFF)
option(MaCh3Tutorial_LOW_MEMORY_STRUCTS_ENABLED "Use floats" OFF)
option(PYTHON_ENABLED "Build python package" OFF)

# KS: Here we try to find tag matching tutorial version. If we can't find one then use develop
# This will allow to grab tutorial for tagged MaCh3 version without a need of manually changing version
Expand Down Expand Up @@ -113,6 +114,7 @@ if(NOT MaCh3_FOUND)
"Prob3ppLinear_ENABLED ON"
"NuFastLinear_ENABLED ON"
"CUDAProb3_ENABLED ON"
"MaCh3_PYTHON_ENABLED ${PYTHON_ENABLED}"
)
# MaCh3 sets up cmessage for us, so can't cmessage until we've set up MaCh3
cmessage(STATUS "Didn't find MaCh3, will checkout the ${MaCh3_Branch} branch from mach3-software/MaCh3")
Expand Down Expand Up @@ -146,6 +148,51 @@ add_subdirectory(Tutorial)
add_subdirectory(SplinesTutorial)
add_subdirectory(SamplesTutorial)

# MOVE THIS BLOCK HERE - BEFORE add_subdirectory(python)
# After MaCh3 is added/found, determine MaCh3_PREFIX
if(NOT DEFINED MaCh3_PREFIX OR MaCh3_PREFIX STREQUAL "")
# Try to detect if MaCh3 was fetched by CPM
if(EXISTS "${CMAKE_BINARY_DIR}/_deps/mach3-src")
set(MaCh3_PREFIX "${CMAKE_BINARY_DIR}/_deps/mach3-src")
cmessage(STATUS "Detected CPM-fetched MaCh3: ${MaCh3_PREFIX}")
# Try to get from MaCh3 package config
elseif(DEFINED MaCh3_DIR)
get_filename_component(MaCh3_PREFIX "${MaCh3_DIR}" DIRECTORY)
get_filename_component(MaCh3_PREFIX "${MaCh3_PREFIX}" DIRECTORY)
cmessage(STATUS "Detected installed MaCh3 from MaCh3_DIR: ${MaCh3_PREFIX}")
# Try to get from target properties
elseif(TARGET MaCh3::All)
get_target_property(MACH3_INCLUDE_DIRS MaCh3::All INTERFACE_INCLUDE_DIRECTORIES)
if(MACH3_INCLUDE_DIRS)
list(GET MACH3_INCLUDE_DIRS 0 FIRST_INCLUDE_DIR)
get_filename_component(MaCh3_PREFIX "${FIRST_INCLUDE_DIR}" DIRECTORY)
cmessage(STATUS "Detected MaCh3 from target include dirs: ${MaCh3_PREFIX}")
endif()
endif()

# Final validation
if(NOT DEFINED MaCh3_PREFIX OR MaCh3_PREFIX STREQUAL "")
cmessage(FATAL_ERROR "Could not determine MaCh3_PREFIX. Please set it manually with -DMaCh3_PREFIX=<path>")
endif()

if(NOT EXISTS "${MaCh3_PREFIX}")
cmessage(FATAL_ERROR "MaCh3_PREFIX does not exist: ${MaCh3_PREFIX}")
endif()

# Cache it for use in subdirectories
set(MaCh3_PREFIX "${MaCh3_PREFIX}" CACHE PATH "MaCh3 installation or source directory" FORCE)
cmessage(STATUS "Set MaCh3_PREFIX: ${MaCh3_PREFIX}")
endif()

# NOW add the python subdirectory - MaCh3_PREFIX is already set
if(PYTHON_ENABLED)
cmessage(STATUS "PYTHON IS ENABLED!!")
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
cmessage(STATUS "CMAKE_INSTALL_RPATH is ${CMAKE_INSTALL_RPATH}")
set(PYMACH3_PATH ${CMAKE_BINARY_DIR}/python/pyMaCh3)
add_subdirectory(python)
endif()

configure_file(cmake/Templates/setup.MaCh3Tutorial.sh.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.MaCh3Tutorial.sh" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.MaCh3Tutorial.sh" DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

Expand Down
4 changes: 2 additions & 2 deletions SamplesTutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(HEADERS
SampleHandlerTutorial.h
StructsTutorial.h
${CMAKE_CURRENT_SOURCE_DIR}/SampleHandlerTutorial.h
${CMAKE_CURRENT_SOURCE_DIR}/StructsTutorial.h
)

add_library(SamplesTutorial SHARED
Expand Down
2 changes: 1 addition & 1 deletion SplinesTutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(HEADERS BinnedSplinesTutorial.h
set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/BinnedSplinesTutorial.h
)

add_library(BinnedSplinesTutorial SHARED
Expand Down
25 changes: 25 additions & 0 deletions cmake/Templates/setup.MaCh3Tutorial.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,28 @@ else
fi

unset SETUPDIR

# Python bindings configuration
PYTHON_ENABLED=@MaCh3_PYTHON_ENABLED@

if [ "${PYTHON_ENABLED}" = "ON" ] || [ "${PYTHON_ENABLED}" = "TRUE" ] || [ "${PYTHON_ENABLED}" = "1" ]; then
# Python bindings are enabled
PYMACH3_PATH="@PYMACH3_PATH@"

if [ -d "${PYMACH3_PATH}" ]; then
if [ -z "${PYTHONPATH}" ]; then
export PYTHONPATH="${PYMACH3_PATH}"
else
# Prepend to existing PYTHONPATH, avoiding duplicates
if [[ ":${PYTHONPATH}:" != *":${PYMACH3_PATH}:"* ]]; then
export PYTHONPATH="${PYMACH3_PATH}:${PYTHONPATH}"
fi
fi
echo "✓ Added pyMaCh3 to PYTHONPATH: ${PYMACH3_PATH}"
else
echo "⚠️ Warning: pyMaCh3 directory not found at ${PYMACH3_PATH}"
echo " Python bindings may not have been built successfully"
fi
else
echo "Python bindings not enabled in this build"
fi
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = ["scikit-build-core", "pybind11"]
build-backend = "scikit_build_core.build"

[project]
name = "pyMaCh3_tutorial"
version = "0.0.1"
authors = [{ name = "The MaCh3 Collaboration" }]
dependencies = [
"numpy",
"matplotlib",
"pandas",
"pyMC",
]

[tool.scikit-build]
wheel.install-dir = "pyMaCh3_tutorial"

[tool.scikit-build.cmake]
args = ["-DPYTHON_ENABLED=ON"]
10 changes: 10 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

include(${MaCh3_PREFIX}/cmake/Modules/pyMaCh3.cmake)

setup_pyMaCh3(
INSTALL_DIR "NONE"
BINDING_FILES pyMaCh3.cpp
LINK_TARGETS
BinnedSplinesTutorial
SamplesTutorial
)
Loading