Skip to content

Commit

Permalink
MAINTENANCE: Update to use Machinekit-HAL's new packaging scheme
Browse files Browse the repository at this point in the history
Add a new simple CMake based build-system taking advantage of the new targets and scripts exported by Machinekit-HAL. For user's convenience also adds a Debian packaging.
  • Loading branch information
cerna committed Jan 22, 2022
1 parent ff03242 commit 4da9215
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 5 deletions.
112 changes: 112 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# ##############################################################################
# Description: CMakeLists.txt
#
# This file, 'CMakeLists.txt', implements build system rules for BB-GPIO project
#
# Copyright (C) 2021 Jakub Fišer <jakub DOT fiser AT eryaf DOT com>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this library; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# ##############################################################################
# ~~~

cmake_minimum_required(VERSION 3.22)

set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(CMAKE_EXPORT_LINK_COMMANDS TRUE)
set(CMAKE_DISABLE_SOURCE_CHANGES TRUE)
set(CMAKE_DISABLE_IN_SOURCE_BUILD TRUE)

project(
BB-GPIO
VERSION 1.0.0
DESCRIPTION "GPIO driver for Beaglebone Black SBC"
HOMEPAGE_URL "https://github.com/PocketNC/bb_gpio"
LANGUAGES C)

if(CMAKE_TOOLCHAIN_FILE)
cmake_path(IS_RELATIVE CMAKE_TOOLCHAIN_FILE _toolchain_file_is_relative)
if(_toolchain_file_is_relative)
file(REAL_PATH "${CMAKE_TOOLCHAIN_FILE}" _toolchain_path BASE_DIRECTORY
"${CMAKE_BINARY_DIR}" EXPAND_TILDE)
if(NOT EXISTS "${_toolchain_path}")
message(
FATAL_ERROR "Specified Toolchain file ${_toolchain_path} doesn't exist!"
)
endif()
set(CMAKE_TOOLCHAIN_FILE "${_toolchain_path}")
message(
WARNING
"CMAKE_TOOLCHAIN_FILE set to ${CMAKE_TOOLCHAIN_FILE} to resolve the relative path issue. Please, avoid using relative paths!"
)
unset(_toolchain_path)
endif()
unset(_toolchain_file_is_relative)
endif()

find_package(
Machinekit-HAL
COMPONENTS Managed-Runtime Managed-HAL
REQUIRED)

include(GNUInstallDirs)
include(CPackComponent)
include(CPack)
include(FindPkgConfig)

set(MACHINEKIT_HAL_PACKAGE_PREFIX_PATH "machinekit/hal")
set(MACHINEKIT_HAL_MANAGED_MODULE_DIRECTORY
"${CMAKE_INSTALL_LIBDIR}/${MACHINEKIT_HAL_PACKAGE_PREFIX_PATH}/module/managed"
)

set(CMAKE_C_STANDARD 11)

set(CMAKE_C_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_C_FLAGS_RELEASE "-O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O0")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O0")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O0")

message(STATUS "Value of CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "Value of CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "Value of CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")

pkg_check_modules(LIBGPIOD "libgpiod" REQUIRED IMPORTED_TARGET)

add_library(bb_gpio MODULE)
target_sources(bb_gpio PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bb_gpio.c"
"${CMAKE_CURRENT_SOURCE_DIR}/bb_gpio.h")

target_link_libraries(
bb_gpio PRIVATE Machinekit::HAL::managed_hal Machinekit::HAL::managed_runtime
PkgConfig::LIBGPIOD)

export_rtapi_symbols(TARGET bb_gpio)

set_target_properties(
bb_gpio
PROPERTIES OUTPUT_NAME "bb_gpio"
PREFIX "mod"
LIBRARY_OUTPUT_DIRECTORY
"${MACHINEKIT_HAL_MANAGED_MODULE_DIRECTORY}")

install(TARGETS bb_gpio
LIBRARY DESTINATION "${MACHINEKIT_HAL_MANAGED_MODULE_DIRECTORY}"
COMPONENT BB_GPIO_Managed_Module_Drivers)

