Skip to content

Commit

Permalink
Pip installer (#750)
Browse files Browse the repository at this point in the history
* added pip-installer for ASGarD
  • Loading branch information
mkstoyanov authored Nov 23, 2024
1 parent 15edef9 commit ff95111
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 107 deletions.
118 changes: 72 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@ function (register_project name dir url default_tag)
FetchContent_MakeAvailable(${name})
endfunction ()

# Catch two testing framework.
# The default behavior is to build catch together with ASGarD,
# but if Catch2_ROOT is explicitly provided then search
# for an existing installation.
if (Catch2_ROOT)
find_package(Catch2 REQUIRED)
else()
register_project (Catch2
CATCH2
https://github.com/catchorg/Catch2.git
v3.3.0
)
endif()

#Mark CATCH variables as advanced.
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
string(FIND "${_variableName}" "CATCH_" out)
if("${out}" EQUAL 0)
mark_as_advanced(${_variableName})
endif()
endforeach()

###############################################################################
## Set up the compiler and general global build options
Expand Down Expand Up @@ -82,6 +60,14 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_CURRENT_BINARY_DIR}/asgard_install")
endif()

# set the rpath to the final path with the installation
set(__asgard_install_prefix ${CMAKE_INSTALL_PREFIX})
if (SKBUILD)
set(__asgard_install_prefix ${ASGARD_python_pip_path})
endif()

list(APPEND CMAKE_INSTALL_RPATH "${__asgard_install_prefix}/lib")
list(APPEND CMAKE_BUILD_RPATH "${__asgard_install_prefix}/lib")

# set up possible commandline input variable defaults (override with -D)
include(CMakeDependentOption)
Expand All @@ -96,7 +82,11 @@ option (ASGARD_USE_MPI "Optional distributed computing support for asgard" OFF)
option (ASGARD_USE_PYTHON "Optional Python tool for post-processing, plotting and quick prototyping" OFF)
option (ASGARD_USE_HIGHFIVE "Use the HighFive HDF5 header library for I/O" OFF)

option (ASGARD_BUILD_OPENBLAS "Download and build our own OpenBLAS" OFF)
if ($ENV{ASGARD_BUILD_OPENBLAS})
option (ASGARD_BUILD_OPENBLAS "Download and build our own OpenBLAS" ON)
else()
option (ASGARD_BUILD_OPENBLAS "Download and build our own OpenBLAS" OFF)
endif()
option (ASGARD_BUILD_HDF5 "Download and build our own HDF5/HighFive" OFF)
option (ASGARD_HIGHFIVE_PATH "Optional location of existing HighFive library" "")
option (ASGARD_HDF5_PATH "Optional location of lib/ containing HDF5" "")
Expand Down Expand Up @@ -143,6 +133,30 @@ endif()
## Pull in external support as needed
###############################################################################

if (ASGARD_BUILD_TESTS)
# Catch2 for testing, if Catch2_ROOT is provided then look for the existing installation,
# if Catch2_ROOT is not given, download and build together with ASGarD
if (Catch2_ROOT OR DEFINED ENV{Catch2_ROOT})
find_package(Catch2 REQUIRED)
else()
register_project (Catch2
CATCH2
https://github.com/catchorg/Catch2.git
v3.3.0
)
endif()
endif()

#Mark CATCH variables as advanced.
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
string(FIND "${_variableName}" "CATCH_" out)
if("${out}" EQUAL 0)
mark_as_advanced(${_variableName})
endif()
endforeach()


list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/contrib)
find_package (LINALG REQUIRED)

Expand Down Expand Up @@ -183,6 +197,20 @@ if (ASGARD_USE_PYTHON)
endif()
find_package(Python 3.0 REQUIRED COMPONENTS Interpreter)

