Skip to content

Commit

Permalink
FEATURE: Implement installing CMake scripts for out-of-source-tree build
Browse files Browse the repository at this point in the history
Install CMake config script files to a base operating system under the `/usr/lib/<gnu-triplet>/cmake/Machinekit-HAL`mount-point for the Debian packaging.

Implement missing COMPONENT files for selected targets. (As CMake does not take care of it automatically.)

Make sure the 'usercomp.0' runtest is successful.
  • Loading branch information
cerna committed Dec 22, 2021
1 parent 53ee7b2 commit f6a35e6
Show file tree
Hide file tree
Showing 144 changed files with 1,470 additions and 681 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/debian-builder-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ jobs:
DISTRIBUTION: ${{ matrix.osDistribution}}
VERSION: ${{ matrix.osVersionCodename}}
ARCHITECTURE: ${{ matrix.architecture}}
BUILD_TARGET: 'machinekit-hal_base'
BUILD_TARGET: 'machinekit-hal_builder_base'
IMAGE_NAME: 'machinekit-hal-runner'
working-directory: ./build/machinekit-hal
Expand All @@ -548,7 +548,7 @@ jobs:
/home/machinekit/machinekit-hal/*.deb
echo "ANNOUNCE_IPV4=0" | sudo tee -a /etc/machinekit/hal/machinekit.ini
echo "ANNOUNCE_IPV6=0" | sudo tee -a /etc/machinekit/hal/machinekit.ini
run_runtests
run_runtests -v
"
env:
DOCKER_IMAGE: 'docker.pkg.github.com/${{ github.repository }}/machinekit-hal-runner:latest'
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ share/pkgconfig/machinekit-hal.pc
/packages/
# install artifacts
/include/
# CMake binary tree usual directories
obj-*
build
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ set(MACHINEKIT_HAL_UNMANAGED_MODULE_DIRECTORY
"${MACHINEKIT_HAL_EXECUTABLE_DIRECTORY}")
set(MACHINEKIT_HAL_INTERNAL_EXECUTABLE_DIRECTORY
"${CMAKE_INSTALL_LIBEXECDIR}/${MACHINEKIT_HAL_PACKAGE_PREFIX_PATH}")
set(MACHINEKIT_HAL_INTERFACE_DIRECTORY "${CMAKE_INSTALL_INCLUDEDIR}")
set(MACHINEKIT_HAL_INTERFACE_DIRECTORY
"${CMAKE_INSTALL_INCLUDEDIR}/${MACHINEKIT_HAL_PACKAGE_PREFIX_PATH}")
set(MACHINEKIT_HAL_SYSTEM_CONFIG_DIRECTORY
"${CMAKE_INSTALL_SYSCONFDIR}/${MACHINEKIT_HAL_PACKAGE_PREFIX_PATH}")
set(MACHINEKIT_HAL_LOCAL_STATE_DIRECTORY "${CMAKE_INSTALL_LOCALSTATEDIR}")
Expand Down
4 changes: 3 additions & 1 deletion debian/control.in
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ Description: Universal framework for machine control based on Hardware Abstracti
Package: python3-machinekit-hal
Architecture: any
Multi-Arch: foreign
Depends: ${shlibs:Depends}, ${misc:Depends}, ${cpack:Depends}, ${python3:Depends}
Depends: ${shlibs:Depends}, ${misc:Depends}, ${cpack:Depends}, ${python3:Depends},
python3-yapps,
yapps2
Description: Machinekit-HAL's Python exacutables
This package contains the executables written in Python for the Machinekit-HAL project

Expand Down
7 changes: 7 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,12 @@ else
dh_dwz
endif

# This is hopefully a temporary hack (but HACK nonetheless) to install the CMake configuration files
# for `find_package()` calls as there is a problem with CPack based installation as outlined
# in https://discourse.cmake.org/t/installing-cmake-exports-with-cpack/4718 and waiting for an expert help
override_dh_install:
cd debian/tmp && find . -iwholename '*/Machinekit-HAL/*.cmake' -exec mkdir \
-p ../libmachinekit-hal-dev/$(dirname {}) \; -exec cp {} ../libmachinekit-hal-dev/{} \;

%:
dh $@ --buildsystem=cmake --with=python3
30 changes: 22 additions & 8 deletions debian/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import shutil
import pathlib
import tempfile
from contextlib import nullcontext
#from contextlib import nullcontext
from typing import Union, List

import importlib.util
Expand Down Expand Up @@ -138,7 +138,7 @@ def run_runtests(self, test_path: pathlib.Path = None) -> None:
(config if self.generator == "Ninja Multi-Config" else ".") / \
"share" / "machinekit" / "hal" / "testsuite" / \
"runtests" if test_path is None else test_path

test_directory = pathlib.Path(tempfile.mkdtemp(suffix=config))
destination = test_directory / "runtests"
print(
Expand Down Expand Up @@ -191,21 +191,35 @@ def build(self,
if target is not None:
build_additional.append(["--target", target])

if sudo:
_context = sh.contrib.sudo(
password=self.sudo_password, _with=True, _out=sys.stdout.buffer)
else:
_context = nullcontext()
# Available only in Python 3.7 and later
# if sudo:
# _context = sh.contrib.sudo(
# password=self.sudo_password, _with=True, _out=sys.stdout.buffer)
# else:
# _context = nullcontext()

for config in self.configs:
with _context:
# Until fully supported, use ExitStack
# with _context:
if not sudo:
sh.cmake("--build", self.build_directory,
"-j", number_of_cores_string,
"--verbose",
"--config", config,
*build_additional,
_out=sys.stdout.buffer)

else:
# Using `sh.contrib.sudo` is not possible because of the old version of `sh`
# in Ubuntu Bionic registry
sudo_cmd = sh.sudo.bake("-S", _in=self.sudo_password)
sudo_cmd.cmake("--build", self.build_directory,
"-j", number_of_cores_string,
"--verbose",
"--config", config,
*build_additional,
_out=sys.stdout.buffer)

def test_for_sudo(self: object) -> bool:
try:
sh.dpkg_query("-W", "sudo", _tty_out=False)
Expand Down
8 changes: 2 additions & 6 deletions src/executables/comp/src/MachinekitHALCompFunction.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,14 @@ function(add_legacy_managed_module target_name)
add_library(${target_name} MODULE)
target_sources(${target_name} PRIVATE ${preprocessed_c_source_file})

target_link_libraries(${target_name} PRIVATE hal_api runtime_api)
target_link_libraries(${target_name} PRIVATE managed_hal managed_runtime)

if(${prefix}_LINK_LIBRARIES)
target_link_libraries(${target_name} PRIVATE ${${prefix}_LINK_LIBRARIES})
endif()

export_rtapi_symbols(TARGET ${target_name})

target_compile_definitions(${target_name} PRIVATE "RTAPI")

set_target_properties(
${target_name} PROPERTIES OUTPUT_NAME "${source_file_stem}" PREFIX "mod")

Expand Down Expand Up @@ -207,14 +205,12 @@ function(add_legacy_unmanaged_module target_name)
add_executable(${target_name})
target_sources(${target_name} PRIVATE ${preprocessed_c_source_file})

target_link_libraries(${target_name} PRIVATE hal runtime)
target_link_libraries(${target_name} PRIVATE unmanaged_hal unmanaged_runtime)

if(${prefix}_LINK_LIBRARIES)
target_link_libraries(${target_name} PRIVATE ${${prefix}_LINK_LIBRARIES})
endif()

target_compile_definitions(${target_name} PRIVATE "ULAPI")

if(${prefix}_OUTPUT_DIRECTORY)
cmake_path(IS_ABSOLUTE ${prefix}_OUTPUT_DIRECTORY
output_directory_is_absolute)
Expand Down
36 changes: 16 additions & 20 deletions src/executables/comp/src/comp.g
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ parser Hal:
token POP: "[-()+*/]|&&|\\|\\||personality|==|&|!=|<|<=|>|>="
token TSTRING: "\"\"\"(\\.|\\\n|[^\\\"]|\"(?!\"\")|\n)*\"\"\""

