Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDBetteridge/pip install #10

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
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
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,28 @@ jobs:
run: |
cd build
make test

# NOTE: The pip-installed version of libsupermesh does not include any tests, so only check
# that it builds.
build_pip:
name: "Build libsupermesh with pip"
# The type of runner that the job will run on
runs-on: self-hosted
# The docker container to use.
container:
image: firedrakeproject/firedrake-env:latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install libsupermesh
shell: bash
run: |
python -m venv ../test_env
source ../test_env/bin/activate
export MPI_HOME=$MPICH_DIR
pip install .
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Contributors to libsupermesh:
* Dr. Patrick E. Farrell, Mathematical Institute, University of Oxford, UK,
and Center for Biomedical Computing, Simula Research Laboratory, Oslo, Norway
* Mr. Matteo Croci, Mathematical Institute, University of Oxford, UK
* Dr. Jack Betteridge, Department of Mathematics, Imperial College London, UK
100 changes: 68 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ set(CMAKE_Fortran_MODULE_DIRECTORY ${LIBSUPERMESH_BINARY_DIR}/include)
include_directories(${LIBSUPERMESH_SOURCE_DIR}/include)
include_directories(${LIBSUPERMESH_BINARY_DIR}/include)
include_directories(${LIBSUPERMESH_BINARY_DIR}/include_local)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
if("${SKBUILD}" STREQUAL 2)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
else()
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
endif()

find_package(MPI REQUIRED)
set(link_libraries ${MPI_Fortran_LIBRARIES})
Expand Down Expand Up @@ -127,7 +131,7 @@ message(STATUS "")

# Python is not required, but we want to add pip packages to spatialindex search path
set(Python_FIND_VIRTUALENV "FIRST")
find_package(Python)
find_package(Python COMPONENTS Interpreter Development.Module)
if(Python_FOUND)
message(STATUS "Python_VERSION_MAJOR " ${Python_VERSION_MAJOR})
message(STATUS "Python_VERSION_MINOR " ${Python_VERSION_MINOR})
Expand All @@ -152,6 +156,11 @@ if((NOT spatialindexlib) AND (Python_FOUND))
# Forces build to fail if we still cannot find spatialindex
unset(spatialindexlib)
find_library(spatialindexlib NAMES spatialindex REQUIRED)
else()
# Get the headers
execute_process(COMMAND ${Python_EXECUTABLE} -c "import rtree; print(rtree.finder.get_include(), end='')"
OUTPUT_VARIABLE spatialindexheaders
)
endif()
endif()

Expand All @@ -176,43 +185,65 @@ endif()
find_path(spatialindexheaders
NAMES spatialindex/SpatialIndex.h
REQUIRED
PATHS /usr/local/include /usr/include $ENV{VIRTUAL_ENV}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/rtree/include
PATHS /usr/local/include /usr/include $ENV{VIRTUAL_ENV}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/rtree/include spatialindexheaders
)
if(spatialindexheaders)
message(STATUS "Found libspatialindex headers: " ${spatialindexheaders})
include_directories(${spatialindexheaders})
endif()