cpack_add_component(BB_GPIO_Managed_Module_Drivers GROUP BB_GPIO_Managed_Module)

cpack_add_component_group(BB_GPIO_Managed_Module)
11 changes: 6 additions & 5 deletions bb_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
*
********************************************************************/

#include "rtapi.h" /* RTAPI realtime OS API */
#include "rtapi_app.h" /* RTAPI realtime module decls */
#include "rtapi_errno.h" /* EINVAL etc */
#include "hal.h" /* HAL public API decls */
#include "hal_priv.h"
#include "runtime/rtapi.h" /* RTAPI realtime OS API */
#include "runtime/rtapi_app.h" /* RTAPI realtime module decls */
#include "runtime/rtapi_errno.h" /* EINVAL etc */
#include "hal/hal.h" /* HAL public API decls */
#include "hal/hal_priv.h"
#include "bb_gpio.h"
#include <sys/mman.h>

#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>

MODULE_AUTHOR("John Allwine");
MODULE_DESCRIPTION("Driver for GPIO pins on Beaglebone Boards using /dev/mem");
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bb-gpio (1.0.0) bullseye; urgency=low

* Update to use the new Machinekit-HAL packaging scheme
* Add simple Debian packaging
* Add a CMake based buildsystem

-- Jakub Fišer <jakub.fiser@eryaf.com> Sat, 22 Jan 2020 10:00:00 +0200
25 changes: 25 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Source: bb-gpio
Section: misc
Priority: optional
Maintainer: MachinekitBot <machinekit@eryaf.com>
Build-Depends:
dh-cmake,
dh-cmake-compat (= 1),
dh-sequence-cpack,
debhelper-compat (= 12),
debhelper (>= 10),
libmachinekit-hal-dev,
libgpiod-dev
Standards-Version: 4.5.1
Homepage: https://github.com/PocketNC/bb_gpio


Package: modbb-gpio
Architecture: any
Multi-Arch: same
Depends:
${shlibs:Depends},
${misc:Depends},
machinekit-hal
Description: BeagleBone Black GPIO Driver for Machinekit-HAL
Managed HAL driver module for BeagleBone Black GPIO
1 change: 1 addition & 0 deletions debian/modbb-gpio.cpack-component-groups
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BB_GPIO_Managed_Module
51 changes: 51 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/make -f

# ####################################################################
# Description: rules
#
# This file, 'rules', implements build targets for Debian
# style packaging
#
# Copyright (C) 2021 Jakub Fišer <jakub DOT fiser AT eryaf DOT com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# #####################################################################

# Turn OFF the Link-Time Optimization (LTO) during compilation as it clashes with the
# current version of linker script turning symbols of HAL modules local (defined
# in 'MachinekitHALSymbolVisibilityFunction.cmake' CMake file)
DEB_CFLAGS_MAINT_STRIP :=-flto=auto -ffat-lto-objects
DEB_CXXFLAGS_MAINT_STRIP :=-flto=auto -ffat-lto-objects
DEB_LDFLAGS_MAINT_STRIP :=-flto=auto

# Set the main optimization value for all parts to O0
DEB_CFLAGS_MAINT_STRIP +=-O2
DEB_CXXFLAGS_MAINT_STRIP +=-O2
DEB_CFLAGS_MAINT_APPEND :=-O0
DEB_CXXFLAGS_MAINT_APPEND :=-O0

# Do not warn on potential reproducible build datetime mismatch
DEB_CPPFLAGS_MAINT_STRIP :=-Wdate-time

export DEB_CFLAGS_MAINT_STRIP
export DEB_CXXFLAGS_MAINT_STRIP
export DEB_LDFLAGS_MAINT_STRIP
export DEB_CFLAGS_MAINT_APPEND
export DEB_CXXFLAGS_MAINT_APPEND
export DEB_CPPFLAGS_MAINT_STRIP

%:
dh $@ --buildsystem=cmake

0 comments on commit 4da9215

Please sign in to comment.