diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81ea1b2..17f54c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 . diff --git a/AUTHORS b/AUTHORS index ade4ac3..8fecedf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index fc62c53..21af648 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) @@ -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}) @@ -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() @@ -176,7 +185,7 @@ 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}) @@ -184,35 +193,57 @@ if(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" @@ -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) diff --git a/README.md b/README.md index dcf15f5..4b5c809 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c62f317 --- /dev/null +++ b/pyproject.toml @@ -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 = "j.r.maddison@ed.ac.uk"}, + {name = "Iakovos Panourgias", email = ""}, + {name = "Patrick E. Farrell", email = ""}, + {name = "Matteo Croci", email = ""}, + {name = "Jack Betteridge", email = "J.Betteridge@imperial.ac.uk"}, +] +maintainers = [ + {name = "Jack Betteridge", email = "J.Betteridge@imperial.ac.uk"}, +] +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" +