diff --git a/.github/workflows/build-software.yml b/.github/workflows/build-software.yml index 62c3cfd..46cc4fc 100644 --- a/.github/workflows/build-software.yml +++ b/.github/workflows/build-software.yml @@ -7,10 +7,12 @@ on: - "v*.*.*" pull_request: branches: [ main ] + workflow_dispatch: jobs: build: runs-on: ${{ matrix.sys.os }} + container: ${{ matrix.sys.container }} strategy: # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. @@ -18,31 +20,54 @@ jobs: matrix: sys: - - { os: ubuntu-latest, shell: bash, c_compiler: gcc, binary_orig: digilivolo, binary_target: digilivolo-linux-x86_64 } - - { os: ubuntu-latest, shell: bash, c_compiler: clang } - - { os: windows-latest, shell: 'msys2 {0}', c_compiler: gcc, binary_orig: digilivolo.exe, binary_target: digilivolo-win-x86_64.exe } - - { os: windows-latest, shell: pwsh, c_compiler: gcc } - - { os: windows-latest, shell: pwsh, c_compiler: clang } + - { os: ubuntu-latest, container: 'ghcr.io/phusion/holy-build-box/hbb-64', shell: bash , c_compiler: gcc , binary_orig: digilivolo } + - { os: ubuntu-latest, container: 'debian:10' , shell: bash , c_compiler: gcc , binary_orig: digilivolo } + - { os: ubuntu-20.04 , shell: bash , c_compiler: gcc , binary_orig: digilivolo , binary_release: digilivolo-linux-x86_64 } + - { os: ubuntu-latest, container: 'debian' , shell: bash , crosscompile: armhf, binary_orig: digilivolo , binary_release: digilivolo-linux-armhf } + - { os: ubuntu-latest, container: 'debian' , shell: bash , crosscompile: arm64, binary_orig: digilivolo , binary_release: digilivolo-linux-arm64 } + - { os: ubuntu-20.04 , shell: bash , c_compiler: clang , binary_orig: digilivolo } + - { os: windows-latest , shell: 'msys2 {0}', c_compiler: gcc , binary_orig: digilivolo.exe, binary_release: digilivolo-win-x86_64.exe } + - { os: windows-latest , shell: pwsh , c_compiler: gcc , binary_orig: digilivolo.exe } + - { os: windows-latest , shell: pwsh , c_compiler: clang , binary_orig: digilivolo.exe } build_type: [Release] + defaults: run: shell: ${{ matrix.sys.shell }} steps: - - uses: ConorMacBride/install-package@v1 + + - name: Install required prerequisite packages on the container and configure git + if: matrix.sys.container != '' + run: | + apt update || yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm + apt -y full-upgrade || yum update -y + apt install -y sudo git dialog python3 python3-pip python3-setuptools curl wget || yum install -y sudo git dialog python3 python3-pip python3-setuptools ninja-build make cmake3 libusb-devel libudev-devel curl wget + git --version + git config --global --add safe.directory /__w/dl/dl + echo + cat /etc/os-release + + - name: Install packages required for the workflow and build deps + uses: ConorMacBride/install-package@v1 + if: matrix.sys.container != 'ghcr.io/phusion/holy-build-box/hbb-64' with: - apt: libudev-dev - - - uses: actions/checkout@v4 + apt: libudev-dev sudo gcc cmake build-essential make sudo libusb-dev libc6-dev pkg-config file ninja-build clang + + - name: Checkout repo + uses: actions/checkout@v3 with: submodules: 'recursive' + - name: '[HBB] Create symlink cmake -> cmake3' + if: matrix.sys.container == 'ghcr.io/phusion/holy-build-box/hbb-64' + run: ln -s /usr/bin/cmake3 /usr/bin/cmake + - name: Install Ninja - if: matrix.sys.shell != 'msys2 {0}' - id: ninja + if: matrix.sys.shell == 'pwsh' uses: turtlesec-no/get-ninja@main - - name: 'Setup MSYS2' + - name: Setup MSYS2 UCRT64 if: matrix.sys.shell == 'msys2 {0}' uses: msys2/setup-msys2@v2 with: @@ -57,31 +82,53 @@ jobs: cmake:p ninja:p - - name: Configure CMake + - name: Install cross compiling toolchain and deps + if: ${{ matrix.sys.crosscompile != '' }} + shell: bash + run: | + echo "Installing cross toolchain for ${{ matrix.sys.crosscompile }}" + sudo dpkg --add-architecture ${{ matrix.sys.crosscompile }} + sudo apt update + sudo apt install -y crossbuild-essential-${{ matrix.sys.crosscompile }} + sudo apt install -y libudev-dev:${{ matrix.sys.crosscompile }} libusb-dev:${{ matrix.sys.crosscompile }} libc6-dev:${{ matrix.sys.crosscompile }} pkg-config:${{ matrix.sys.crosscompile }} + + - name: Configure CMake project run: > - cmake -B software/build - -DCMAKE_C_COMPILER=${{ matrix.sys.c_compiler }} + cmake -B software/build ${{ env.CMAKE_TOOLCHAIN_FILE_OPT }} ${{ env.CMAKE_C_COMPILER_OPT }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DUSE_SYSTEM_HIDAPI=false -G Ninja -S software + env: + CMAKE_TOOLCHAIN_FILE_OPT: ${{ matrix.sys.crosscompile == '' && ' ' || format('-DCMAKE_TOOLCHAIN_FILE=cmake/{0}-linux-toolchain.cmake', matrix.sys.crosscompile) }} + CMAKE_C_COMPILER_OPT: ${{ matrix.sys.c_compiler == '' && ' ' || format('-DCMAKE_C_COMPILER={0}', matrix.sys.c_compiler) }} - - name: Build + - name: Build software run: cmake --build software/build - - name: Rename binary - if: ${{ matrix.sys.binary_target != '' }} + - name: Print some info on compiled binary + shell: bash + run: | + echo "=== objdump -x ===" + objdump -x software/build/${{ matrix.sys.binary_orig }} || /bin/true + echo "=== size -A ===" + size -A software/build/${{ matrix.sys.binary_orig }} || /bin/true + echo "=== ldd -v ===" + ldd -v software/build/${{ matrix.sys.binary_orig }} || /bin/true + echo "=== file & ls ===" + file software/build/${{ matrix.sys.binary_orig }} || /bin/true + ls -l software/build/${{ matrix.sys.binary_orig }} || /bin/true + + - name: Rename binary to release target + if: ${{ matrix.sys.binary_release != '' }} shell: bash run: | - mv software/build/${{ matrix.sys.binary_orig }} software/build/${{ matrix.sys.binary_target }} - ls -l software/build/${{ matrix.sys.binary_target }} - file software/build/${{ matrix.sys.binary_target }} + mv software/build/${{ matrix.sys.binary_orig }} software/build/${{ matrix.sys.binary_release }} - name: Make and upload release - uses: softprops/action-gh-release@v2 - if: startsWith(github.ref, 'refs/tags/') && matrix.sys.binary_target != '' + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') && matrix.sys.binary_release != '' with: fail_on_unmatched_files: false generate_release_notes: true - make_latest: true - files: software/build/${{ matrix.sys.binary_target }} + files: software/build/${{ matrix.sys.binary_release }} diff --git a/.gitignore b/.gitignore index 259148f..107977e 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ *.exe *.out *.app + +*.bak diff --git a/README.md b/README.md index 7698787..c5f2b5c 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ USB HID Reports. As well as other various improvements. Download compiled firmware from [releases page](https://github.com/N-Storm/DigiLivolo/releases) or build from sources (see below for instructions). -Software binaries for Linux/Windows x86_64 can be downloaded from +Software binaries for Windows x64, Linux x86_64 and ARM can be downloaded from [releases page](https://github.com/N-Storm/DigiLivolo/releases) as well. Instructions for building from sources are provided below. @@ -135,9 +135,11 @@ it from there. Requires PlatformIO plugin installed. From the `DigiLivolo/software` directory: ```shell -cmake -Wno-dev -B ./build . && cmake --build ./build +cmake -DCMAKE_BUILD_TYPE=Release -Wno-dev -B ./build . && cmake --build ./build ``` +Or simply run `bash build.sh` script from this directory. + For building on Windows [MSYS2](https://www.msys2.org/) UCRT64 has been tested to work. Resulting binary should be compiled as `build/digilivolo[.exe]`. diff --git a/software/CMakeLists.txt b/software/CMakeLists.txt index 245309a..221d584 100644 --- a/software/CMakeLists.txt +++ b/software/CMakeLists.txt @@ -2,11 +2,14 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR) set(PROJECT_NAME "digilivolo") project(${PROJECT_NAME} C) +option(USE_SYSTEM_HIDAPI "Don't build included hidapi, use system installed version instead" FALSE) +option(HIDAPI_WITH_LIBUSB "Build hidapi with libusb interface" FALSE) +option(BUILD_SHARED_LIBS "Link target & deps dynamically where possible" FALSE) + if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -std=gnu11 -flto -ffunction-sections -fdata-sections -ffat-lto-objects -Wall -Wl,--warn-common -Wl,--gc-sections") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og -std=gnu11 -Wall -Wl,--warn-common") endif() -set(HIDAPI_WITH_LIBUSB FALSE) -set(BUILD_SHARED_LIBS FALSE) # HIDAPI as static library on all platforms if(POLICY CMP0074) # allow using hidapi_ROOT if CMake supports it @@ -27,26 +30,32 @@ execute_process( message(STATUS "Project: ${PROJECT_NAME} ${GIT_VERSION}") -if(NOT USE_SYSTEM_HIDAPI) - add_subdirectory(lib/hidapi) - message(STATUS "hidapi will be built from sources") -else() - message(STATUS "Finding library hidapi") - find_package(hidapi 0.13 REQUIRED) -endif() - -message(STATUS "Using HIDAPI: ${hidapi_VERSION}") - -add_subdirectory(lib/argp-standalone) - configure_file(src/git_version.h.in src/git_version.h @ONLY) add_executable(${PROJECT_NAME} src/args.c src/digilivolo.c src/usb_func.c) target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/src") -target_link_libraries(${PROJECT_NAME} hidapi::hidapi argp-standalone) + +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +find_package(argp) + +if(NOT ARGP_FOUND) + add_subdirectory(lib/argp-standalone) + target_link_libraries(${PROJECT_NAME} argp-standalone) +endif() + +if(USE_SYSTEM_HIDAPI) + message(STATUS "Finding library hidapi") + find_package(HIDAPI 0.13 REQUIRED) + target_link_libraries(${PROJECT_NAME} HIDAPI::hidapi) +else() + add_subdirectory(lib/hidapi) + message(STATUS "hidapi will be built from sources") + target_link_libraries(${PROJECT_NAME} hidapi::hidapi) + message(STATUS "Using HIDAPI: ${hidapi_VERSION}") +endif() # Strip binary for release builds add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_STRIP} $ + COMMAND $<$:${CMAKE_STRIP}> $<$:$> VERBATIM ) diff --git a/software/build.sh b/software/build.sh index 65d96f5..9ab2964 100644 --- a/software/build.sh +++ b/software/build.sh @@ -20,7 +20,7 @@ fi # cmake -DUSE_SYSTEM_HIDAPI=false -B ${SCRIPT_DIR}/build -G 'Unix Makefiles' ${SCRIPT_DIR} # cmake -DUSE_SYSTEM_HIDAPI=false -B ${SCRIPT_DIR}/build -G 'Ninja' -Wno-dev ${SCRIPT_DIR} -cmake -DUSE_SYSTEM_HIDAPI=false -Wno-dev -B ${SCRIPT_DIR}/build ${SCRIPT_DIR} +cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_HIDAPI=false -Wno-dev -B ${SCRIPT_DIR}/build ${SCRIPT_DIR} cmake --build ${SCRIPT_DIR}/build diff --git a/software/cmake/FindHIDAPI.cmake b/software/cmake/FindHIDAPI.cmake new file mode 100644 index 0000000..fc0e3cd --- /dev/null +++ b/software/cmake/FindHIDAPI.cmake @@ -0,0 +1,234 @@ +#.rst: +# FindHIDAPI +# ---------- +# https://github.com/rpavlik/cmake-modules +# +# Try to find HIDAPI library, from http://www.signal11.us/oss/hidapi/ +# +# Cache Variables: (probably not for direct use in your scripts) +# HIDAPI_INCLUDE_DIR +# HIDAPI_LIBRARY +# +# Non-cache variables you might use in your CMakeLists.txt: +# HIDAPI_FOUND +# HIDAPI_INCLUDE_DIRS +# HIDAPI_LIBRARIES +# +# COMPONENTS +# ^^^^^^^^^^ +# +# This module respects several COMPONENTS specifying the backend you prefer: +# ``any`` (the default), ``libusb``, and ``hidraw``. +# The availablility of the latter two depends on your platform. +# +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines :prop_tgt:`IMPORTED` target ``HIDAPI::hidapi`` (in all cases or +# if no components specified), ``HIDAPI::hidapi-libusb`` (if you requested the libusb component), +# and ``HIDAPI::hidapi-hidraw`` (if you requested the hidraw component), +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# ``HIDAPI_FOUND`` +# True if HIDAPI or the requested components (if any) were found. +# +# We recommend using the imported targets instead of the following. +# +# ``HIDAPI_INCLUDE_DIRS`` +# ``HIDAPI_LIBRARIES`` +# +# Original Author: +# 2009-2021 Rylie Pavlik +# https://ryliepavlik.com/ +# +# Copyright 2009-2010, Iowa State University +# Copyright 2019-2021, Collabora, Ltd. +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) +# +# SPDX-License-Identifier: BSL-1.0 + +set(HIDAPI_ROOT_DIR + "${HIDAPI_ROOT_DIR}" + CACHE PATH "Root to search for HIDAPI") + +# Clean up components +if(HIDAPI_FIND_COMPONENTS) + if(WIN32 OR APPLE) + # This makes no sense on Windows or Mac, which have native APIs + list(REMOVE HIDAPI_FIND_COMPONENTS libusb) + endif() + + if(NOT ${CMAKE_SYSTEM} MATCHES "Linux") + # hidraw is only on linux + list(REMOVE HIDAPI_FIND_COMPONENTS hidraw) + endif() +endif() +if(NOT HIDAPI_FIND_COMPONENTS) + # Default to any + set(HIDAPI_FIND_COMPONENTS any) +endif() + +# Ask pkg-config for hints +if(NOT ANDROID) + find_package(PkgConfig QUIET) + if(PKG_CONFIG_FOUND) + set(_old_prefix_path "${CMAKE_PREFIX_PATH}") + # So pkg-config uses HIDAPI_ROOT_DIR too. + if(HIDAPI_ROOT_DIR) + list(APPEND CMAKE_PREFIX_PATH ${HIDAPI_ROOT_DIR}) + endif() + pkg_check_modules(PC_HIDAPI_LIBUSB QUIET hidapi-libusb) + pkg_check_modules(PC_HIDAPI_HIDRAW QUIET hidapi-hidraw) + # Restore + set(CMAKE_PREFIX_PATH "${_old_prefix_path}") + endif() +endif() + +# Actually search +find_library( + HIDAPI_UNDECORATED_LIBRARY + NAMES hidapi + PATHS "${HIDAPI_ROOT_DIR}" + PATH_SUFFIXES lib) + +find_library( + HIDAPI_LIBUSB_LIBRARY + NAMES hidapi hidapi-libusb + PATHS "${HIDAPI_ROOT_DIR}" + PATH_SUFFIXES lib + HINTS ${PC_HIDAPI_LIBUSB_LIBRARY_DIRS}) + +if(CMAKE_SYSTEM MATCHES "Linux") + find_library( + HIDAPI_HIDRAW_LIBRARY + NAMES hidapi-hidraw + HINTS ${PC_HIDAPI_HIDRAW_LIBRARY_DIRS}) +endif() + +find_path( + HIDAPI_INCLUDE_DIR + NAMES hidapi.h + PATHS "${HIDAPI_ROOT_DIR}" + PATH_SUFFIXES hidapi include include/hidapi + HINTS ${PC_HIDAPI_HIDRAW_INCLUDE_DIRS} ${PC_HIDAPI_LIBUSB_INCLUDE_DIRS}) + +find_package(Threads QUIET) + +### +# Compute the "I don't care which backend" library +### +set(HIDAPI_LIBRARY) + +# First, try to use a preferred backend if supplied +if("${HIDAPI_FIND_COMPONENTS}" MATCHES "libusb" + AND HIDAPI_LIBUSB_LIBRARY + AND NOT HIDAPI_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_LIBUSB_LIBRARY}) +endif() +if("${HIDAPI_FIND_COMPONENTS}" MATCHES "hidraw" + AND HIDAPI_HIDRAW_LIBRARY + AND NOT HIDAPI_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_HIDRAW_LIBRARY}) +endif() + +# Then, if we don't have a preferred one, settle for anything. +if(NOT HIDAPI_LIBRARY) + if(HIDAPI_LIBUSB_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_LIBUSB_LIBRARY}) + elseif(HIDAPI_HIDRAW_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_HIDRAW_LIBRARY}) + elseif(HIDAPI_UNDECORATED_LIBRARY) + set(HIDAPI_LIBRARY ${HIDAPI_UNDECORATED_LIBRARY}) + endif() +endif() + +### +# Determine if the various requested components are found. +### +set(_hidapi_component_required_vars) + +foreach(_comp IN LISTS HIDAPI_FIND_COMPONENTS) + if("${_comp}" STREQUAL "any") + list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR + HIDAPI_LIBRARY) + if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_LIBRARY}") + set(HIDAPI_any_FOUND TRUE) + mark_as_advanced(HIDAPI_INCLUDE_DIR) + else() + set(HIDAPI_any_FOUND FALSE) + endif() + + elseif("${_comp}" STREQUAL "libusb") + list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR + HIDAPI_LIBUSB_LIBRARY) + if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_LIBUSB_LIBRARY}") + set(HIDAPI_libusb_FOUND TRUE) + mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBUSB_LIBRARY) + else() + set(HIDAPI_libusb_FOUND FALSE) + endif() + + elseif("${_comp}" STREQUAL "hidraw") + list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR + HIDAPI_HIDRAW_LIBRARY) + if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_HIDRAW_LIBRARY}") + set(HIDAPI_hidraw_FOUND TRUE) + mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_HIDRAW_LIBRARY) + else() + set(HIDAPI_hidraw_FOUND FALSE) + endif() + + else() + message(WARNING "${_comp} is not a recognized HIDAPI component") + set(HIDAPI_${_comp}_FOUND FALSE) + endif() +endforeach() +unset(_comp) + +### +# FPHSA call +### +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + HIDAPI + REQUIRED_VARS ${_hidapi_component_required_vars} THREADS_FOUND + HANDLE_COMPONENTS) +if(HIDAPI_FOUND) + set(HIDAPI_LIBRARIES "${HIDAPI_LIBRARY}") + set(HIDAPI_INCLUDE_DIRS "${HIDAPI_INCLUDE_DIR}") + if(NOT TARGET HIDAPI::hidapi) + add_library(HIDAPI::hidapi UNKNOWN IMPORTED) + set_target_properties( + HIDAPI::hidapi + PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${HIDAPI_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${HIDAPI_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads) + endif() +endif() + +if(HIDAPI_libusb_FOUND AND NOT TARGET HIDAPI::hidapi-libusb) + add_library(HIDAPI::hidapi-libusb UNKNOWN IMPORTED) + set_target_properties( + HIDAPI::hidapi-libusb + PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${HIDAPI_LIBUSB_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${HIDAPI_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads) +endif() + +if(HIDAPI_hidraw_FOUND AND NOT TARGET HIDAPI::hidapi-hidraw) + add_library(HIDAPI::hidapi-hidraw UNKNOWN IMPORTED) + set_target_properties( + HIDAPI::hidapi-hidraw + PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${HIDAPI_HIDRAW_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${HIDAPI_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads) +endif() diff --git a/software/cmake/Findargp.cmake b/software/cmake/Findargp.cmake new file mode 100644 index 0000000..3999991 --- /dev/null +++ b/software/cmake/Findargp.cmake @@ -0,0 +1,88 @@ +# This file is part of CMake-argp. +# +# https://github.com/alehaa/CMake-argp/ +# +# CMake-argp 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 3 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 General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with this program. If not, see +# +# http://www.gnu.org/licenses/ +# +# +# Copyright (c) +# 2016-2017 Alexander Haase +# + +include(CheckFunctionExists) +include(FindPackageHandleStandardArgs) +include(FindPackageMessage) + + +# Do the following checks for header, library and argp functions quietly. Only +# print the result at the end of this file. +set(CMAKE_REQUIRED_QUIET TRUE) + + +# First check if argp is shipped together with libc without linking to any other +# library or including any paths. In that case, no files for argp need to be +# searched and argp may be used out-of-the-box. +check_function_exists("argp_parse" ARGP_IN_LIBC) +if (ARGP_IN_LIBC) + # Set the argp library- and include-paths to empty values, otherwise CMake + # might print warnings about unknown variables and fills them with + # 'xy-NOTFOUND'. + set(ARGP_FOUND TRUE) + set(ARGP_LIBRARIES "") + set(ARGP_INCLUDE_PATH "") + + # Print a message, that argp has been successfully found and return from + # this module, as argp doesn't need to be searched as a separate library. + find_package_message(argp "Found argp: built-in" "built-in") + return() +endif() + + +# Argp is not part of the libc, so it needs to be searched as a separate library +# with its own include directory. +# +# First search the argp header file. If it is not found, any further steps will +# fail. +find_path(ARGP_INCLUDE_PATH "argp.h") +if (ARGP_INCLUDE_PATH) + # Try to find the argp library and check if it has the required argp_parse + # function. + set(CMAKE_REQUIRED_INCLUDES "${ARGP_INCLUDE_PATH}") + find_library(ARGP_LIBRARIES "argp") + + # Check if argp_parse is available. Some implementations don't have this + # symbol defined, thus they're not compatible. + if (ARGP_LIBRARIES) + set(CMAKE_REQUIRED_LIBRARIES "${ARGP_LIBRARIES}") + check_function_exists("argp_parse" ARGP_EXTERNAL) + if (NOT ARGP_EXTERNAL) + message(FATAL_ERROR "Your system ships an argp library in " + "${ARGP_LIBRARIES}, but it does not have a symbol " + "named argp_parse.") + endif () + endif () +endif () + + +# Restore the quiet settings. By default the last check should be printed if not +# disabled in the find_package call. +set(CMAKE_REQUIRED_QUIET ${argp_FIND_QUIETLY}) + + +# Check for all required variables. +find_package_handle_standard_args(argp + DEFAULT_MSG + ARGP_LIBRARIES ARGP_INCLUDE_PATH) +mark_as_advanced(ARGP_LIBRARIES ARGP_INCLUDE_PATH) diff --git a/software/cmake/arm64-linux-toolchain.cmake b/software/cmake/arm64-linux-toolchain.cmake new file mode 100644 index 0000000..d37fc5d --- /dev/null +++ b/software/cmake/arm64-linux-toolchain.cmake @@ -0,0 +1,14 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +SET (TRIPLET aarch64-linux-gnu) +SET(CMAKE_C_COMPILER ${TRIPLET}-gcc) + +# We have cross pkg-config installed instead +SET(PKG_CONFIG_EXECUTABLE ${TRIPLET}-pkg-config) + +# search for programs in the build host directories +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# for libraries and headers in the target directories +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/software/cmake/arm-linux-gnueabihf-gcc-toolchain.cmake b/software/cmake/armhf-linux-toolchain.cmake similarity index 100% rename from software/cmake/arm-linux-gnueabihf-gcc-toolchain.cmake rename to software/cmake/armhf-linux-toolchain.cmake diff --git a/software/src/digilivolo.c b/software/src/digilivolo.c index fefe723..e8be8ca 100644 --- a/software/src/digilivolo.c +++ b/software/src/digilivolo.c @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) dl_dev = find_digilivolo(devices); if (!dl_dev) { printf("ERROR: unable to find device\n"); - if (arguments.verbose) + if (arguments.verbose) { if (devices) { printf("Devices with matching VID/PID (0x%04x:0x%04x), but wrong product or manufacturer string:\n", DIGILIVOLO_VID, DIGILIVOLO_PID); print_devices(devices); @@ -84,6 +84,7 @@ int main(int argc, char* argv[]) printf("All enumerated devices, but none of them match VID/PID (0x%04x:0x%04x):\n", DIGILIVOLO_VID, DIGILIVOLO_PID); print_devices(devices); } + } } else { if (arguments.verbose) { diff --git a/software/src/git_version.h b/software/src/git_version.h new file mode 100644 index 0000000..468ce2f --- /dev/null +++ b/software/src/git_version.h @@ -0,0 +1,26 @@ +/* Part of the DigiLivolo control software. + * https://github.com/N-Storm/DigiLivolo/ + * Copyright (c) 2024 GitHub user N-Storm. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef GIT_VERSION_H +#define GIT_VERSION_H + +#define GIT_VERSION "v0.4.3" + +#endif // GIT_VERSION_H