diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b075fc8f8d..95d738d279 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -159,17 +159,20 @@ endif() ######################################################################## # User input options # ######################################################################## -# 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() +# backward compatibility with CMake before 3.12 and older LAMMPS documentation +if (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" - " Setting Python interpreter to: ${PYTHON_EXECUTABLE}") + " Setting Python interpreter to: ${Python_EXECUTABLE}") endif() 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) # backward compatibility - if(PYTHON_EXECUTABLE) - set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) - endif() find_package(Python COMPONENTS Interpreter) if(BUILD_IS_MULTI_CONFIG) set(MY_BUILD_DIR ${CMAKE_BINARY_DIR}/$) diff --git a/cmake/Modules/Packages/PYTHON.cmake b/cmake/Modules/Packages/PYTHON.cmake index 59260e39d5..e05edadbf3 100644 --- a/cmake/Modules/Packages/PYTHON.cmake +++ b/cmake/Modules/Packages/PYTHON.cmake @@ -1,6 +1,6 @@ if(NOT Python_INTERPRETER) - # backward compatibility + # backward compatibility with CMake before 3.12 and older LAMMPS documentation if(PYTHON_EXECUTABLE) set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) endif() diff --git a/doc/src/Build_extras.rst b/doc/src/Build_extras.rst index 393d7e1c20..7a7b5cf0d5 100644 --- a/doc/src/Build_extras.rst +++ b/doc/src/Build_extras.rst @@ -1056,12 +1056,12 @@ additional details. .. 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 on your system. To use a different Python version, you can either 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 have the development headers installed for this version, e.g. python2-devel. diff --git a/doc/src/Howto_pylammps.rst b/doc/src/Howto_pylammps.rst index 2db61cd5bb..bce37d5ac7 100644 --- a/doc/src/Howto_pylammps.rst +++ b/doc/src/Howto_pylammps.rst @@ -133,7 +133,7 @@ to the location in the virtual environment with: .. code-block:: bash - cmake . -DPYTHON_EXECUTABLE=$(which python) + cmake . -DPython_EXECUTABLE=$(which python) # install LAMMPS package in virtualenv (testing) make install-python