install LAMMPS python module with either install-python or install target if prerequisites are given

This commit is contained in:
Axel Kohlmeyer
2019-03-26 16:00:48 -04:00
parent 0edb82eb5e
commit 07a6749ddc

View File

@ -1475,23 +1475,47 @@ install(
) )
############################################################################### ###############################################################################
# Install LAMMPS module into site-packages folder # Install LAMMPS lib and python module into site-packages folder with
# Only available, if a shared library is built # "install-python" target. Behaves exactly like "make install-python" for
# conventional build. Only available, if a shared library is built.
# This is primarily for people that only want to use the Python wrapper.
############################################################################### ###############################################################################
if(BUILD_LIB AND BUILD_SHARED_LIBS) if(BUILD_LIB AND BUILD_SHARED_LIBS)
find_package(PythonInterp) find_package(PythonInterp)
add_custom_target( if (${PYTHONINTERP_FOUND})
install-python add_custom_target(
${PYTHON_EXECUTABLE} install.py -v ${LAMMPS_SOURCE_DIR}/version.h install-python
-m ${CMAKE_CURRENT_SOURCE_DIR}/../python/lammps.py ${PYTHON_EXECUTABLE} install.py -v ${LAMMPS_SOURCE_DIR}/version.h
-l ${CMAKE_BINARY_DIR}/liblammps${CMAKE_SHARED_LIBRARY_SUFFIX} -m ${CMAKE_CURRENT_SOURCE_DIR}/../python/lammps.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../python -l ${CMAKE_BINARY_DIR}/liblammps${CMAKE_SHARED_LIBRARY_SUFFIX}
COMMENT "Installing LAMMPS Python module" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../python
) COMMENT "Installing LAMMPS Python module")
else()
add_custom_target(
install-python
echo "Must have Python installed to install the LAMMPS Python module")
endif()
else() else()
add_custom_target( add_custom_target(
install-python install-python
echo "Installation of the LAMMPS Python module requires building the LAMMPS shared library") echo "Must build LAMMPS as a shared library to use the Python module")
endif()
###############################################################################
# Add LAMMPS python module to "install" target. This is taylored for building
# LAMMPS for package managers and with different prefix settings.
# This requires either a shared library or that the PYTHON package is included.
###############################################################################
if((BUILD_LIB AND BUILD_SHARED_LIBS) OR (PKG_PYTHON))
find_package(PythonInterp)
if (${PYTHONINTERP_FOUND})
if(NOT PYTHON_INSTDIR)
execute_process(COMMAND ${PYTHON_EXECUTABLE}
-c "import distutils.sysconfig as cg; print(cg.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))"
OUTPUT_VARIABLE PYTHON_INSTDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../python/lammps.py DESTINATION ${PYTHON_INSTDIR})
endif()
endif() endif()
############################################################################### ###############################################################################