Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to override PYTHON_VERSION when invoking cmake #1442

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

mchukhrii
Copy link
Contributor

Currently cmake script will override PYTHON_EXECUTABLE if specified in command line.
This patch should fix it. Now if PYTHON_EXECUTABLE is not empty it will be used and python version discovery will not run.

@mchukhrii mchukhrii force-pushed the master branch 9 times, most recently from 21e1e17 to 89f31ba Compare March 22, 2024 23:55
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
if (NOT NO_PYVERBS AND Python_VERSION_MAJOR EQUAL 3)
FIND_PACKAGE(PythonInterp REQUIRED)
FIND_PACKAGE(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite different now, previously we only required the development packages if cmake was enabled, now it needs it always

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this discards the preference to use python3, that doesn't seem right. If PYTHON_VERSION is not specified it should continue to do the automatic detection logic.

Copy link
Contributor Author

@mchukhrii mchukhrii Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_package will not fail if PythonLibs is not found.
https://cmake.org/cmake/help/v3.11/command/find_package.html
but PYTHONLIBS_FOUND wont be set so i check for that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elseif (${CMAKE_VERSION} VERSION_GREATER "3.12")
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
FIND_PACKAGE(Python 3 REQUIRED COMPONENTS Interpreter OPTIONAL_COMPONENTS Development)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both legs if this if should be setting this, right?

Copy link
Contributor Author

@mchukhrii mchukhrii Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIND_PACKAGE(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT)
elseif (${CMAKE_VERSION} VERSION_GREATER "3.12")
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
FIND_PACKAGE(Python 3 REQUIRED COMPONENTS Interpreter OPTIONAL_COMPONENTS Development)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What fails cmake if cython is enabled and we don't find Development?

Copy link
Contributor Author

@mchukhrii mchukhrii Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If find_package python find developer libs Python_Development_FOUND variable is set so i check for that
https://cmake.org/cmake/help/v3.13/module/FindPython.html#result-variables

@mchukhrii
Copy link
Contributor Author

Updated commit. Now should always prefer python3

CMakeLists.txt Outdated
if (NOT NO_PYVERBS AND Python_VERSION_MAJOR EQUAL 3)
FIND_PACKAGE(PythonInterp 3 REQUIRED)
FIND_PACKAGE(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT)
elseif (${CMAKE_VERSION} VERSION_GREATER "3.12")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing to handle 3.12:
VERSION_GREATER_EQUAL

Make it possible to override PYTHON_VERSION when invoking cmake.

Signed-off-by: Maksym Chukhrii <mchukhrii@nvidia.com>
@rleon rleon merged commit 4b08a22 into linux-rdma:master Apr 3, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants