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

python: Use FindPython cmake module instead of deprecated FindPythonInterp #227

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.12)

# Enable MACOSX_RPATH by default
cmake_policy(SET CMP0042 NEW)
Expand Down
8 changes: 4 additions & 4 deletions cmake/appveyor.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ if(BUILD_ZFPY)
set(CTEST_SITE "${CTEST_SITE}_zfpy$ENV{PYTHON_VERSION}")

# sanitize python include dir path (ex. windows vs linux slashes)
set(PYTHON_INCLUDE_DIR "")
file(TO_CMAKE_PATH "${CTEST_SOURCE_DIRECTORY}\\$ENV{VIRTUALENV_NAME}\\Include" PYTHON_INCLUDE_DIR)
set(Python_INCLUDE_DIR "")
file(TO_CMAKE_PATH "${CTEST_SOURCE_DIRECTORY}\\$ENV{VIRTUALENV_NAME}\\Include" Python_INCLUDE_DIR)

list(APPEND cfg_options
-DPYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR}
-DPYTHON_LIBRARY=$ENV{PYTHON_LIB_PATH}
-DPython_INCLUDE_DIR=${Python_INCLUDE_DIR}
-DPython_LIBRARY=$ENV{PYTHON_LIB_PATH}
)
endif()

Expand Down
9 changes: 2 additions & 7 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27.0)
cmake_policy(SET CMP0148 OLD)
endif ()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/scikit-build-cmake)
include(UseCython)
include(FindPythonExtensions)
include(FindNumPy)

find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(PythonExtensions REQUIRED)
find_package(Cython 0.28 REQUIRED) # >= v0.28 required for const memoryview support
find_package(NumPy REQUIRED)
Expand All @@ -26,5 +21,5 @@ set(PYLIB_BUILD_DIR "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Directory where zfp py
set_target_properties(zfpy PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYLIB_BUILD_DIR})

# Install to the typical python module directory
set(python_install_lib_dir "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/")
set(python_install_lib_dir "lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/")
install(TARGETS zfpy LIBRARY DESTINATION ${python_install_lib_dir})
8 changes: 1 addition & 7 deletions python/scikit-build-cmake/FindCython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@

# Use the Cython executable that lives next to the Python executable
# if it is a local installation.
if(Python_EXECUTABLE)
get_filename_component(_python_path ${Python_EXECUTABLE} PATH)
elseif(Python3_EXECUTABLE)
get_filename_component(_python_path ${Python3_EXECUTABLE} PATH)
elseif(DEFINED PYTHON_EXECUTABLE)
get_filename_component(_python_path ${PYTHON_EXECUTABLE} PATH)
endif()
get_filename_component(_python_path ${Python_EXECUTABLE} PATH)

if(DEFINED _python_path)
find_program(CYTHON_EXECUTABLE
Expand Down
16 changes: 8 additions & 8 deletions python/scikit-build-cmake/FindNumPy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ if(NOT NumPy_FOUND)
find_program(NumPy_CONV_TEMPLATE_EXECUTABLE NAMES conv-template)
find_program(NumPy_FROM_TEMPLATE_EXECUTABLE NAMES from-template)

if(PYTHON_EXECUTABLE)
execute_process(COMMAND "${PYTHON_EXECUTABLE}"
if(Python_EXECUTABLE)
execute_process(COMMAND "${Python_EXECUTABLE}"
-c "import numpy; print(numpy.get_include())"
OUTPUT_VARIABLE _numpy_include_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
execute_process(COMMAND "${PYTHON_EXECUTABLE}"
execute_process(COMMAND "${Python_EXECUTABLE}"
-c "import numpy; print(numpy.__version__)"
OUTPUT_VARIABLE NumPy_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand All @@ -60,31 +60,31 @@ if(NOT NumPy_FOUND)

# XXX This is required to support NumPy < v0.15.0. See note in module documentation above.
if(NOT NumPy_CONV_TEMPLATE_EXECUTABLE)
execute_process(COMMAND "${PYTHON_EXECUTABLE}"
execute_process(COMMAND "${Python_EXECUTABLE}"
-c "from numpy.distutils import conv_template; print(conv_template.__file__)"
OUTPUT_VARIABLE _numpy_conv_template_file
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
set(NumPy_CONV_TEMPLATE_EXECUTABLE "${PYTHON_EXECUTABLE}" "${_numpy_conv_template_file}" CACHE STRING "Command executing conv-template program" FORCE)
set(NumPy_CONV_TEMPLATE_EXECUTABLE "${Python_EXECUTABLE}" "${_numpy_conv_template_file}" CACHE STRING "Command executing conv-template program" FORCE)
endif()

# XXX This is required to support NumPy < v0.15.0. See note in module documentation above.
if(NOT NumPy_FROM_TEMPLATE_EXECUTABLE)
execute_process(COMMAND "${PYTHON_EXECUTABLE}"
execute_process(COMMAND "${Python_EXECUTABLE}"
-c "from numpy.distutils import from_template; print(from_template.__file__)"
OUTPUT_VARIABLE _numpy_from_template_file
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
set(NumPy_FROM_TEMPLATE_EXECUTABLE "${PYTHON_EXECUTABLE}" "${_numpy_from_template_file}" CACHE STRING "Command executing from-template program" FORCE)
set(NumPy_FROM_TEMPLATE_EXECUTABLE "${Python_EXECUTABLE}" "${_numpy_from_template_file}" CACHE STRING "Command executing from-template program" FORCE)
endif()
endif()
endif()

find_path(NumPy_INCLUDE_DIR
numpy/arrayobject.h
PATHS "${_numpy_include_dir}" "${PYTHON_INCLUDE_DIR}"
PATHS "${_numpy_include_dir}" "${Python_INCLUDE_DIR}"
PATH_SUFFIXES numpy/core/include
)

Expand Down
24 changes: 12 additions & 12 deletions python/scikit-build-cmake/FindPythonExtensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@
# limitations under the License.
#=============================================================================

find_package(PythonInterp REQUIRED)
if(SKBUILD AND NOT PYTHON_LIBRARY)
set(PYTHON_LIBRARY "no-library-required")
find_package(PythonLibs)
unset(PYTHON_LIBRARY)
unset(PYTHON_LIBRARIES)
find_package(Python REQUIRED)
if(SKBUILD AND NOT Python_LIBRARY)
set(Python_LIBRARY "no-library-required")
find_package(Python COMPONENTS Development)
unset(Python_LIBRARY)
unset(Python_LIBRARIES)
else()
find_package(PythonLibs)
find_package(Python COMPONENTS Development)
endif()
include(targetLinkLibrariesWithDynamicLookup)

Expand Down Expand Up @@ -297,7 +297,7 @@ sys.stdout.write(\";\".join((
)))
")

execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "${_command}"
execute_process(COMMAND "${Python_EXECUTABLE}" -c "${_command}"
OUTPUT_VARIABLE _list
RESULT_VARIABLE _result)

Expand Down Expand Up @@ -417,7 +417,7 @@ function(python_extension_module _target)
endif()

if(NOT _is_non_lib)
include_directories("${PYTHON_INCLUDE_DIRS}")
include_directories("${Python_INCLUDE_DIRS}")
endif()

if(_is_module_lib)
Expand All @@ -442,7 +442,7 @@ function(python_extension_module _target)
endif()
endif()

target_link_libraries_with_dynamic_lookup(${_target} ${PYTHON_LIBRARIES})
target_link_libraries_with_dynamic_lookup(${_target} ${Python_LIBRARIES})

if(_is_module_lib)
_set_python_extension_symbol_visibility(${_target})
Expand All @@ -451,8 +451,8 @@ function(python_extension_module _target)
endfunction()

function(python_standalone_executable _target)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(${_target} ${SKBUILD_LINK_LIBRARIES_KEYWORD} ${PYTHON_LIBRARIES})
include_directories(${Python_INCLUDE_DIRS})
target_link_libraries(${_target} ${SKBUILD_LINK_LIBRARIES_KEYWORD} ${Python_LIBRARIES})
endfunction()

function(python_modules_header _name)
Expand Down
2 changes: 1 addition & 1 deletion python/scikit-build-cmake/UsePythonExtensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function(add_python_library _name)
_remove_whitespace(_tempita_command)
add_custom_command(
OUTPUT ${_source_we}
COMMAND ${PYTHON_EXECUTABLE} -c "${_tempita_command}"
COMMAND ${Python_EXECUTABLE} -c "${_tempita_command}"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_source}"
${_args_DEPENDS}
)
Expand Down