Skip to content

Commit 003d302

Browse files
Fetch and build ffbidx with cmake
1 parent 1f5d726 commit 003d302

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

CMakeLists.txt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ include(AlwaysColourCompilation)
2222
include_directories(include)
2323

2424
# Find Python
25-
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
25+
find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
2626
include_directories(${Python3_INCLUDE_DIRS})
2727

28+
# Make sure we can install ffbidx into correct location.
29+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
30+
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install path" FORCE)
31+
endif()
32+
2833
# Dependency fetching
2934
set(FETCHCONTENT_QUIET OFF)
3035
include(FetchContent)
@@ -48,6 +53,21 @@ FetchContent_Declare(
4853
)
4954
FetchContent_MakeAvailable(argparse)
5055

56+
# Required for Python module build of ffbidx
57+
set(BUILD_FAST_INDEXER ON CACHE BOOL "" FORCE)
58+
set(PYTHON_MODULE ON CACHE BOOL "" FORCE)
59+
set(PYTHON_MODULE_RPATH ON CACHE BOOL "" FORCE)
60+
61+
# Override install path for ffbidx to site-packages
62+
set(PYTHON_MODULE_PATH ${Python3_SITEARCH} CACHE PATH "Python install path" FORCE)
63+
64+
FetchContent_Declare(
65+
ffbidx
66+
GIT_REPOSITORY https://github.com/paulscherrerinstitute/fast-feedback-indexer.git
67+
GIT_TAG main
68+
)
69+
FetchContent_MakeAvailable(ffbidx)
70+
5171
find_package(fmt REQUIRED)
5272
find_package(spdlog REQUIRED)
5373

@@ -128,4 +148,13 @@ add_subdirectory(h5read)
128148
add_subdirectory(baseline)
129149
add_subdirectory(spotfinder)
130150

151+
# define a ssx_index 'executable' that actually just runs the python code (for style consistency)
131152
configure_file(${CMAKE_SOURCE_DIR}/scripts/ssx_index ${CMAKE_BINARY_DIR}/bin/ssx_index COPYONLY)
153+
154+
# run 'pip install .' to install the c++ extension for ssx_index
155+
install(CODE "
156+
execute_process(
157+
COMMAND ${Python3_EXECUTABLE} -m pip install .
158+
WORKING_DIRECTORY \"${CMAKE_SOURCE_DIR}\"
159+
)
160+
")

build.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ build_directory() {
161161
make -j"$JOBS"
162162
fi
163163
)
164+
165+
# Install
166+
print_status "Installing $description..."
167+
(
168+
cd "$build_dir"
169+
if [[ "$BUILD_CMD" == "ninja" ]]; then
170+
ninja "install"
171+
else
172+
make "install" -j"$JOBS"
173+
fi
174+
)
164175

165176
print_success "Successfully built $description"
166177
}

tests/test_gpu_ssx_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def test_gpu_ssx_index(dials_data, tmp_path):
157157
cwd=tmp_path,
158158
)
159159
assert not proc.stderr
160-
assert tmp_path / "indexed.refl"
161-
assert tmp_path / "indexed_crystals.json"
160+
assert (tmp_path / "indexed.refl").exists()
161+
assert (tmp_path / "indexed_crystals.json").exists()
162162
with open(tmp_path / "indexed_crystals.json", "r") as f:
163163
crystals = json.load(f)
164164
for i, (crystal, expected) in enumerate(

0 commit comments

Comments
 (0)