for consistency with CMake 3.12+ we should set Python_EXECUTABLE instead of PYTHON_EXECUTABLE

This commit is contained in:
Axel Kohlmeyer
2023-10-24 07:51:54 -04:00
parent 22cc6bf0b3
commit ceed4c7db8
4 changed files with 16 additions and 16 deletions

View File

@ -159,17 +159,20 @@ endif()
######################################################################## ########################################################################
# User input options # # User input options #
######################################################################## ########################################################################
# set path to python interpreter and thus enforcing python version when # backward compatibility with CMake before 3.12 and older LAMMPS documentation
# in a virtual environment and PYTHON_EXECUTABLE is not set on command line if (PYTHON_EXECUTABLE)
if(DEFINED ENV{VIRTUAL_ENV} AND NOT PYTHON_EXECUTABLE)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(PYTHON_EXECUTABLE "$ENV{VIRTUAL_ENV}/Scripts/python.exe")
else()
set(PYTHON_EXECUTABLE "$ENV{VIRTUAL_ENV}/bin/python")
endif()
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
endif()
# set path to python interpreter and thus enforcing python version when
# in a virtual environment and Python_EXECUTABLE is not set on command line
if(DEFINED ENV{VIRTUAL_ENV} AND NOT Python_EXECUTABLE)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(Python_EXECUTABLE "$ENV{VIRTUAL_ENV}/Scripts/python.exe")
else()
set(Python_EXECUTABLE "$ENV{VIRTUAL_ENV}/bin/python")
endif()
message(STATUS "Running in virtual environment: $ENV{VIRTUAL_ENV}\n" message(STATUS "Running in virtual environment: $ENV{VIRTUAL_ENV}\n"
" Setting Python interpreter to: ${PYTHON_EXECUTABLE}") " Setting Python interpreter to: ${Python_EXECUTABLE}")
endif() endif()
set(LAMMPS_MACHINE "" CACHE STRING "Suffix to append to lmp binary (WON'T enable any features automatically") set(LAMMPS_MACHINE "" CACHE STRING "Suffix to append to lmp binary (WON'T enable any features automatically")
@ -794,9 +797,6 @@ install(
############################################################################### ###############################################################################
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
# backward compatibility # backward compatibility
if(PYTHON_EXECUTABLE)
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
endif()
find_package(Python COMPONENTS Interpreter) find_package(Python COMPONENTS Interpreter)
if(BUILD_IS_MULTI_CONFIG) if(BUILD_IS_MULTI_CONFIG)
set(MY_BUILD_DIR ${CMAKE_BINARY_DIR}/$<CONFIG>) set(MY_BUILD_DIR ${CMAKE_BINARY_DIR}/$<CONFIG>)

View File

@ -1,6 +1,6 @@
if(NOT Python_INTERPRETER) if(NOT Python_INTERPRETER)
# backward compatibility # backward compatibility with CMake before 3.12 and older LAMMPS documentation
if(PYTHON_EXECUTABLE) if(PYTHON_EXECUTABLE)
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
endif() endif()

View File

@ -1056,12 +1056,12 @@ additional details.
.. code-block:: bash .. code-block:: bash
-D PYTHON_EXECUTABLE=path # path to Python executable to use -D Python_EXECUTABLE=path # path to Python executable to use
Without this setting, CMake will guess the default Python version Without this setting, CMake will guess the default Python version
on your system. To use a different Python version, you can either on your system. To use a different Python version, you can either
create a virtualenv, activate it and then run cmake. Or you can create a virtualenv, activate it and then run cmake. Or you can
set the PYTHON_EXECUTABLE variable to specify which Python set the Python_EXECUTABLE variable to specify which Python
interpreter should be used. Note note that you will also need to interpreter should be used. Note note that you will also need to
have the development headers installed for this version, have the development headers installed for this version,
e.g. python2-devel. e.g. python2-devel.

View File

@ -133,7 +133,7 @@ to the location in the virtual environment with:
.. code-block:: bash .. code-block:: bash
cmake . -DPYTHON_EXECUTABLE=$(which python) cmake . -DPython_EXECUTABLE=$(which python)
# install LAMMPS package in virtualenv # install LAMMPS package in virtualenv
(testing) make install-python (testing) make install-python