Skip to content

Commit

Permalink
unify all compiled C++ into 1 binary file (#64)
Browse files Browse the repository at this point in the history
* unify all compiled C++ into 1 binary file

* fix docs

* fix apply_flags() in cmake script

* switch to pypa/build pkg in CI

to create sdist for release (and bdist for docs)

* remove debug flag for RF24 lib
  • Loading branch information
2bndy5 authored Jun 15, 2024
1 parent 4db31f1 commit 628b6c6
Show file tree
Hide file tree
Showing 23 changed files with 570 additions and 576 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ jobs:

- name: Build package for docs extraction and linting examples
run: |
python3 setup.py sdist bdist_wheel
python3 -m pip install dist/pyrf24-*.whl
python -m pip install build
python -m build
python -m pip install dist/pyrf24-*.whl
- name: check python typing
run: mypy src
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ jobs:
- name: build source distributable wheel
# sdist for non-supprted platforms will serve as a stub lib install
run: python setup.py sdist
run: |
python -m pip install build
python -m build -s
- name: Save distributable wheels as artifacts
uses: actions/upload-artifact@v4
Expand Down
109 changes: 29 additions & 80 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.15)
project(pyrf24)

if(SKBUILD)
message(STATUS "This project is being built using scikit-build & pybind11")
message(STATUS "This project is being built using scikit-build & pybind11")
endif()

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
Expand All @@ -14,112 +14,61 @@ include(cmake/using_flags.cmake)
add_subdirectory(pybind11)
include(RF24/cmake/AutoConfig_RF24_DRIVER.cmake)
add_subdirectory(RF24/utility) # configure the RF24_DRIVER

if(NOT "${RF24_LINKED_DRIVER}" STREQUAL "")
message(STATUS "Linking to utility driver '${RF24_LINKED_DRIVER}'")
endif()

# suplement our copy of linux/gpio.h into SPIDEV & RPi driver sources
# suplement our copy of linux/gpio.h into SPIDEV driver sources
set(SUPPLEMENT_LINUX_GPIO_H FALSE)

if("${RF24_DRIVER}" STREQUAL "SPIDEV")
set(SUPPLEMENT_LINUX_GPIO_H TRUE)
message(STATUS "Supplementing ${RF24_DRIVER} driver with linux/gpio.h")
# file(COPY src/linux/gpio.h DESTINATION RF24/utility/${RF24_DRIVER}/linux)
list(APPEND RF24_DRIVER_SOURCES src/linux/gpio.h)
endif()

### Build C++ RF24 stack as shared libraries (resulting in isolated binary drivers)

################################# RF24 C++ #########################
add_library(cpp_rf24 SHARED
# ## Build python bindings for RF24 stack into 1 binary
pybind11_add_module(pyrf24
RF24/RF24.cpp
${RF24_DRIVER_SOURCES}
)
if(SUPPLEMENT_LINUX_GPIO_H)
target_include_directories(cpp_rf24 PUBLIC src)
endif()
target_include_directories(cpp_rf24 PUBLIC utility)
if(NOT "${RF24_LINKED_DRIVER}" STREQUAL "")
if("${RF24_DRIVER}" STREQUAL "wiringPi")
target_link_libraries(cpp_rf24 PUBLIC rt crypt ${RF24_LINKED_DRIVER})
else()
target_link_libraries(cpp_rf24 PUBLIC ${RF24_LINKED_DRIVER})
endif()
endif()
apply_flags(cpp_rf24)

################################# RF24Network C++ #########################
add_library(cpp_rf24_network SHARED
RF24Network/RF24Network.cpp
)
# don't let source look for an installed RF24 lib
target_compile_definitions(cpp_rf24_network PUBLIC USE_RF24_LIB_SRC)
target_include_directories(cpp_rf24_network PUBLIC
RF24
RF24/utility
RF24/utility/${RF24_DRIVER}
RF24Network
)
target_link_libraries(cpp_rf24_network PUBLIC cpp_rf24)
apply_flags(cpp_rf24_network)

################################# RF24Mesh C++ #########################
add_library(cpp_rf24_mesh SHARED
RF24Mesh/RF24Mesh.cpp
)
# don't let source look for an installed RF24 lib
target_compile_definitions(cpp_rf24_mesh PUBLIC USE_RF24_LIB_SRC)
target_include_directories(cpp_rf24_mesh PUBLIC
RF24
RF24/utility
RF24/utility/${RF24_DRIVER}
RF24Network
RF24Mesh
)
target_link_libraries(cpp_rf24_mesh PUBLIC cpp_rf24_network)
apply_flags(cpp_rf24_mesh)

### Build python bindings for RF24 stack and link to shared C++ lib binaries

################################# RF24 #############################
pybind11_add_module(rf24 src/pyRF24.cpp)
target_link_libraries(rf24 PUBLIC cpp_rf24)
target_include_directories(rf24 PUBLIC
RF24
RF24/utility
RF24/utility/${RF24_DRIVER}
src/pyRF24.cpp
src/pyRF24Network.cpp
src/pyRF24Mesh.cpp
src/glue.cpp
)

################################# RF24NETWORK #############################
pybind11_add_module(rf24_network src/pyRF24Network.cpp)
target_link_libraries(rf24_network PUBLIC cpp_rf24_network)
target_include_directories(rf24_network PUBLIC
RF24
RF24/utility
RF24/utility/${RF24_DRIVER}
RF24Network
)
# don't let source look for an installed RF24 lib
target_compile_definitions(rf24_network PUBLIC USE_RF24_LIB_SRC)
target_compile_definitions(pyrf24 PUBLIC USE_RF24_LIB_SRC)

if(SUPPLEMENT_LINUX_GPIO_H)
target_include_directories(pyrf24 PUBLIC src)
endif()

################################# RF24MESH #############################
pybind11_add_module(rf24_mesh src/pyRF24Mesh.cpp)
target_link_libraries(rf24_mesh PUBLIC cpp_rf24_mesh)
target_include_directories(rf24_mesh PUBLIC
target_include_directories(pyrf24 PUBLIC
RF24
RF24/utility
RF24/utility/${RF24_DRIVER}
RF24Network
RF24Mesh
)
# don't let source look for an installed RF24 lib
target_compile_definitions(rf24_mesh PUBLIC USE_RF24_LIB_SRC)

if(NOT "${RF24_LINKED_DRIVER}" STREQUAL "")
if("${RF24_DRIVER}" STREQUAL "wiringPi")
target_link_libraries(pyrf24 PUBLIC rt crypt ${RF24_LINKED_DRIVER})
else()
target_link_libraries(pyrf24 PUBLIC ${RF24_LINKED_DRIVER})
endif()
endif()

apply_flags(pyrf24)

################################ INSTALL RULES ####################################
# these are needed for scikit builds since the resulting .so files are copied into
# ############################### INSTALL RULES ####################################
# these are needed since the resulting .so files are copied into
# the binary distribution wheels (.whl files) for python.
install(TARGETS rf24 rf24_network rf24_mesh DESTINATION .)
install(TARGETS cpp_rf24 cpp_rf24_network cpp_rf24_mesh DESTINATION .)
install(TARGETS pyrf24 DESTINATION .)

# uncomment to show compiler args used in build logs
# ## uncomment to show compiler args used in build logs
# set(CMAKE_VERBOSE_MAKEFILE ON)
Loading

0 comments on commit 628b6c6

Please sign in to comment.