Skip to content

Commit c464d6e

Browse files
author
Clement Champetier
committed
CMake: check python version when install corresponding binding
* If CMake 2.8.8, can get python version from PYTHONLIBS_VERSION_STRING. * Else, get python version from include path.
1 parent 3c07530 commit c464d6e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ if(SWIG_FOUND)
6161
if(PYTHONLIBS_FOUND)
6262
include_directories(${PYTHON_INCLUDE_PATH})
6363

64+
if(NOT DEFINED PYTHONLIBS_VERSION_STRING) # Since CMake 2.8.8
65+
# Get Python version from include path
66+
string(LENGTH ${PYTHON_INCLUDE_DIRS} PYTHON_INCLUDE_DIRS_LENGTH)
67+
math(EXPR PYTHON_INCLUDE_DIRS_LENGTH "${PYTHON_INCLUDE_DIRS_LENGTH} - 3" )
68+
string(SUBSTRING ${PYTHON_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS_LENGTH} 3 PYTHONLIBS_VERSION_STRING)
69+
endif()
70+
6471
# Swig flags
6572
set(CMAKE_SWIG_FLAGS -c++ -fcompact)
6673

@@ -75,7 +82,7 @@ if(SWIG_FOUND)
7582
install(
7683
FILES ${AVTRANSCODER_PYTHON_BINDING_FILE}
7784
RENAME "avtranscoder.py"
78-
DESTINATION "lib/python2.7/site-packages/avtranscoder/"
85+
DESTINATION "lib/python${PYTHONLIBS_VERSION_STRING}/site-packages/avtranscoder/"
7986
)
8087
else()
8188
message("PYTHON not found, will not build python binding.")

0 commit comments

Comments
 (0)