Skip to content

Commit

Permalink
Export python bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
asadchev committed Apr 19, 2022
1 parent a394668 commit 557efa6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ then either choose path a or b:
$ make export
this produces a tarball with a Libint library that can be unpacked, configured, and compiled elsewhere.

Python:
$ cmake -DPYTHON_EXECUTABLE=`which python3` -DLIBINT2_PYTHON=ON .
$ cd python && make -j2 libint2-python
1 change: 1 addition & 0 deletions export/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ exportdir::
echo "set(LIBINT2_LIBRARY_CXX_SRC" > $(TOPDIR)/$(EXPORTDIR)/srclist.cmake
ls $(TOPDIR)/$(EXPORTDIR)/src >> $(TOPDIR)/$(EXPORTDIR)/srclist.cmake
echo ")" >> $(TOPDIR)/$(EXPORTDIR)/srclist.cmake
cp -rap $(SRCTOPDIR)/python $(TOPDIR)/$(EXPORTDIR)/
19 changes: 18 additions & 1 deletion export/cmake/CMakeLists.txt.export
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ redefaultable_option(REQUIRE_CXX_API "C++11 Libint interface" ON)
redefaultable_option(ENABLE_FORTRAN "Fortran03+ Libint interface" OFF)
redefaultable_option(ENABLE_MPFR "Use GNU MPFR library for high-precision testing (EXPERTS ONLY)" OFF)
redefaultable_option(LIBINT2_BUILD_SHARED_AND_STATIC_LIBS "Build in one shot static and shared library variants. Uses -fPIC." OFF)
redefaultable_option(LIBINT2_PYTHON "Python bindings" OFF)
if (NOT LIBINT2_REALTYPE)
set(LIBINT2_REALTYPE double)
endif()
Expand Down Expand Up @@ -187,7 +188,7 @@ if (NOT CMAKE_CXX_EXTENSIONS)
set_target_properties(libint2_obj PROPERTIES CXX_EXTENSIONS OFF)
endif(NOT CMAKE_CXX_EXTENSIONS)

if(BUILD_SHARED_LIBS OR LIBINT2_BUILD_SHARED_AND_STATIC_LIBS)
if(BUILD_SHARED_LIBS OR LIBINT2_BUILD_SHARED_AND_STATIC_LIBS OR LIBINT2_PYTHON)
set_target_properties(libint2_obj PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

Expand Down Expand Up @@ -508,3 +509,19 @@ feature_summary(WHAT ALL
# appendix: misc details
###############################################################################
SET(CMAKE_COLOR_MAKEFILE ON)

if (LIBINT2_PYTHON)
add_subdirectory(python)
target_compile_definitions(
libint2-python
PRIVATE
__COMPILING_LIBINT2
)
target_include_directories(
libint2-python
PRIVATE
${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}/include
${EIGEN3_INCLUDE_DIR}
)
endif()
15 changes: 10 additions & 5 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ set(CMAKE_CXX_STANDARD 17)
add_compile_options(-Wall)

if (TARGET libint2_obj)
set(python_libint2_target libint2_obj)
set(libint2_python_target libint2_obj)
else()
find_package(Libint2 REQUIRED)
set(python_libint2_target Libint2::cxx)
set(libint2_python_target Libint2::cxx)
endif()

include(FetchContent)
Expand All @@ -23,7 +23,12 @@ FetchContent_MakeAvailable(pybind11)

#find_package(Eigen3 3.3 REQUIRED)

pybind11_add_module(libint2-python MODULE src/libint2/_libint2.cc src/libint2/engine.cc)
pybind11_add_module(
libint2-python MODULE
EXCLUDE_FROM_ALL
src/libint2/_libint2.cc
src/libint2/engine.cc
)

set_target_properties(
libint2-python
Expand All @@ -32,7 +37,7 @@ set_target_properties(
OUTPUT_NAME _libint2
)

target_link_libraries(libint2-python PUBLIC ${python_libint2_target})
target_link_libraries(libint2-python PUBLIC ${libint2_python_target})

# if (Eigen3::Eigen)
# target_link_libraries(libint2-python INTERFACE Eigen3::Eigen)
Expand All @@ -48,7 +53,7 @@ enable_testing()

# add the executable
add_test(
NAME test_libint
NAME libint2-python
COMMAND ${PYTHON_EXECUTABLE} -m setup test
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
Expand Down
1 change: 0 additions & 1 deletion python/src/libint2/_libint2.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <libint2.hpp>
#include <libint2/libint2_params.h>
#include <libint2/chemistry/sto3g_atomic_density.h>
#include <Eigen/Dense>
#include <tuple>
Expand Down

0 comments on commit 557efa6

Please sign in to comment.