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

Look for Python using find_package() #1834

Open
moubctez opened this issue May 30, 2022 · 1 comment
Open

Look for Python using find_package() #1834

moubctez opened this issue May 30, 2022 · 1 comment

Comments

@moubctez
Copy link

In CMake, Python should be detected with find_package() (not FIND_PROGRAM). If there multiple Python versions installed (in my case, there is a system Python and various versions from PkgSrc), it might not be the version we want.

Here's my patch to deal with the issue:

--- apps/CMakeLists.txt.orig	2022-02-22 20:49:04.000000000 +0000
+++ apps/CMakeLists.txt
@@ -21,8 +21,8 @@ ENDIF(INSTALL_HELPER_SCRIPTS)
 
 # Inspired by http://bloerg.net/2012/11/10/cmake-and-distutils.html
 
-FIND_PROGRAM(PYTHON "python3")
-IF(PYTHON)
+find_package (Python3 COMPONENTS Interpreter)
+IF(Python3_FOUND)
     SET(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
     SET(SETUP_PY    "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
     SET(DEPS_IN     "${CMAKE_CURRENT_SOURCE_DIR}/lensfun/__init__.py.in")
@@ -33,7 +33,7 @@ IF(PYTHON)
     CONFIGURE_FILE(${DEPS_IN} ${DEPS})
 
     ADD_CUSTOM_COMMAND(OUTPUT ${OUTPUT}
-                       COMMAND ${PYTHON} ${SETUP_PY} build
+                       COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} build
                        COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
                        DEPENDS ${DEPS_IN})
 
@@ -42,5 +42,5 @@ IF(PYTHON)
     IF(NOT DEFINED SETUP_PY_INSTALL_PREFIX)
       SET(SETUP_PY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
     ENDIF()
-    INSTALL(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install --prefix=\$ENV{DESTDIR}${SETUP_PY_INSTALL_PREFIX})")
+    INSTALL(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} install --root=\$ENV{DESTDIR})")
 ENDIF(PYTHON)
@payano
Copy link
Contributor

payano commented Oct 21, 2022

Hello, Could you please do a PR instead?

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

No branches or pull requests

2 participants