Skip to content

Commit

Permalink
Merge pull request #18 from nRF24/CMake-4-Linux
Browse files Browse the repository at this point in the history
CMake for linux
  • Loading branch information
TMRh20 authored Nov 15, 2021
2 parents 1cefcdb + f35b293 commit da2058a
Show file tree
Hide file tree
Showing 37 changed files with 2,607 additions and 1,147 deletions.
174 changes: 174 additions & 0 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
name: Linux build

on:
pull_request:
types: [opened, reopened]
paths:
- "*.h"
- "*.cpp"
- "CMakeLists.txt"
- "cmake/**"
- "examples/**.cpp"
- "!**Makefile" # old build system is not tested in this workflow
- ".github/workflows/build_linux.yml"
push:
paths:
- "*.h"
- "*.cpp"
- "CMakeLists.txt"
- "cmake/**"
- "examples/**.cpp"
- "!**Makefile" # old build system is not tested in this workflow
- ".github/workflows/build_linux.yml"
release:
types: [published, edited]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
using_cmake:
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
toolchain:
- compiler: "armhf"
usr_dir: "arm-linux-gnueabihf"
- compiler: "arm64"
usr_dir: "aarch64-linux-gnu"
# - compiler: "x86_64"
# usr_dir: "x86_64-linux-gnux32"
# - compiler: "i686"
# usr_dir: "i686-linux-gnu"
- compiler: "default" # github runner is hosted on a "amd64"
usr_dir: "local" # use default compiler to test build all examples (including the ncurses ones)

steps:
# - name: provide toolchain (for x86_64)
# if: ${{ matrix.toolchain.compiler == 'x86_64' }}
# run: |
# sudo apt-get update
# sudo apt-get install gcc-x86-64-linux-gnux32 g++-x86-64-linux-gnux32

# - name: provide toolchain (for i686)
# if: ${{ matrix.toolchain.compiler == 'i686' }}
# run: |
# sudo apt-get update
# sudo apt-get install gcc-i686-linux-gnu g++-i686-linux-gnu

- name: provide toolchain (for arm64)
if: ${{ matrix.toolchain.compiler == 'arm64' }}
run: |
sudo apt-get update
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: provide toolchain (for armhf)
if: ${{ matrix.toolchain.compiler == 'armhf' }}
run: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
- name: checkout RF24
uses: actions/checkout@v2
with:
repository: nRF24/RF24
ref: rp2xxx

- name: build & install RF24
run: |
mkdir build
cd build
cmake .. -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D RF24_DRIVER=SPIDEV \
-D CMAKE_INSTALL_PREFIX=/usr/${{ matrix.toolchain.usr_dir }} \
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchains/${{ matrix.toolchain.compiler }}.cmake
sudo make install
- name: checkout RF24Network
uses: actions/checkout@v2
with:
repository: nRF24/RF24Network

- name: build & install RF24Network
run: |
mkdir build
cd build
cmake .. -D CMAKE_BUILD_TYPE=$BUILD_TYPE \
-D CMAKE_INSTALL_PREFIX=/usr/${{ matrix.toolchain.usr_dir }} \
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchains/${{ matrix.toolchain.compiler }}.cmake
sudo make install
- name: checkout RF24Mesh
uses: actions/checkout@v2
with:
repository: nRF24/RF24Mesh

- name: build & install RF24Mesh
run: |
mkdir build
cd build
cmake .. -D CMAKE_BUILD_TYPE=$BUILD_TYPE \
-D CMAKE_INSTALL_PREFIX=/usr/${{ matrix.toolchain.usr_dir }} \
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchains/${{ matrix.toolchain.compiler }}.cmake
sudo make install
- name: checkout RF24Gateway
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: create CMake build environment
run: cmake -E make_directory ${{ github.workspace }}/build

- name: configure lib
working-directory: ${{ github.workspace }}/build
run: |
cmake .. -D CMAKE_BUILD_TYPE=$BUILD_TYPE \
-D CMAKE_INSTALL_PREFIX=/usr/${{ matrix.toolchain.usr_dir }} \
-D CMAKE_TOOLCHAIN_FILE=cmake/toolchains/${{ matrix.toolchain.compiler }}.cmake
- name: build lib
working-directory: ${{ github.workspace }}/build
run: cmake --build .