file(GLOB source_files ${LIBSUPERMESH_SOURCE_DIR}/src/*.F90 ${LIBSUPERMESH_SOURCE_DIR}/src/*.c ${LIBSUPERMESH_SOURCE_DIR}/src/*.cpp)
add_library(supermesh ${source_files})
if("${SKBUILD}" STREQUAL 2)
python_add_library(supermesh MODULE WITH_SOABI ${source_files})
else()
add_library(supermesh ${source_files})
endif()

set(test_main ${LIBSUPERMESH_SOURCE_DIR}/src/tests/test_main.cpp)
file(GLOB unittest_files ${LIBSUPERMESH_SOURCE_DIR}/src/tests/*.F90)
set(unittests "")
foreach(unittest_file ${unittest_files})
get_filename_component(unittest ${unittest_file} NAME_WE)
add_executable(${unittest} ${unittest_file} ${test_main})
list(APPEND unittests ${unittest})
set_property(TARGET ${unittest} PROPERTY COMPILE_DEFINITIONS "TESTNAME=${unittest}")
if(unittest MATCHES parallel)
add_test(${unittest} ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ./${unittest} ${MPIEXEC_POSTFLAGS})
else()
add_test(${unittest} ${unittest})
endif()
set_tests_properties(${unittest} PROPERTIES FAIL_REGULAR_EXPRESSION "Fail:")
endforeach()
target_link_libraries(supermesh PUBLIC ${link_libraries})
set_target_properties(supermesh PROPERTIES INSTALL_RPATH "$ORIGIN/../Rtree.libs")
set_target_properties(supermesh PROPERTIES LINK_FLAGS "${MPI_Fortran_LINK_FLAGS}")
if("${SKBUILD}" STREQUAL 2)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)

set(test_link_libraries supermesh ${link_libraries} ${MPI_CXX_LIBRARIES})
target_link_libraries(supermesh ${link_libraries})
set_target_properties(supermesh PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
foreach(test ${unittests})
target_link_libraries(${test} ${test_link_libraries})
endforeach()
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

set_target_properties(supermesh PROPERTIES LINK_FLAGS "${MPI_Fortran_LINK_FLAGS}")
foreach(unittest ${unittests})
set_target_properties(${unittest} PROPERTIES LINK_FLAGS "${MPI_Fortran_LINK_FLAGS} ${MPI_CXX_LINK_FLAGS}")
endforeach()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()

# Only build tests if not built by scikit-build-core
if(NOT "${SKBUILD}" STREQUAL 2)
set(test_main ${LIBSUPERMESH_SOURCE_DIR}/src/tests/test_main.cpp)
file(GLOB unittest_files ${LIBSUPERMESH_SOURCE_DIR}/src/tests/*.F90)
set(unittests "")
foreach(unittest_file ${unittest_files})
get_filename_component(unittest ${unittest_file} NAME_WE)
add_executable(${unittest} ${unittest_file} ${test_main})
list(APPEND unittests ${unittest})
set_property(TARGET ${unittest} PROPERTY COMPILE_DEFINITIONS "TESTNAME=${unittest}")
if(unittest MATCHES parallel)
add_test(${unittest} ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ./${unittest} ${MPIEXEC_POSTFLAGS})
else()
add_test(${unittest} ${unittest})
endif()
set_tests_properties(${unittest} PROPERTIES FAIL_REGULAR_EXPRESSION "Fail:")
endforeach()

set(test_link_libraries supermesh ${link_libraries} ${MPI_CXX_LIBRARIES})
foreach(test ${unittests})
target_link_libraries(${test} ${test_link_libraries})
endforeach()

foreach(unittest ${unittests})
set_target_properties(${unittest} PROPERTIES LINK_FLAGS "${MPI_Fortran_LINK_FLAGS} ${MPI_CXX_LINK_FLAGS}")
endforeach()
endif()

configure_file (
"${LIBSUPERMESH_SOURCE_DIR}/config/libsupermesh.pc.in"
Expand Down Expand Up @@ -246,9 +277,14 @@ if(ENABLE_DOCS)
FORCE_PDF EXCLUDE_FROM_ALL BIBFILES doc/bibliography.bib)
endif()

install(TARGETS supermesh DESTINATION lib)
install(DIRECTORY ${LIBSUPERMESH_BINARY_DIR}/include DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${LIBSUPERMESH_BINARY_DIR}/config/libsupermesh.pc DESTINATION lib/pkgconfig)
if("${SKBUILD}" STREQUAL 2)
install(TARGETS supermesh DESTINATION supermesh)
install(DIRECTORY ${LIBSUPERMESH_BINARY_DIR}/include DESTINATION supermesh)
else()
install(TARGETS supermesh DESTINATION lib)
install(DIRECTORY ${LIBSUPERMESH_BINARY_DIR}/include DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${LIBSUPERMESH_BINARY_DIR}/config/libsupermesh.pc DESTINATION lib/pkgconfig)
endif()

file(GLOB data_files ${LIBSUPERMESH_SOURCE_DIR}/src/tests/data/*.ele
${LIBSUPERMESH_SOURCE_DIR}/src/tests/data/*.node)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ libsupermesh is available under the [GNU Lesser General Public License version 2
* Dr. Patrick E. Farrell, Mathematical Institute, University of Oxford, UK,
and Center for Biomedical Computing, Simula Research Laboratory, Oslo, Norway
* Mr. Matteo Croci, Mathematical Institute, University of Oxford, UK
* Dr. Jack Betteridge, Department of Mathematics, Imperial College London, UK
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[project]
name = "libsupermesh"
version = "1.0.1"
description = "A parallel supermeshing library"
readme = "README.md"
authors = [
{name = "James R. Maddison", email = "[email protected]"},
{name = "Iakovos Panourgias", email = ""},
{name = "Patrick E. Farrell", email = ""},
{name = "Matteo Croci", email = ""},
{name = "Jack Betteridge", email = "[email protected]"},
]
maintainers = [
{name = "Jack Betteridge", email = "[email protected]"},
]
dependencies = [
"rtree>=1.2",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
"Programming Language :: Python",
"Operating System :: OS Independent"
]

[project.urls]
Repository = "https://github.com/firedrakeproject/libsupermesh"

[build-system]
requires = ["scikit-build-core", "rtree>=1.2"]
build-backend = "scikit_build_core.build"

Loading