Fix installation of lammps.py with CMake

In CMake 3.10 the PythonInterp module defined PYTHON_EXECUTABLE.  Since CMake
3.12 the Python module defines Python_EXECUTABLE.

Since the rest of the code was using PYTHON_EXECUTABLE and expecting it to be
defined, no matter which version, in newer versions of CMake this would lead to
lammps.py not being installed at all.

This commit changes the LAMMPS CMake files to use the newer variable name and
sets Python_EXECUTABLE in older versions if needed.
This commit is contained in:
Richard Berger 2020-04-14 17:45:46 -04:00
parent 7d71d5bfb3
commit 0afa9e60f9
1 changed files with 10 additions and 4 deletions

View File

@ -599,13 +599,16 @@ install(
if(BUILD_SHARED_LIBS)
if(CMAKE_VERSION VERSION_LESS 3.12)
find_package(PythonInterp) # Deprecated since version 3.12
if(PYTHONINTERP_FOUND)
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
endif()
else()
find_package(Python COMPONENTS Interpreter)
endif()
if (PYTHON_EXECUTABLE)
if (Python_EXECUTABLE)
add_custom_target(
install-python
${PYTHON_EXECUTABLE} install.py -v ${LAMMPS_SOURCE_DIR}/version.h
${Python_EXECUTABLE} install.py -v ${LAMMPS_SOURCE_DIR}/version.h
-m ${LAMMPS_PYTHON_DIR}/lammps.py
-l ${CMAKE_BINARY_DIR}/liblammps${CMAKE_SHARED_LIBRARY_SUFFIX}
WORKING_DIRECTORY ${LAMMPS_PYTHON_DIR}
@ -629,11 +632,14 @@ endif()
if(BUILD_SHARED_LIBS OR PKG_PYTHON)
if(CMAKE_VERSION VERSION_LESS 3.12)
find_package(PythonInterp) # Deprecated since version 3.12
if(PYTHONINTERP_FOUND)
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
endif()
else()
find_package(Python COMPONENTS Interpreter)
endif()
if (PYTHON_EXECUTABLE)
execute_process(COMMAND ${PYTHON_EXECUTABLE}
if (Python_EXECUTABLE)
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_DEFAULT_INSTDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
set(PYTHON_INSTDIR ${PYTHON_DEFAULT_INSTDIR} CACHE PATH "Installation folder for LAMMPS Python module")