Skip to content

Commit

Permalink
cmake : add python support
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Jan 23, 2021
1 parent a641067 commit 0bb4550
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ jobs:
make
ctest
ubuntu-18_04-python:
runs-on: ubuntu-18.04

strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]

steps:
- name: Clone
uses: actions/checkout@v1
with:
submodules: recursive

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Dependencies
run: |
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install cmake;
- name: Configure
run: cmake . -DGGWAVE_SUPPORT_PYTHON=ON -DCMAKE_BUILD_TYPE=${{ matrix.build }}

- name: Build
run: |
make
ctest
ubuntu-18_04-gcc-sanitized:
runs-on: ubuntu-18.04

Expand Down
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ option(GGWAVE_SANITIZE_ADDRESS "ggwave: enable address sanitizer" OFF)
option(GGWAVE_SANITIZE_UNDEFINED "ggwave: enable undefined sanitizer" OFF)

option(GGWAVE_SUPPORT_SDL2 "ggwave: support for libSDL2" ${GGWAVE_SUPPORT_SDL2_DEFAULT})
option(GGWAVE_SUPPORT_PYTHON "ggwave: support for python" OFF)

option(GGWAVE_BUILD_TESTS "ggwave: build examples" ${GGWAVE_STANDALONE})
option(GGWAVE_BUILD_EXAMPLES "ggwave: build examples" ${GGWAVE_STANDALONE})
Expand Down Expand Up @@ -71,6 +72,31 @@ endif()

add_subdirectory(src)

if (GGWAVE_SUPPORT_PYTHON)
file(GLOB_RECURSE GGWAVE_SOURCES "include/*" "src/*")

add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/bindings/python/ggwave.bycython.cpp
OUTPUT ${CMAKE_SOURCE_DIR}/bindings/python/ggwave
DEPENDS ${CMAKE_SOURCE_DIR}/bindings/python/Makefile
DEPENDS ${CMAKE_SOURCE_DIR}/bindings/python/ggwave.pyx
DEPENDS ${CMAKE_SOURCE_DIR}/bindings/python/cggwave.pxd
DEPENDS ${CMAKE_SOURCE_DIR}/bindings/python/setup.py
DEPENDS ${GGWAVE_SOURCES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bindings/python
COMMAND make clean
COMMAND make
COMMENT "Compiling Python module"
VERBATIM
)

add_custom_target(ggwave-py ALL
DEPENDS bindings/python/ggwave.bycython.cpp
DEPENDS bindings/python/ggwave
)
endif()


if (GGWAVE_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
Expand Down
12 changes: 11 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ target_link_libraries(${TEST_TARGET} PRIVATE
ggwave
)

add_test(NAME ${TEST_TARGET} COMMAND $<TARGET_FILE:${TEST_TARGET}>)
add_test(NAME ${TEST_TARGET}-cpp COMMAND $<TARGET_FILE:${TEST_TARGET}>)

if (GGWAVE_SUPPORT_PYTHON)
add_test(NAME ${TEST_TARGET}-py
COMMAND python test-ggwave.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

set_tests_properties(${TEST_TARGET}-py
PROPERTIES ENVIRONMENT "PYTHONPATH=${PROJECT_SOURCE_DIR}/bindings/python")
endif()
7 changes: 7 additions & 0 deletions tests/test-ggwave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ggwave
import numpy as np

instance = ggwave.init()

# generate audio waveform for string "hello python"
waveform = ggwave.encode("hello python", txProtocolId = 1, volume = 20, instance = instance)

0 comments on commit 0bb4550

Please sign in to comment.