set(__asgard_pysubpath "lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")
if (SKBUILD)
# scikit build compiles and install in one place, then moves the files to a different location
if (ASGARD_osx_framework)
set(__asgard_pysubpath "lib/python/site-packages")
endif()
set(__asgard_final_path "${ASGARD_python_pip_path}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}asgard${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(_asgard_python_path "${CMAKE_INSTALL_PREFIX}/${__asgard_pysubpath}")
else()
# regular build, all those folders are the same
set(__asgard_final_path "${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}asgard${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(_asgard_python_path "${CMAKE_INSTALL_PREFIX}/${__asgard_pysubpath}")
endif()

# CMake accepts YES, ON or 1 in either upper or lower case
# some configured scripts use only ON as a valid value
set(ASGARD_USE_PYTHON ON)
Expand Down Expand Up @@ -213,9 +241,7 @@ if (ASGARD_USE_PYTHON)
add_custom_target(asgard_python_testing ALL DEPENDS "${_pyasgard_buildstage}")

# install the module without the testing files
set(__pyasgard_libasgard_path__ "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}asgard${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(_asgard_python_path "${CMAKE_INSTALL_PREFIX}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")

set(__pyasgard_libasgard_path__ "${__asgard_final_path}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/python/asgard_config.py" "${CMAKE_CURRENT_BINARY_DIR}/pyinstall/asgard_config.py")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pyinstall/asgard_config.py" DESTINATION "${_asgard_python_path}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/asgard.py" DESTINATION "${_asgard_python_path}")
Expand Down Expand Up @@ -250,14 +276,16 @@ if (ASGARD_USE_PYTHON)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pyinstall/asgard_matlab.py" DESTINATION share/asgard/matlab)
endif()

foreach(_asg_testinput test_input1.txt test_input2.txt)
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_asg_testinput}"
COMMAND "${CMAKE_COMMAND}"
ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/testing/${_asg_testinput} ${CMAKE_CURRENT_BINARY_DIR}/${_asg_testinput}
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/testing/${_asg_testinput}"
COMMENT "Copying ${CMAKE_CURRENT_SOURCE_DIR}/testing/${_asg_testinput}")
list(APPEND _asg_testinputfiles "${CMAKE_CURRENT_BINARY_DIR}/${_asg_testinput}")
endforeach()
if (ASGARD_BUILD_TESTS)
foreach(_asg_testinput test_input1.txt test_input2.txt)
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_asg_testinput}"
COMMAND "${CMAKE_COMMAND}"
ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/testing/${_asg_testinput} ${CMAKE_CURRENT_BINARY_DIR}/${_asg_testinput}
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/testing/${_asg_testinput}"
COMMENT "Copying ${CMAKE_CURRENT_SOURCE_DIR}/testing/${_asg_testinput}")
list(APPEND _asg_testinputfiles "${CMAKE_CURRENT_BINARY_DIR}/${_asg_testinput}")
endforeach()
endif()
foreach(_asg_testinput inputs_1d_1.txt inputs_1d_2.txt)
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_asg_testinput}"
COMMAND "${CMAKE_COMMAND}"
Expand Down Expand Up @@ -632,15 +660,7 @@ endforeach()
#-------------------------------------------------------------------------------
include(CMakePackageConfigHelpers)

target_include_directories(libasgard PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)

set_target_properties(asgard_exe PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/")
if (ASGARD_BUILD_HDF5 OR ASGARD_BUILD_OPENBLAS)
set_target_properties(libasgard PROPERTIES BUILD_RPATH "${CMAKE_INSTALL_PREFIX}/lib/")
set_target_properties(libasgard PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/")
set_target_properties(asgard_exe PROPERTIES BUILD_RPATH "${CMAKE_INSTALL_PREFIX}/lib/")
endif()

target_include_directories(libasgard PUBLIC $<INSTALL_INTERFACE:${__asgard_install_prefix}/include>)

foreach (_asg_target asgard_highfive asgard_hdf5 libasgard asgard_exe)
if (TARGET ${_asg_target})
Expand Down Expand Up @@ -681,9 +701,15 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testing/CMakeLists.txt"
install(EXPORT "asgard-export" DESTINATION "lib/${CMAKE_PROJECT_NAME}" FILE "${CMAKE_PROJECT_NAME}-targets.cmake")

if (TARGET asgard_highfive)
# must install the highfive dependency
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/contrib/highfive/include/"
DESTINATION include)
# must install the highfive dependency
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/contrib/highfive/include/"
DESTINATION include)
set(__asgard_custom_hdf5 ON)
if (TARGET hdf5::hdf5)
set(__asgard_find_hdf5 ON)
else()
set(__asgard_find_hdf5 OFF)
endif()
endif()

configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/asgard-config.cmake"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# ASGarD - Adaptive Sparse Grid Discretization