rule File: ComponentDeclaration Declaration* "$" {{ return True }}
rule File: ComponentDeclaration Declaration * "$" {{return True}}
rule ComponentDeclaration:
"component" NAME OptString";" {{ comp(NAME, OptString); }}
"component" NAME OptString";" {{comp(NAME, OptString); }}
rule Declaration:
"pin" PINDIRECTION TYPE HALNAME OptArray OptSAssign OptPersonality OptString ";" {{ pin(HALNAME, TYPE, OptArray, PINDIRECTION, OptString, OptSAssign, OptPersonality) }}
"pin" PINDIRECTION TYPE HALNAME OptArray OptSAssign OptPersonality OptString ";" {{pin(HALNAME, TYPE, OptArray, PINDIRECTION, OptString, OptSAssign, OptPersonality)}}
| "param" PARAMDIRECTION TYPE HALNAME OptArray OptSAssign OptPersonality OptString ";" {{ param(HALNAME, TYPE, OptArray, PARAMDIRECTION, OptString, OptSAssign, OptPersonality) }}
| "function" NAME OptFP OptString ";" {{ function(NAME, OptFP, OptString) }}
| "variable" NAME STARREDNAME OptSimpleArray OptAssign ";" {{ variable(NAME, STARREDNAME, OptSimpleArray, OptAssign) }}
Expand Down Expand Up @@ -256,13 +256,13 @@ def prologue(f):
f.write("/* Autogenerated by %s -- do not edit */\n" % (
sys.argv[0]))
f.write("""\
#include "runtime/rtapi.h"
#ifdef RTAPI
#include "runtime/rtapi_app.h"
#endif
#include "runtime/rtapi_string.h"
#include "runtime/rtapi_errno.h"
#include "hal/hal.h"
# include "runtime/rtapi.h"
# ifdef RTAPI
# include "runtime/rtapi_app.h"
# endif
# include "runtime/rtapi_string.h"
# include "runtime/rtapi_errno.h"
# include "hal/hal.h"
static int comp_id;
""")
Expand Down Expand Up @@ -662,9 +662,7 @@ add_executable({module_name})
target_sources({module_name} PRIVATE {c_source_file})
target_link_libraries({module_name}
PRIVATE Machinekit::HAL::hal)
target_compile_definitions({module_name} PRIVATE "ULAPI")
PRIVATE Machinekit::HAL::unmanaged_hal)
set_target_properties(
{module_name}
Expand Down Expand Up @@ -726,7 +724,7 @@ def build_usr(tempdir, filename, mode, origfilename, installdir):
# TODO: Does this really make sense?
for sofile in tempdir.glob('*.so'):
shutil.copy(sofile, pathlib.Path.cwd() / sofile.name)
#else:
# else:
# raise SystemExit("Error: Unable to copy module from temporary directory")

cmake_recipe_base_managed = """
Expand All @@ -753,13 +751,11 @@ add_library({module_name} MODULE)
target_sources({module_name} PRIVATE {c_source_file})
target_link_libraries({module_name}
PRIVATE Machinekit::HAL::hal_api
Machinekit::HAL::runtime_api)
PRIVATE Machinekit::HAL::managed_hal
Machinekit::HAL::managed_runtime)
export_rtapi_symbols(TARGET {module_name})
target_compile_definitions({module_name} PRIVATE "RTAPI")
set_target_properties(
{module_name}
PROPERTIES OUTPUT_NAME "{module_name}"
Expand Down Expand Up @@ -821,7 +817,7 @@ def build_rt(tempdir, filename, mode, origfilename, installdir):
# TODO: Does this really make sense?
for sofile in tempdir.glob('*.so'):
shutil.copy(sofile, pathlib.Path.cwd() / sofile.name)
#else:
# else:
# raise SystemExit("Error: Unable to copy module from temporary directory")

############################################################
Expand Down Expand Up @@ -1200,7 +1196,7 @@ def main():
if outfile and mode != PREPROCESS and mode != DOCUMENT:
raise SystemExit("Error: Can only specify -o when preprocessing or documenting")

#if mode == MODINC:
# if mode == MODINC:
# if args:
# raise SystemExit(
# "Error: Can not specify input files when using --print-modinc")
Expand Down
6 changes: 2 additions & 4 deletions src/executables/halcmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ if(BUILD_HALCMD_EXECUTABLE)

target_sources(halcmd PRIVATE ${SOURCE_FILES} ${PRIVATE_HEADER_FILES})

target_compile_definitions(halcmd PRIVATE "ULAPI")

pkg_check_modules(AVAHICLIENT "avahi-client" REQUIRED IMPORTED_TARGET)
pkg_check_modules(PROTOBUF "protobuf" REQUIRED IMPORTED_TARGET)

# TODO: Needed just because of the config.h??
target_link_libraries(
halcmd
PRIVATE runtime
hal
PRIVATE unmanaged_runtime
unmanaged_hal
hal_command
mkini
PkgConfig::AVAHICLIENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,14 @@ function(add_instantiatable_module target_name)
add_library(${target_name} MODULE)
target_sources(${target_name} PRIVATE ${preprocessed_c_source_file})

target_link_libraries(${target_name} PRIVATE hal_api runtime_api)
target_link_libraries(${target_name} PRIVATE managed_hal managed_runtime)

if(${prefix}_LINK_LIBRARIES)
target_link_libraries(${target_name} PRIVATE ${${prefix}_LINK_LIBRARIES})
endif()

export_rtapi_symbols(TARGET ${target_name})

target_compile_definitions(${target_name} PRIVATE "RTAPI")

set_target_properties(
${target_name} PROPERTIES OUTPUT_NAME "${source_file_stem}" PREFIX "mod")

Expand Down
6 changes: 2 additions & 4 deletions src/executables/instcomp/src/instcomp.g
Original file line number Diff line number Diff line change
Expand Up @@ -1082,13 +1082,11 @@ add_library({module_name} MODULE)
target_sources({module_name} PRIVATE {c_source_file})
target_link_libraries({module_name}
PRIVATE Machinekit::HAL::hal_api
Machinekit::HAL::runtime_api)
PRIVATE Machinekit::HAL::managed_hal
Machinekit::HAL::managed_runtime)
export_rtapi_symbols(TARGET {module_name})
target_compile_definitions({module_name} PRIVATE "RTAPI")
set_target_properties(
{module_name}
PROPERTIES OUTPUT_NAME "{module_name}"
Expand Down
4 changes: 1 addition & 3 deletions src/executables/mksocmemio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm.*")

target_sources(mksocmemio PRIVATE ${SOURCE_FILES})

target_link_libraries(mksocmemio PRIVATE runtime_api hal_api)

target_compile_definitions(mksocmemio PRIVATE "ULAPI")
target_link_libraries(mksocmemio PRIVATE unmanaged_runtime unmanaged_hal)

install(TARGETS mksocmemio
RUNTIME DESTINATION "${MACHINEKIT_HAL_EXECUTABLE_DIRECTORY}"
Expand Down
27 changes: 0 additions & 27 deletions src/executables/mksocmemio/src/mksocmemio.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,6 @@
#define MAXUIOIDS 100
#define MAXNAMELEN 256

// filename is printf-style
int rtapi_fs_read(char *buf, const size_t maxlen, const char *name, ...)
{
char fname[4096];
va_list args;

va_start(args, name);
size_t len = vsnprintf(fname, sizeof(fname), name, args);
va_end(args);

if (len < 1)
return -EINVAL; // name too short

int fd, rc;
if ((fd = open(fname, O_RDONLY)) >= 0) {
rc = read(fd, buf, maxlen);
close(fd);
if (rc < 0)
return -errno;
char *s = strchr(buf, '\n');
if (s) *s = '\0';
return strlen(buf);
} else {
return -errno;
}
}

static void show_usage(void)
{
printf("mksocmemio: Utility to read or write hm2socfpga memory locatons\n");
Expand Down
4 changes: 2 additions & 2 deletions src/executables/msgd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ if(BUILD_MSGD_EXECUTABLE)

target_link_libraries(
msgd
PRIVATE runtime
hal
PRIVATE unmanaged_runtime
unmanaged_hal
runtime_memory_api
mkini
machinetalk
Expand Down
5 changes: 2 additions & 3 deletions src/executables/mutexwatch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ if(BUILD_MUTEXWATCH_EXECUTABLE)
# TODO: Use FindLibRT CMake module or not?
find_library(RT "rt" REQUIRED)

target_link_libraries(mutexwatch PRIVATE runtime hal runtime_memory_api ${RT})

target_compile_definitions(mutexwatch PRIVATE "ULAPI")
target_link_libraries(mutexwatch PRIVATE unmanaged_runtime unmanaged_hal
runtime_memory_api ${RT})

install(TARGETS mutexwatch
RUNTIME DESTINATION "${MACHINEKIT_HAL_EXECUTABLE_DIRECTORY}"
Expand Down
3 changes: 2 additions & 1 deletion src/executables/npbdecode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ if(BUILD_NPBDECODE_EXECUTABLE)

target_sources(npbdecode PRIVATE ${SOURCE_FILES})

target_link_libraries(npbdecode PRIVATE machinetalk machinetalk_proto_c)
target_link_libraries(npbdecode PRIVATE machinetalk machinetalk_proto_c
protobuf-nanopb-static)

target_compile_definitions(npbdecode PRIVATE "PB_FIELD_32BIT")

Expand Down
Loading

0 comments on commit f6a35e6

Please sign in to comment.