- name: install lib
working-directory: ${{ github.workspace }}/build
run: sudo cmake --install .

- name: package lib
working-directory: ${{ github.workspace }}/build
run: sudo cpack

- name: Save artifact
uses: actions/upload-artifact@v2
with:
name: "pkg_RF24Gateway"
path: |
${{ github.workspace }}/build/pkgs/*.deb
${{ github.workspace }}/build/pkgs/*.rpm
- name: Upload Release assets
if: github.event_name == 'release' && (matrix.toolchain.compiler == 'armhf' || matrix.toolchain.compiler == 'arm64')
uses: csexton/release-asset-action@master
with:
pattern: "${{ github.workspace }}/build/pkgs/librf24*"
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: clean build environment
working-directory: ${{ github.workspace }}/build
run: sudo rm -r ./*

- name: configure examples
working-directory: ${{ github.workspace }}/build
run: |
cmake ../examples \
-D CMAKE_TOOLCHAIN_FILE=../cmake/toolchains/${{ matrix.toolchain.compiler }}.cmake
- name: build examples
working-directory: ${{ github.workspace }}/build
run: |
cmake --build .
file ./RF24GatewayNode
86 changes: 53 additions & 33 deletions .github/workflows/doxygen.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,64 @@
name: DoxyGen build
name: build Docs

on:
pull_request:
branches:
- master
types: [opened, reopened]
paths:
- "*.h"
- "*.md"
- "docs/**"
- "!**README.md"
- "examples**.cpp"
- ".github/workflows/doxygen.yml"
- "Doxyfile"
push:
branches:
- master
paths:
- "*.h"
- "*.md"
- "docs/**"
- "!**README.md"
- "examples**.cpp"
- ".github/workflows/doxygen.yml"
- "Doxyfile"
release:
branches:
- master
types:
- published
- edited
branches: [master]
types: [published, edited]

jobs:
build-doxygen:
runs-on: ubuntu-latest

steps:
- name: get latest release version number
id: latest_ver
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: nRF24/RF24Gateway
- name: checkout
uses: actions/checkout@v2
- name: overwrite doxygen tags
run: |
touch doxygenAction
echo "PROJECT_NUMBER = ${{ steps.latest_ver.outputs.release }}" >> doxygenAction
echo "@INCLUDE = doxygenAction" >> Doxyfile
- name: build doxygen
uses: mattnotmitt/doxygen-action@v1
with:
working-directory: '.'
doxyfile-path: './Doxyfile'
- name: upload to github pages
if: ${{ github.event_name == 'release'}}
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/html
- name: get latest release version number
id: latest_ver
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: nRF24/RF24Gateway

- name: checkout
uses: actions/checkout@v2

- name: overwrite doxygen tags
run: |
touch doxygenAction
echo "PROJECT_NUMBER = ${{ steps.latest_ver.outputs.release }}" >> doxygenAction
echo "@INCLUDE = doxygenAction" >> Doxyfile
- name: build doxygen
uses: mattnotmitt/doxygen-action@v1
with:
working-directory: '.'
doxyfile-path: './Doxyfile'

- name: Save doxygen docs as artifact
uses: actions/upload-artifact@v2
with:
name: "RF24Gateway_doxygen_docs"
path: ${{ github.workspace }}/docs/html

- name: upload to github pages
if: ${{ github.event_name == 'release'}}
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/html
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# ignore doxygen generated files
# Generated library files
*.so
*.so.1

# ignore docs folder
docs/html/
docs/xml/

# ignore CMake stuff
build/
*CMakeUserPresets.json

# ignore local vscode folder
.vscode/
92 changes: 92 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
cmake_minimum_required(VERSION 3.15)

# Set the project name to your project name
project(RF24Gateway C CXX)
include(cmake/StandardProjectSettings.cmake)
include(cmake/PreventInSourceBuilds.cmake)

# Link this 'library' to set the c++ standard / compile-time options requested
add_library(project_options INTERFACE)
target_compile_features(project_options INTERFACE cxx_std_17)
add_compile_options(-Ofast -Wall)

# allow using CMake options to adjust RF24Network_config.h without modiying source code
option(DEBUG_LEVEL "adjust the verbosity of the debugging messages" 0)

# detect CPU and add compiler flags accordingly
include(cmake/detectCPU.cmake)

if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
if(ENABLE_BUILD_WITH_TIME_TRACE)
add_compile_definitions(project_options INTERFACE -ftime-trace)
endif()
endif()

# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
add_library(project_warnings INTERFACE)

# enable cache system
include(cmake/Cache.cmake)

# standard compiler warnings
include(cmake/CompilerWarnings.cmake)
set_project_warnings(project_warnings)

# get library info from Arduino IDE's required library.properties file
include(cmake/GetLibInfo.cmake) # sets the variable LibTargetName

# setup CPack options
include(cmake/CPackInfo.cmake)

find_library(RF24 rf24 REQUIRED)
message(STATUS "using RF24 library: ${RF24}")

find_library(RF24Network rf24network REQUIRED)
message(STATUS "using RF24Network library: ${RF24Network}")

find_library(RF24Mesh rf24mesh REQUIRED)
message(STATUS "using RF24Mesh library: ${RF24Mesh}")

###########################
# create target for bulding the RF24Log lib
###########################
add_library(${LibTargetName} SHARED RF24Gateway.cpp)
target_include_directories(${LibTargetName} PUBLIC ${CMAKE_CURRENT_LIST_DIR})

target_link_libraries(${LibTargetName} INTERFACE
project_options
project_warnings
SHARED ${RF24}
SHARED ${RF24Network}
SHARED ${RF24Mesh}
)

set_target_properties(
${LibTargetName}
PROPERTIES
SOVERSION ${${LibName}_VERSION_MAJOR}
VERSION ${${LibName}_VERSION_STRING}
)

# assert the appropriate preprocessor macros for RF24Network_config.h
if(DEBUG_LEVEL GREATER 0)
message(STATUS "DEBUG_LEVEL set to ${DEBUG_LEVEL}")
target_compile_definitions(${LibTargetName} PUBLIC DEBUG_LEVEL=${DEBUG_LEVEL})
endif()

###########################
# target install rules for the RF24Log lib
###########################
install(TARGETS ${LibTargetName} DESTINATION lib)

install(FILES
RF24Gateway.h
DESTINATION include/RF24Gateway
)

# CMAKE_CROSSCOMPILING is only TRUE when CMAKE_TOOLCHAIN_FILE is specified via CLI
if(CMAKE_HOST_UNIX AND "${CMAKE_CROSSCOMPILING}" STREQUAL "FALSE")
install(CODE "message(STATUS \"Updating ldconfig\")")
install(CODE "execute_process(COMMAND ldconfig)")
endif()
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
These are the current requirements for getting your code included in RF24:
These are the current requirements for getting your code included in RF24Gateway:

* Try your best to follow the rest of the code, if you're unsure then the NASA C style can help as it's closest to the current style: https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19950022400.pdf

Expand All @@ -7,3 +7,8 @@ These are the current requirements for getting your code included in RF24:
* Follow the [Arduino IDE formatting style](https://www.arduino.cc/en/Reference/StyleGuide) for Arduino examples

* Add [doxygen-compatible documentation](https://www.doxygen.nl/manual/docblocks.html) to any new functions you add, or update existing documentation if you change behaviour

* CMake modules and CMakeLists.txt files should also have a uniform syntax.
- Indentation is a mandatory 4 spaces (not a `\t` character).
- Closing parenthesis for multi-line commands should have the same indentation as the line that opened the parenthesis.
- For other useful CMake syntax convention, please see [CMake docs for developers](https://cmake.org/cmake/help/v3.20/manual/cmake-developer.7.html) and [this useful best CMake practices article](https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1). The qiBuild project has some [well-reasoned "Dos & Don'ts" guideline](http://doc.aldebaran.com/qibuild/hacking/contrib/cmake/coding_guide.html), but beware that the nRF24 organization is not related to the qiBuild project in any way.
Loading

0 comments on commit da2058a

Please sign in to comment.