To cite the ASGarD code in your work, please use:
* [![DOI](https://joss.theoj.org/papers/10.21105/joss.06766/status.svg)](https://doi.org/10.21105/joss.06766)
* [doi:10.11578/dc.20201125.5](https://www.osti.gov/doecode/biblio/48752)

Papers using ASGarD:
* [Sparse-grid Discontinuous Galerkin Methods for the Vlasov-Poisson-Lenard-Bernstein Model](https://arxiv.org/abs/2402.06493)

The ASGarD project has the goal of building a solver specifically targeting
high-dimensional PDEs where the "curse-of-dimensionality" has previously
precluded useful continuum / Eularian (grid or mesh based as opposed to
Expand All @@ -15,6 +8,13 @@ Discontinuous-Galerkin finite-element solver build atop an adaptive hierarchical
sparse-grid (note this is different from the "combination technique" when applied
to sparse-grids).

To cite the ASGarD code in your work, please use:
* [![DOI](https://joss.theoj.org/papers/10.21105/joss.06766/status.svg)](https://doi.org/10.21105/joss.06766)
* [doi:10.11578/dc.20201125.5](https://www.osti.gov/doecode/biblio/48752)

Papers using ASGarD:
* [Sparse-grid Discontinuous Galerkin Methods for the Vlasov-Poisson-Lenard-Bernstein Model](https://arxiv.org/abs/2402.06493)

[Documentation of usage: https://project-asgard.github.io/asgard/](https://project-asgard.github.io/asgard/)

The [developer documentation](https://github.com/project-asgard/ASGarD/wiki/developing)
Expand Down
7 changes: 5 additions & 2 deletions asgard-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ endif()

@PACKAGE_INIT@

include("@CMAKE_INSTALL_PREFIX@/lib/@CMAKE_PROJECT_NAME@/@[email protected]")
include("@__asgard_install_prefix@/lib/@CMAKE_PROJECT_NAME@/@[email protected]")

if ("@ASGARD_USE_MPI@" AND NOT TARGET MPI::MPI_CXX)
if (NOT MPI_HOME AND NOT DEFINED ENV{MPI_HOME})
Expand Down Expand Up @@ -41,10 +41,13 @@ target_link_libraries (asgard::LINALG

if (@ASGARD_USE_HIGHFIVE@)
enable_language (C)
if (@__asgard_find_hdf5@)
find_package (HDF5 REQUIRED)
endif()
endif()

add_executable(asgard::exe IMPORTED)
set_property(TARGET asgard::exe PROPERTY IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/bin/asgard${CMAKE_EXECUTABLE_SUFFIX_CXX}")
set_property(TARGET asgard::exe PROPERTY IMPORTED_LOCATION "@__asgard_install_prefix@/bin/asgard${CMAKE_EXECUTABLE_SUFFIX_CXX}")

add_library(asgard::asgard INTERFACE IMPORTED GLOBAL)
target_link_libraries(asgard::asgard INTERFACE libasgard)
Expand Down
2 changes: 1 addition & 1 deletion contrib/FindLINALG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include (FindPackageHandleStandardArgs)

# Check for platform provided BLAS and LAPACK libaries. If these were not found
# then build the openblas library.
if (NOT ${ASGARD_BUILD_OPENBLAS})
if (NOT ASGARD_BUILD_OPENBLAS)
find_package (BLAS)
find_package (LAPACK)

Expand Down
65 changes: 17 additions & 48 deletions contrib/asgard_io.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,23 @@
###############################################################################

###############################################################################
## HDF5 (libhdf5) (https://portal.hdfgroup.org/display/support)
## BlueBrain/HighFive (https://github.com/BlueBrain/HighFive)
#
# right now, we only access this through the HighFive wrapper lib
# header-only library for a c++ interface into libhdf5
# included in the asgard repo at contrib/HighFive
###############################################################################
function (get_hdf5)
add_library (asgard_hdf5 INTERFACE)

if (NOT ASGARD_BUILD_HDF5)
# search for hdf5 under user-supplied path(s)
if (ASGARD_HDF5_PATH)
find_library (hdf5_search hdf5
PATHS ${ASGARD_HDF5_PATH} PATH_SUFFIXES lib lib64 NO_DEFAULT_PATH)
set (hdf5_include ${ASGARD_HDF5_PATH}/include)
set (hdf5_lib "-L${ASGARD_HDF5_PATH}/lib -Wl,-rpath,${ASGARD_HDF5_PATH}/lib/ -lhdf5")
message (STATUS "using external hdf5 found at ${ASGARD_HDF5_PATH}")
set (HDF5_FOUND TRUE)
endif ()

# search for hdf5 in some typical locations
if (NOT HDF5_FOUND)
find_package (HDF5 QUIET)
set (hdf5_include ${HDF5_INCLUDE_DIRS})
set (hdf5_lib ${HDF5_LIBRARIES})
message (STATUS "using external hdf5 found at ${HDF5_LIBRARIES}")
endif ()
if (ASGARD_USE_HIGHFIVE)

# never build HDF5 unless ASGARD_BUILD_HDF5 is explicitly ON
if (NOT HDF5_FOUND)
message(FATAL_ERROR "could not find HDF5, plese provide -DASGARD_HDF5_PATH")
endif()
# -- first we need HDF5
enable_language (C)

target_include_directories (asgard_hdf5 INTERFACE ${hdf5_include})
target_link_libraries (asgard_hdf5 INTERFACE ${hdf5_lib})
endif ()
add_library (asgard_hdf5 INTERFACE)

# if used asked us to build HDF5
if (ASGARD_BUILD_HDF5)
message (STATUS "building hdf5 from source")

set(__asgard_h5_install_prefix "${CMAKE_INSTALL_PREFIX}")
include (ExternalProject)
if (DEFINED CMAKE_APPLE_SILICON_PROCESSOR AND CMAKE_APPLE_SILICON_PROCESSOR STREQUAL "arm64")
# Get HDF5 to build on Apple silicon
Expand All @@ -51,7 +29,7 @@ function (get_hdf5)
URL https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.11/src/hdf5-1.10.11.tar.bz2
DOWNLOAD_NO_PROGRESS 1
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/contrib/hdf5/src/hdf5_external/autogen.sh
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/contrib/hdf5/src/hdf5_external/configure --prefix=${CMAKE_INSTALL_PREFIX}
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/contrib/hdf5/src/hdf5_external/configure --prefix=${__asgard_h5_install_prefix}
BUILD_COMMAND make
BUILD_IN_SOURCE 1
INSTALL_COMMAND make install
Expand All @@ -62,37 +40,28 @@ function (get_hdf5)
PREFIX "contrib/hdf5"
URL https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.11/src/hdf5-1.10.11.tar.bz2
DOWNLOAD_NO_PROGRESS 1
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/contrib/hdf5/src/hdf5_external/configure --prefix=${CMAKE_INSTALL_PREFIX}
CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/contrib/hdf5/src/hdf5_external/configure --prefix=${__asgard_h5_install_prefix}
BUILD_COMMAND make
BUILD_IN_SOURCE 1
INSTALL_COMMAND make install
)
endif()

# either it was already here, or we just built it here
set (hdf5_include ${CMAKE_INSTALL_PREFIX}/include)
set (hdf5_lib "-L${CMAKE_INSTALL_PREFIX}/lib -Wl,-rpath,${hdf5_contrib_path}/lib/ -lhdf5")
set (hdf5_include ${__asgard_h5_install_prefix}/include)
set (hdf5_lib "${__asgard_h5_install_prefix}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}hdf5${CMAKE_SHARED_LIBRARY_SUFFIX}")

target_include_directories (asgard_hdf5 INTERFACE $<BUILD_INTERFACE:${hdf5_include}>)
target_link_libraries (asgard_hdf5 INTERFACE $<BUILD_INTERFACE:${hdf5_lib}>)
endif ()

endfunction()

###############################################################################
## BlueBrain/HighFive (https://github.com/BlueBrain/HighFive)
#
# header-only library for a c++ interface into libhdf5
# included in the asgard repo at contrib/HighFive
###############################################################################
if (ASGARD_USE_HIGHFIVE)
else() # not building HDF5, using the find-package

# first we need HDF5
enable_language (C)
get_hdf5()
find_package (HDF5 REQUIRED)
target_link_libraries (asgard_hdf5 INTERFACE hdf5::hdf5)

# now HighFive itself
endif ()

# -- second, we get HighFive itself
set (highfive_PATH ${CMAKE_SOURCE_DIR}/contrib/highfive)
if (NOT EXISTS ${highfive_PATH}/include/highfive/H5Easy.hpp)
execute_process (COMMAND rm -rf ${highfive_PATH})
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.19)
project(asgard_examples VERSION @asgard_VERSION_MAJOR@.@asgard_VERSION_MINOR@.@asgard_VERSION_PATCH@ LANGUAGES CXX)

find_package(asgard @asgard_VERSION_MAJOR@.@asgard_VERSION_MINOR@.@asgard_VERSION_PATCH@ REQUIRED
PATHS "@CMAKE_INSTALL_PREFIX@")
PATHS "@__asgard_install_prefix@")

add_executable(continuity_2d continuity_2d.cpp)
add_executable(inputs_1d inputs_1d.cpp)
Expand Down
22 changes: 22 additions & 0 deletions python/pipinstall/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include setup.py
include pyproject.toml
include CMakeLists.txt
include LICENSE.txt
include *.md
include asgard-config.cmake
include asgard-env.sh

include contrib/asgard_io.cmake
include contrib/contrib.cmake
include contrib/FindLINALG.cmake
include contrib/GetGitRevisionDescription.cmake
include contrib/GetGitRevisionDescription.cmake.in

recursive-include doxygen *
recursive-include examples *
recursive-include infiles *
recursive-include python *
recursive-include src *

include testing/TestingCMakeLists.txt
include testing/test_post_install.sh
Loading

0 comments on commit ff95111

Please sign in to comment.