Commit ca7a1458 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Improve build of Python module + add build of wheel package.

parent 33117479
......@@ -68,8 +68,9 @@ add_custom_target(api_xml
)
# Generate the Python wrapper source code for the API in XML format
add_custom_target(pylinphone_source ALL
${PYTHON_EXECUTABLE} "${LINPHONE_SOURCE_DIR}/tools/python/apixml2python.py" "--outputfile" "${CMAKE_CURRENT_BINARY_DIR}/linphone.c" "${CMAKE_CURRENT_BINARY_DIR}/api.xml"
set(SOURCE_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/linphone.c")
add_custom_target(pylinphone_source
${PYTHON_EXECUTABLE} "${LINPHONE_SOURCE_DIR}/tools/python/apixml2python.py" "--outputfile" "${SOURCE_FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/api.xml"
DEPENDS api_xml "${LINPHONE_SOURCE_DIR}/tools/python/apixml2python.py" "${LINPHONE_SOURCE_DIR}/tools/python/apixml2python/linphone.py"
WORKING_DIRECTORY "${LINPHONE_SOURCE_DIR}/tools/python"
)
......@@ -80,21 +81,32 @@ if(WIN32)
list(APPEND LINPHONE_LIBRARIES gcc mingwex)
file(GLOB LINPHONE_DYNAMIC_LIBRARIES "${CMAKE_INSTALL_PREFIX}/bin/*.dll")
endif()
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/linphone")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.cmake" "${CMAKE_CURRENT_BINARY_DIR}/linphone/__init__.py")
file(COPY ${LINPHONE_DYNAMIC_LIBRARIES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/linphone")
if(MSVC AND NOT "${MSVC_VERSION}" STREQUAL "9")
file(COPY ${MSVCR_LIB} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/linphone")
endif()
file(COPY "${CMAKE_INSTALL_PREFIX}/share/images" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/linphone/share/")
file(COPY "${CMAKE_INSTALL_PREFIX}/share/linphone" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/linphone/share/")
file(COPY "${CMAKE_INSTALL_PREFIX}/share/sounds" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/linphone/share/")
file(GLOB_RECURSE LINPHONE_DATA_FILES RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/linphone" "${CMAKE_CURRENT_BINARY_DIR}/linphone/*")
if(MSVC AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(PDB_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build/lib.win32-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/linphone/linphone.pdb")
list(APPEND LINPHONE_DATA_FILES ${PDB_FILENAME})
set(_BUILDS "exe" "msi" "zip" "wheel")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
list(PREPEND _BUILDS "debug")
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.cmake" "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
foreach(_BUILD ${_BUILDS})
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/linphone")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.cmake" "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/linphone/__init__.py")
file(COPY ${LINPHONE_DYNAMIC_LIBRARIES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/linphone")
if(MSVC AND NOT "${MSVC_VERSION}" STREQUAL "9")
file(COPY ${MSVCR_LIB} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/linphone")
endif()
file(COPY "${CMAKE_INSTALL_PREFIX}/share/images" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/linphone/share/")
file(COPY "${CMAKE_INSTALL_PREFIX}/share/linphone" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/linphone/share/")
file(COPY "${CMAKE_INSTALL_PREFIX}/share/sounds" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/linphone/share/")
file(GLOB_RECURSE LINPHONE_DATA_FILES RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/linphone" "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/linphone/*")
if(MSVC AND ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND (NOT "${_BUILD}" STREQUAL "debug"))
set(PDB_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_debug/build/lib.win32-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/linphone/linphone.pdb")
list(APPEND LINPHONE_DATA_FILES ${PDB_FILENAME})
endif()
if("${_BUILD}" STREQUAL "msi")
set(BUILD_VERSION ${LINPHONE_VERSION})
else()
set(BUILD_VERSION ${LINPHONE_GIT_REVISION})
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.cmake" "${CMAKE_CURRENT_BINARY_DIR}/build_${_BUILD}/linphone/setup.py")
endforeach()
if(MSVC)
......@@ -106,32 +118,46 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
add_custom_target(pylinphone_debug ALL
${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/setup.py" "build" "--debug"
DEPENDS pylinphone_source
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_debug/linphone"
)
else()
add_custom_target(pylinphone_debug ALL DEPENDS pylinphone_source)
endif()
# Generate the installer
set(EXE_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/dist/linphone-${LINPHONE_VERSION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.exe")
set(EXE_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_exe/linphone/dist/linphone-${LINPHONE_GIT_REVISION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.exe")
add_custom_target(pylinphone_exe ALL
${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/setup.py" "bdist_wininst"
${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_exe/linphone/setup.py" "bdist_wininst"
DEPENDS pylinphone_debug
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_exe/linphone"
)
install(FILES ${EXE_FILENAME} DESTINATION "." RENAME "linphone-${LINPHONE_GIT_REVISION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.exe")
install(FILES ${EXE_FILENAME} DESTINATION ".")
# Generate the msi
set(MSI_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/dist/linphone-${LINPHONE_VERSION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.msi")
set(MSI_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_msi/linphone/dist/linphone-${LINPHONE_VERSION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.msi")
add_custom_target(pylinphone_msi ALL
${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/setup.py" "bdist_msi"
${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_msi/linphone/setup.py" "bdist_msi"
DEPENDS pylinphone_exe
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_msi/linphone"
)
install(FILES ${MSI_FILENAME} DESTINATION "." RENAME "linphone-${LINPHONE_GIT_REVISION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.msi")
install(FILES ${MSI_FILENAME} DESTINATION ".")
# Generate the zip
set(ZIP_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/dist/linphone-${LINPHONE_VERSION}.win32.zip")
set(ZIP_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone/dist/linphone-${LINPHONE_GIT_REVISION}.win32.zip")
add_custom_target(pylinphone_zip ALL
${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/setup.py" "bdist" "--format=zip"
${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone/setup.py" "bdist" "--format=zip"
DEPENDS pylinphone_msi
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone"
)
install(FILES ${ZIP_FILENAME} DESTINATION "." RENAME "linphone-${LINPHONE_GIT_REVISION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.zip")
# Generate the wheel package
string(REPLACE "-" "_" LINPHONE_UNDERSCORE_GIT_REVISION ${LINPHONE_GIT_REVISION})
set(WHEEL_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone/dist/linphone-${LINPHONE_UNDERSCORE_GIT_REVISION}-cp27-none-win32.whl")
add_custom_target(pylinphone_wheel ALL
${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone/setup.py" "bdist_wheel"
DEPENDS pylinphone_zip
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone"
)
install(FILES ${WHEEL_FILENAME} DESTINATION ".")
endif()
......@@ -18,9 +18,9 @@
import os
import string
from distutils.core import setup, Extension
from setuptools import setup, Extension
version = "@LINPHONE_VERSION@"
version = "@BUILD_VERSION@"
macros = "@LINPHONE_CPPFLAGS@"
include_dirs = "@LINPHONE_INCLUDE_DIRS@"
libraries = "@LINPHONE_LIBRARIES@"
......@@ -45,15 +45,33 @@ ext = Extension('linphone',
include_dirs = include_dirs,
libraries = libraries,
library_dirs = library_dirs,
sources = ['linphone.c']
sources = ['@SOURCE_FILENAME@']
)
setup(name = 'linphone',
version = version,
description = 'Linphone package for Python',
author = "Belledonne Communications",
author_email = "contact@belledonne-communications.com",
url = "http://www.linphone.org/",
packages = ['linphone'],
ext_package = 'linphone',
ext_modules = [ext],
package_data = {'linphone': data_files}
package_data = {'linphone': data_files},
zip_safe = True,
keywords = ["sip", "voip"],
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Win32 (MS Windows)",
"Intended Audience :: Developers",
"Intended Audience :: Telecommunications Industry",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Natural Language :: English",
"Operating System :: Microsoft :: Windows",
"Programming Language :: C",
"Programming Language :: C++",
"Programming Language :: Python :: 2.7",
"Topic :: Communications :: Chat",
"Topic :: Communications :: Internet Phone",
"Topic :: Communications :: Telephony"
]
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment