Skip to content

Commit

Permalink
add CMake 4 Linux; clean up tests/jamfile relics
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Jun 5, 2021
1 parent d8bcb22 commit 1e600d7
Show file tree
Hide file tree
Showing 35 changed files with 714 additions and 1,303 deletions.
137 changes: 137 additions & 0 deletions .github/workflows/linux_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Linux build

on:
pull_request:
types: [opened, synchronize, reopened]
push:
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"

steps:
- uses: actions/checkout@v1
- name: install rpmbuild
run: sudo apt-get install rpm

# - 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
if: ${{ matrix.toolchain.compiler == 'default' }}
working-directory: ${{ github.workspace }}/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: create CMake build environment
run: cmake -E make_directory ${{ github.workspace }}/build

- name: configure lib
if: ${{ matrix.toolchain.compiler == 'default' }}
working-directory: ${{ github.workspace }}/build
run: cmake .. -D CMAKE_BUILD_TYPE=$BUILD_TYPE

- name: configure lib (with toolchain compilers)
if: ${{ matrix.toolchain.compiler != 'default' }}
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_RF24Mesh"
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_RPi \
-D CMAKE_TOOLCHAIN_FILE=../cmake/toolchains/${{ matrix.toolchain.compiler }}.cmake
- name: build examples
working-directory: ${{ github.workspace }}/build
run: |
cmake --build .
file ./helloworld_tx
89 changes: 87 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,93 @@
# (or more exactly: if we just got included in a pico-sdk based project)
if (PICO_SDK_PATH)
# If so, load the relevant CMakeLists-file but don't do anything else
include(${CMAKE_CURRENT_LIST_DIR}/usePicoSDK.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/usePicoSDK.cmake)
return()
endif()

## TODO: Non-PicoSDK builds

############################
# for non-RPi-Pico platforms
############################
cmake_minimum_required(VERSION 3.15)

# Set the project name to your project name
project(RF24Network 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)

# 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}")

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

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

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

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

install(FILES
RF24Network.h
RF24Network_config.h
DESTINATION include/RF24Network
)

# 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()
3 changes: 0 additions & 3 deletions Jamfile

This file was deleted.

73 changes: 73 additions & 0 deletions cmake/CPackInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This module will build a debian compatible package to install - handy for cross-compiling

if(NOT PKG_REV)
set(PKG_REV "1")
endif()

# get target arch if not cross-compiling
if(NOT TARGET_ARCH) # TARGET_ARCH is defined only in the toolchain_<ARCH_TYPE>.cmake files
if(WIN32)
set(TARGET_ARCH $ENV{PROCESSOR_ARCHITECTURE})
else()
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE TARGET_ARCH
)
endif()
string(STRIP "${TARGET_ARCH}" TARGET_ARCH)
endif()

# set the Cpack generators (specific to types of packages to create)
if(NOT WIN32)
set(CPACK_GENERATOR DEB RPM) # RPM requires rpmbuild executable
else()
set(CPACK_GENERATOR "") # should find out how to build vcpkg packages
endif()

# assemble a debian package filename from known info
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_FILE_NAME "lib${LibTargetName}_${${LibName}_VERSION_STRING}-${PKG_REV}_${TARGET_ARCH}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR "${${LibName}_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${${LibName}_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${${LibName}_VERSION_PATCH}")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/pkgs") # for easy uploading to github releases

if(NOT WIN32)
###############################
# info specific debian packages
###############################
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
set(CPACK_DEBIAN_PACKAGE_SECTION libs)
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)

###############################
# info specific rpm (fedora) packages
###############################
set(CPACK_RPM_FILE_NAME "lib${LibTargetName}-${${LibName}_VERSION_STRING}-${PKG_REV}.${TARGET_ARCH}.rpm")
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${TARGET_ARCH})
set(CPACK_RPM_PACKAGE_LICENSE "GPLv2.0")
set(CPACK_RPM_PACKAGE_VENDOR "Humanity")

# create a post-install & post-removal scripts to update linker
set(POST_SCRIPTS
${CMAKE_BINARY_DIR}/DEBIAN/postrm
${CMAKE_BINARY_DIR}/DEBIAN/postinst
)
foreach(script ${POST_SCRIPTS})
file(WRITE ${script} /sbin/ldconfig)
execute_process(COMMAND chmod +x ${script})
execute_process(COMMAND chmod 775 ${script})
endforeach()
# declare scripts for deb pkgs
list(JOIN POST_SCRIPTS ";" EXTRA_CTRL_FILES)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA EXTRA_CTRL_FILES)
# declare scripts for rpm pkgs
list(POP_FRONT POST_SCRIPTS CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE)
list(POP_FRONT POST_SCRIPTS CPACK_RPM_POST_INSTALL_SCRIPT_FILE)

message(STATUS "ready to package: ${CPACK_PACKAGE_FILE_NAME}.deb")
message(STATUS "ready to package: ${CPACK_RPM_FILE_NAME}")
endif()

include(CPack)
31 changes: 31 additions & 0 deletions cmake/Cache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
option(ENABLE_CACHE "Enable cache if available" ON)
if(NOT ENABLE_CACHE)
return()
endif()

set(CACHE_OPTION
"ccache"
CACHE STRING "Compiler cache to be used"
)
set(CACHE_OPTION_VALUES "ccache" "sccache")
set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES})
list(
FIND
CACHE_OPTION_VALUES
${CACHE_OPTION}
CACHE_OPTION_INDEX
)

if(${CACHE_OPTION_INDEX} EQUAL -1)
message(STATUS
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}"
)
endif()

find_program(CACHE_BINARY ${CACHE_OPTION})
if(CACHE_BINARY)
message(STATUS "${CACHE_OPTION} found and enabled")
set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BINARY})
else()
message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it")
endif()
Loading

0 comments on commit 1e600d7

Please sign in to comment.