Skip to content

Commit

Permalink
build pip wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
figroc committed Sep 14, 2020
1 parent 915bd5b commit 754d2b2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.12)

project(s2-geometry)
project(s2geometry VERSION 0.9.0)

include(CMakeDependentOption)
include(CheckCXXCompilerFlag)
Expand Down Expand Up @@ -410,7 +410,7 @@ install(FILES src/s2/util/units/length-units.h
DESTINATION include/s2/util/units)
install(TARGETS s2 s2testing DESTINATION lib)

message("GTEST_ROOT: ${GTEST_ROOT}")
message(" * GTEST_ROOT: ${GTEST_ROOT}")
if (GTEST_ROOT)
add_subdirectory(${GTEST_ROOT} build_gtest)
include_directories(${GTEST_ROOT}/include)
Expand Down
30 changes: 25 additions & 5 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,31 @@ swig_link_libraries(pywraps2 ${Python3_LIBRARIES} s2)
enable_testing()
add_test(NAME pywraps2_test COMMAND
${Python3_EXECUTABLE}
"${PROJECT_SOURCE_DIR}/src/python/pywraps2_test.py")
"${PROJECT_SOURCE_DIR}/src/python/pywraps2_test.py")
set_property(TEST pywraps2_test PROPERTY ENVIRONMENT
"PYTHONPATH=$ENV{PYTHONPATH}:${PROJECT_BINARY_DIR}/python")

# Install the wrapper.
install(TARGETS _pywraps2 DESTINATION ${Python3_SITELIB})
install(FILES "${PROJECT_BINARY_DIR}/python/pywraps2.py"
DESTINATION ${Python3_SITELIB})
# Package pip wheel
set(PYWRAPS2_PKG "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}")
set(PYWRAPS2_DIST "${CMAKE_CURRENT_BINARY_DIR}/dist")
set(PYWRAPS2_SETUP "${CMAKE_CURRENT_BINARY_DIR}/setup.py")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py" ${PYWRAPS2_SETUP})
add_custom_command(OUTPUT ${PYWRAPS2_PKG}
COMMAND ${CMAKE_COMMAND} -E
make_directory ${PYWRAPS2_PKG}
COMMAND ${CMAKE_COMMAND} -E
copy $<TARGET_FILE:s2> ${PYWRAPS2_PKG}
COMMAND ${CMAKE_COMMAND} -E
copy "$<TARGET_FILE_DIR:_pywraps2>/*pywraps2.*" ${PYWRAPS2_PKG}
COMMAND ${CMAKE_COMMAND} -E
copy "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py" ${PYWRAPS2_PKG}
DEPENDS s2 _pywraps2)
add_custom_command(OUTPUT ${PYWRAPS2_DIST}
COMMAND ${Python3_EXECUTABLE} ${PYWRAPS2_SETUP} bdist_wheel
DEPENDS ${PYWRAPS2_PKG} ${PYWRAPS2_SETUP})
add_custom_target(bdist_wheel ALL DEPENDS ${PYWRAPS2_PKG} ${PYWRAPS2_DIST})

# Install the package
install(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${PYWRAPS2_SETUP} install
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
1 change: 1 addition & 0 deletions src/python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .pywraps2 import *
15 changes: 15 additions & 0 deletions src/python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from setuptools import setup, Distribution


class BinaryDistribution(Distribution):
def has_ext_modules(self):
return True


setup(
name="@PROJECT_NAME@",
version="@PROJECT_VERSION@",
packages=["@PROJECT_NAME@"],
package_data={"": ["*.so", "*.dylib", "*.dll"]},
distclass=BinaryDistribution
)

0 comments on commit 754d2b2

Please sign in to comment.