Skip to content

Commit

Permalink
Merge pull request #205 from msteinbeck/find-python
Browse files Browse the repository at this point in the history
Update find python
  • Loading branch information
msteinbeck authored May 17, 2022
2 parents 1e299f0 + ca1185f commit 6692ba6
Showing 1 changed file with 65 additions and 38 deletions.
103 changes: 65 additions & 38 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1400,40 +1400,67 @@ if(${TINYSPLINE_BINDING_REQUESTED})
"${TINYSPLINE_PHP_INTERFACE_FILE}")
endif()

# Python
if(${TINYSPLINE_ENABLE_PYTHON})
if(${TINYSPLINE_PYTHON_VERSION} STREQUAL "2")
set(Python_ADDITIONAL_VERSIONS
2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
elseif(${TINYSPLINE_PYTHON_VERSION} STREQUAL "3")
set(Python_ADDITIONAL_VERSIONS
3.11 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
endif()
find_package(PythonLibs REQUIRED)
if(${TINYSPLINE_PYTHON_VERSION} STREQUAL "2"
AND NOT ${PYTHONLIBS_VERSION_STRING} MATCHES "^2."
OR ${TINYSPLINE_PYTHON_VERSION} STREQUAL "3"
AND NOT ${PYTHONLIBS_VERSION_STRING} MATCHES "^3.")
message(FATAL_ERROR "Unable to find requested Python version")
endif()
include_directories(${PYTHON_INCLUDE_DIRS})
if(${PYTHONLIBS_VERSION_STRING} MATCHES "^3.")
set(TINYSPLINE_PYTHON_DEFINES "-py3")
endif()
tinyspline_add_swig_library(
TARGET ${TINYSPLINE_PYTHON_CMAKE_TARGET}
LANG python
OUTPUT ${TINYSPLINE_PYTHON_SOURCE_DIRECTORY}
LIBS ${PYTHON_LIBRARIES}
SWIG_ARGS ${TINYSPLINE_PYTHON_DEFINES})
add_custom_command(
TARGET ${TINYSPLINE_PYTHON_CMAKE_TARGET}
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy
"${TINYSPLINE_PYTHON_SOURCE_DIRECTORY}/${TINYSPLINE_PYTHON_CMAKE_TARGET}.py"
"${TINYSPLINE_PYTHON_INTERFACE_FILE}")
endif()
# Python
if(${TINYSPLINE_ENABLE_PYTHON})
if(DEFINED PYTHON_INCLUDE_DIR OR DEFINED PYTHON_LIBRARY)
# Legacy behavior.
find_package(PythonLibs REQUIRED)
set(TINYSPLINE_PYTHON_FOUND ${PYTHONLIBS_FOUND})
set(TINYSPLINE_PYTHON_VERSION_STRING ${PYTHONLIBS_VERSION_STRING})
set(TINYSPLINE_PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
set(TINYSPLINE_PYTHON_LIBRARIES ${PYTHON_LIBRARIES})
if(${PYTHONLIBS_VERSION_STRING} MATCHES "^3.")
set(TINYSPLINE_PYTHON_DEFINES "-py3")
endif()
elseif(${TINYSPLINE_PYTHON_VERSION} STREQUAL "2")
find_package(Python2 REQUIRED
COMPONENTS Interpreter Development
)
set(TINYSPLINE_PYTHON_FOUND ${Python2_FOUND})
set(TINYSPLINE_PYTHON_VERSION_STRING "${Python2_VERSION}")
set(TINYSPLINE_PYTHON_INCLUDE_DIRS ${Python2_INCLUDE_DIRS})
set(TINYSPLINE_PYTHON_LIBRARIES ${Python2_LIBRARIES})
elseif(${TINYSPLINE_PYTHON_VERSION} STREQUAL "3")
find_package(Python3 REQUIRED
COMPONENTS Interpreter Development
)
set(TINYSPLINE_PYTHON_FOUND ${Python3_FOUND})
set(TINYSPLINE_PYTHON_VERSION_STRING "${Python3_VERSION}")
set(TINYSPLINE_PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
set(TINYSPLINE_PYTHON_LIBRARIES ${Python3_LIBRARIES})
set(TINYSPLINE_PYTHON_DEFINES "-py3")
elseif(${TINYSPLINE_PYTHON_VERSION} STREQUAL "ANY")
find_package(Python REQUIRED
COMPONENTS Interpreter Development
)
set(TINYSPLINE_PYTHON_FOUND ${Python_FOUND})
set(TINYSPLINE_PYTHON_VERSION_STRING "${Python_VERSION}")
set(TINYSPLINE_PYTHON_INCLUDE_DIRS ${Python_INCLUDE_DIRS})
set(TINYSPLINE_PYTHON_LIBRARIES ${Python_LIBRARIES})
if(${Python_VERSION_MAJOR} VERSION_EQUAL 3)
set(TINYSPLINE_PYTHON_DEFINES "-py3")
endif()
else()
message(FATAL_ERROR "Python version is not supported")
endif()

include_directories(${TINYSPLINE_PYTHON_INCLUDE_DIRS})
tinyspline_add_swig_library(
TARGET ${TINYSPLINE_PYTHON_CMAKE_TARGET}
LANG python
OUTPUT ${TINYSPLINE_PYTHON_SOURCE_DIRECTORY}
LIBS ${TINYSPLINE_PYTHON_LIBRARIES}
SWIG_ARGS ${TINYSPLINE_PYTHON_DEFINES}
)
add_custom_command(
TARGET ${TINYSPLINE_PYTHON_CMAKE_TARGET}
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy
"${TINYSPLINE_PYTHON_SOURCE_DIRECTORY}/${TINYSPLINE_PYTHON_CMAKE_TARGET}.py"
"${TINYSPLINE_PYTHON_INTERFACE_FILE}"
)
endif()

# R
if(${TINYSPLINE_ENABLE_R})
Expand Down Expand Up @@ -1498,7 +1525,7 @@ tinyspline_set_on_off(TINYSPLINE_WITH_JAVA JNI_FOUND)
tinyspline_set_on_off(TINYSPLINE_WITH_LUA LUA_FOUND)
tinyspline_set_on_off(TINYSPLINE_WITH_OCTAVE OCTAVE_FOUND)
tinyspline_set_on_off(TINYSPLINE_WITH_PHP PHP_FOUND)
tinyspline_set_on_off(TINYSPLINE_WITH_PYTHON PYTHONLIBS_FOUND)
tinyspline_set_on_off(TINYSPLINE_WITH_PYTHON TINYSPLINE_PYTHON_FOUND)
tinyspline_set_on_off(TINYSPLINE_WITH_RUBY RUBY_FOUND)
tinyspline_set_on_off(TINYSPLINE_WITH_R R_FOUND)

Expand Down Expand Up @@ -1779,9 +1806,9 @@ Available Interfaces:
Include: ${PHP_INCLUDE_DIRS}
Python: ${TINYSPLINE_WITH_PYTHON}
Version: ${PYTHONLIBS_VERSION_STRING}
Include: ${PYTHON_INCLUDE_DIRS}
Library: ${PYTHON_LIBRARIES}
Version: ${TINYSPLINE_PYTHON_VERSION_STRING}
Include: ${TINYSPLINE_PYTHON_INCLUDE_DIRS}
Library: ${TINYSPLINE_PYTHON_LIBRARIES}
R: ${TINYSPLINE_WITH_R}
Version: ${R_VERSION}
Expand Down

0 comments on commit 6692ba6

Please sign in to comment.