mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-10-21 00:56:18 +02:00
python/src/module.cpp was one translation unit instantiating every cluster size and value type; it compiled for 38 s and was the critical path of the whole build. The bindings now live in bind_io.cpp (files, geometry, pixel maps, calibration, test probes), bind_hist.cpp, bind_pedestal.cpp, bind_fit.cpp, bind_eta.cpp and one bind_cluster_NxN.cpp per cluster size, with the entry points declared in bindings.hpp and called from module.cpp in the same order as before. The DEFINE_CLUSTER_BINDINGS macros moved to bind_cluster_common.hpp. Headers that several units include needed small fixes: allocate_image_data and define_corner_enum are inline, the file-reader entry point is not, and np_helper.hpp, bind_Defs.hpp, bind_FastPedestal.hpp, bind_PedestalTrackingPixelHistogram.hpp and bind_ClusterFileSink.hpp now include what they use, in particular pybind11/stl/filesystem.h for the std::filesystem::path arguments they bind (previously supplied by include order in module.cpp). The module's exported names, types and docstrings are identical (verified by dumping all 1948 of them), both test suites pass, and a clean Release build with tests drops from 68 s to 42 s; the longest unit now takes 13 s and the remaining 19 s is pybind11's LTO link.
96 lines
2.6 KiB
CMake
96 lines
2.6 KiB
CMake
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
find_package(
|
|
Python 3.10
|
|
COMPONENTS Interpreter Development.Module
|
|
REQUIRED)
|
|
set(PYBIND11_FINDPYTHON ON) # Needed for RH8
|
|
|
|
# Download or find pybind11 depending on configuration
|
|
if(AARE_FETCH_PYBIND11)
|
|
FetchContent_Declare(
|
|
pybind11
|
|
GIT_REPOSITORY https://github.com/pybind/pybind11
|
|
GIT_TAG v3.0.3
|
|
GIT_SHALLOW TRUE)
|
|
FetchContent_MakeAvailable(pybind11)
|
|
else()
|
|
find_package(pybind11 3.0.3 REQUIRED)
|
|
endif()
|
|
|
|
# The compiled python extension: one translation unit per binding area so they
|
|
# compile in parallel; see src/module.cpp for the registration order.
|
|
pybind11_add_module(
|
|
_aare # name of the module
|
|
src/module.cpp
|
|
src/bind_io.cpp
|
|
src/bind_hist.cpp
|
|
src/bind_pedestal.cpp
|
|
src/bind_fit.cpp
|
|
src/bind_eta.cpp
|
|
src/bind_cluster_2x2.cpp
|
|
src/bind_cluster_3x3.cpp
|
|
src/bind_cluster_5x5.cpp
|
|
src/bind_cluster_7x7.cpp
|
|
src/bind_cluster_9x9.cpp)
|
|
|
|
set_target_properties(_aare PROPERTIES LIBRARY_OUTPUT_DIRECTORY
|
|
${CMAKE_BINARY_DIR})
|
|
target_link_libraries(_aare PRIVATE aare_core aare_compiler_flags)
|
|
|
|
target_include_directories(
|
|
_aare SYSTEM
|
|
PRIVATE $<TARGET_PROPERTY:aare::Minuit2,INTERFACE_INCLUDE_DIRECTORIES>)
|
|
|
|
# List of python files to be copied to the build directory
|
|
set(PYTHON_FILES
|
|
aare/__init__.py
|
|
aare/_version.py
|
|
aare/CtbRawFile.py
|
|
aare/ClusterFinder.py
|
|
aare/ClusterVector.py
|
|
aare/Cluster.py
|
|
aare/FastPedestal.py
|
|
aare/Pedestal.py
|
|
aare/calibration.py
|
|
aare/factory.py
|
|
aare/experimental.py
|
|
aare/RawFile.py
|
|
aare/transform.py
|
|
aare/ScanParameters.py
|
|
aare/utils.py)
|
|
|
|
# Copy the python files to the build directory
|
|
foreach(FILE ${PYTHON_FILES})
|
|
configure_file(${FILE} ${CMAKE_BINARY_DIR}/${FILE})
|
|
endforeach(FILE ${PYTHON_FILES})
|
|
|
|
set_target_properties(_aare PROPERTIES LIBRARY_OUTPUT_DIRECTORY
|
|
${CMAKE_BINARY_DIR}/aare)
|
|
|
|
set(PYTHON_EXAMPLES examples/play.py examples/fits.py)
|
|
|
|
# Copy the python examples to the build directory
|
|
foreach(FILE ${PYTHON_EXAMPLES})
|
|
configure_file(${FILE} ${CMAKE_BINARY_DIR}/${FILE})
|
|
message(STATUS "Copying ${FILE} to ${CMAKE_BINARY_DIR}/${FILE}")
|
|
endforeach(FILE ${PYTHON_EXAMPLES})
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../VERSION
|
|
${CMAKE_BINARY_DIR}/aare/VERSION)
|
|
if(AARE_INSTALL_PYTHONEXT)
|
|
install(
|
|
TARGETS _aare
|
|
EXPORT "${TARGETS_EXPORT_NAME}"
|
|
LIBRARY DESTINATION aare COMPONENT python)
|
|
|
|
install(
|
|
FILES ${PYTHON_FILES}
|
|
DESTINATION aare
|
|
COMPONENT python)
|
|
install(
|
|
FILES ../VERSION
|
|
DESTINATION aare
|
|
COMPONENT python)
|
|
endif()
|