Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CI

on: [push, pull_request]

jobs:
build:
name: ${{ matrix.toolchain.name }}
runs-on: ${{ matrix.toolchain.os }}

defaults:
run:
shell: bash

strategy:
fail-fast: false
matrix:
toolchain:
- name: Linux Clang
os: ubuntu-24.04
cmake_args: -DCMAKE_C_COMPILER=clang

- name: Linux GCC
os: ubuntu-24.04

- name: macOS ARM
os: macos-14

- name: macOS Intel
os: macos-13

- name: MinGW
os: windows-2022
cmake_args: -G "MinGW Makefiles"

- name: MSVC 32-bit
os: windows-2022
cmake_args: -A Win32

- name: MSVC 64-bit
os: windows-2022

steps:
- uses: actions/checkout@v4

- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update && sudo apt-get install libusb-1.0-0-dev

- name: Install Windows Dependencies
if: runner.os == 'Windows'
run: |
LIBUSB_VERSION=1.0.28
LIBUSB_PACKAGE=libusb-$LIBUSB_VERSION.7z
aria2c -q https://github.com/libusb/libusb/releases/download/v$LIBUSB_VERSION/$LIBUSB_PACKAGE
7z x $LIBUSB_PACKAGE -olibusb

- name: Install MinGW
if: startsWith(matrix.toolchain.name, 'MinGW')
uses: msys2/setup-msys2@v2

- name: Configure
run: |
cmake -B build ${{ matrix.toolchain.cmake_args }} .

- name: Get Number of CPU Cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores

- name: Build
run: |
export MAKEFLAGS=--keep-going
cmake --build build --config Release --parallel ${{ steps.cpu-cores.outputs.count }}

- name: Install Linux/macOS
if: runner.os != 'Windows'
run: |
sudo cmake --install build

- name: Test POSIX
if: ${{ !startsWith(matrix.toolchain.name, 'MSVC') }}
run: |
build/fobos_devinfo

- name: Test MSVC
if: startsWith(matrix.toolchain.name, 'MSVC')
run: |
build/Release/fobos_devinfo.exe

- name: List Build Directory
if: always()
run: |
git status
ls -lR build
196 changes: 99 additions & 97 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@
########################################################################
cmake_minimum_required(VERSION 3.7.2)

if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
project(fobos)
else()
project(fobos C)
endif()
project(fobos LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS OFF)

include(GNUInstallDirs)
message(>>> "CMAKE_INSTALL_LIBDIR: " ${CMAKE_INSTALL_LIBDIR})
set(CMAKE_C_FLAGS, "${CMAKE_C_FLAGS} -std=c99")
########################################################################

########################################################################
Expand All @@ -47,50 +44,81 @@ endif(NOT CMAKE_BUILD_TYPE)
########################################################################
# Compiler specific setup
########################################################################
if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
ADD_DEFINITIONS(-Wall)
ADD_DEFINITIONS(-Wextra)
ADD_DEFINITIONS(-Wno-unused-parameter)
ADD_DEFINITIONS(-Wno-unused)
ADD_DEFINITIONS(-Wsign-compare)
ADD_DEFINITIONS(-ansi)
elseif(MSVC14 OR MSVC14)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ADD_DEFINITIONS(-D_TIMESPEC_DEFINED)
if(MSVC)
add_definitions(
-D_CRT_SECURE_NO_WARNINGS
-D_TIMESPEC_DEFINED
)
else()
add_compile_options(
-Wall
-Wextra
-Wno-unused-parameter
-Wno-unused
-Wsign-compare
)
endif()
########################################################################

########################################################################
# Find build dependencies
########################################################################
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBUSB libusb-1.0 IMPORTED_TARGET)
if(LIBUSB_LINK_LIBRARIES)
set(LIBUSB_LIBRARIES "${LIBUSB_LINK_LIBRARIES}")
if(NOT DEFINED LIBUSB_INCLUDE_DIRS OR NOT DEFINED LIBUSB_LIBRARIES)
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBUSB libusb-1.0 IMPORTED_TARGET)
if(NOT LIBUSB_FOUND)
message(FATAL_ERROR "LibUSB 1.0 required")
else()
set(LIBUSB_LIBRARIES "${LIBUSB_LINK_LIBRARIES}")
endif()
else()
if(MSVC)
if(MSVC_VERSION EQUAL 1800)
set(LIBUSB_SUFFIX VS2013)
elseif(MSVC_VERSION EQUAL 1900)
set(LIBUSB_SUFFIX VS2015)
elseif((MSVC_VERSION GREATER_EQUAL 1910) AND (MSVC_VERSION LESS_EQUAL 1919))
set(LIBUSB_SUFFIX VS2017)
elseif((MSVC_VERSION GREATER_EQUAL 1920) AND (MSVC_VERSION LESS_EQUAL 1929))
set(LIBUSB_SUFFIX VS2019)
else()
set(LIBUSB_SUFFIX VS2022)
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(LIBUSB_SUFFIX "${LIBUSB_SUFFIX}/MS32")
else()
set(LIBUSB_SUFFIX "${LIBUSB_SUFFIX}/MS64")
endif()

set(LIBUSB_SUFFIX "${LIBUSB_SUFFIX}/dll")
elseif(MINGW)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(LIBUSB_SUFFIX "MinGW32")
else()
set(LIBUSB_SUFFIX "MinGW64")
endif()

set(LIBUSB_SUFFIX "${LIBUSB_SUFFIX}/dll/libusb-1.0.dll")
endif()

set(LIBUSB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libusb/include)
set(LIBUSB_LIBRARIES ${CMAKE_SOURCE_DIR}/libusb/${LIBUSB_SUFFIX})
endif()
else()
if (CMAKE_VS_PLATFORM_NAME STREQUAL Win32)
set(LIBUSB_LIBRARIES ${CMAKE_SOURCE_DIR}/libusb/MS32/dll)
endif()
if (CMAKE_VS_PLATFORM_NAME STREQUAL x64)
set(LIBUSB_LIBRARIES ${CMAKE_SOURCE_DIR}/libusb/MS64/dll)
endif()
set(LIBUSB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libusb/include)
endif()
if(PKG_CONFIG_FOUND AND NOT LIBUSB_FOUND)
message(FATAL_ERROR "LibUSB 1.0 required")
endif()
########################################################################

########################################################################
# Install udev rules
########################################################################
install(
FILES fobos-sdr.rules
DESTINATION "/etc/udev/rules.d"
COMPONENT "udev"
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
install(
FILES fobos-sdr.rules
DESTINATION "/etc/udev/rules.d"
COMPONENT "udev"
)
endif()
########################################################################

########################################################################
Expand All @@ -108,44 +136,46 @@ message(>>> "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR})
########################################################################
add_library(libfobos SHARED fobos/fobos.c)

target_compile_options(libfobos PUBLIC -std=c99)

if(MSVC)
target_compile_options(libfobos PUBLIC "/MT")
ADD_CUSTOM_COMMAND(TARGET libfobos
POST_BUILD
target_compile_options(libfobos PUBLIC "/MT")
add_custom_command(TARGET libfobos
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/Debug
COMMAND ${CMAKE_COMMAND} -E copy ${LIBUSB_LIBRARIES}/libusb-1.0.dll ${PROJECT_BINARY_DIR}/Debug
)
ADD_CUSTOM_COMMAND(TARGET libfobos
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/Release
COMMAND ${CMAKE_COMMAND} -E copy ${LIBUSB_LIBRARIES}/libusb-1.0.dll ${PROJECT_BINARY_DIR}/Release
)
else()
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBUSB_LIBRARIES}/libusb-1.0.dll ${PROJECT_BINARY_DIR}/Debug
)
add_custom_command(TARGET libfobos
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/Release
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBUSB_LIBRARIES}/libusb-1.0.dll ${PROJECT_BINARY_DIR}/Release
)
elseif(MINGW)
add_custom_command(TARGET libfobos
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBUSB_LIBRARIES} ${PROJECT_BINARY_DIR}/msys-usb-1.0.dll
)
endif()

if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
target_link_libraries(libfobos PRIVATE ${LIBUSB_LIBRARIES})
else()
if(MSVC)
target_link_directories(libfobos PRIVATE ${LIBUSB_LIBRARIES})
else()
target_link_libraries(libfobos PRIVATE ${LIBUSB_LIBRARIES})
endif()

target_include_directories(libfobos PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>/fobos
${LIBUSB_INCLUDE_DIRS}
)
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>/fobos
${LIBUSB_INCLUDE_DIRS}
)

set_target_properties(libfobos PROPERTIES DEFINE_SYMBOL "FOBOS_EXPORTS")
set_target_properties(libfobos PROPERTIES OUTPUT_NAME fobos)
########################################################################

########################################################################
# Install public header files
########################################################################
INSTALL(
install(
FILES fobos/fobos.h
DESTINATION include
)
Expand All @@ -154,7 +184,7 @@ INSTALL(
########################################################################
# Install built library files & utilities
########################################################################
INSTALL(
install(
TARGETS libfobos
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
Expand All @@ -163,29 +193,29 @@ INSTALL(
########################################################################
# Create Pkg Config File
########################################################################
FOREACH(inc ${LIBUSB_INCLUDEDIR})
LIST(APPEND LIBFOBOS_PC_CFLAGS "-I${inc}")
ENDFOREACH(inc)
foreach(inc ${LIBUSB_INCLUDEDIR})
list(APPEND LIBFOBOS_PC_CFLAGS "-I${inc}")
endforeach(inc)

FOREACH(lib ${LIBUSB_LIBRARY_DIRS})
LIST(APPEND LIBFOBOS_PC_LIBS "-L${lib}")
ENDFOREACH(lib)
list(APPEND LIBFOBOS_PC_LIBS "-L${lib}")
endforeach(lib)

# use space-separation format for the pc file
STRING(REPLACE ";" " " LIBFOBOS_PC_CFLAGS "${LIBFOBOS_PC_CFLAGS}")
STRING(REPLACE ";" " " LIBFOBOS_PC_LIBS "${LIBFOBOS_PC_LIBS}")
string(REPLACE ";" " " LIBFOBOS_PC_CFLAGS "${LIBFOBOS_PC_CFLAGS}")
string(REPLACE ";" " " LIBFOBOS_PC_LIBS "${LIBFOBOS_PC_LIBS}")

set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix \${prefix})
set(includedir \${prefix}/include)
set(libdir \${exec_prefix}/lib)

CONFIGURE_FILE(
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/libfobos.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libfobos.pc
@ONLY)

INSTALL(
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libfobos.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
Expand All @@ -210,18 +240,8 @@ add_custom_target(uninstall
add_executable(fobos_devinfo
eval/fobos_devinfo_main.c)

target_compile_options(fobos_devinfo PUBLIC -std=c99)

target_link_libraries(fobos_devinfo PRIVATE libfobos)

if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
target_link_libraries(fobos_devinfo PRIVATE ${LIBUSB_LIBRARIES})
else()
target_link_directories(fobos_devinfo PRIVATE ${LIBUSB_LIBRARIES})
endif()

target_include_directories(fobos_devinfo PRIVATE ${CMAKE_SOURCE_DIR})

target_include_directories(fobos_devinfo PRIVATE ${CMAKE_SOURCE_DIR}/fobos)
########################################################################

Expand All @@ -232,16 +252,8 @@ add_executable(fobos_recorder
eval/fobos_recorder_main.c
wav/wav_file.c)

target_compile_options(fobos_recorder PUBLIC -std=c99)

target_link_libraries(fobos_recorder PRIVATE libfobos)

if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
target_link_libraries(fobos_recorder PRIVATE ${LIBUSB_LIBRARIES})
else()
target_link_directories(fobos_recorder PRIVATE ${LIBUSB_LIBRARIES})
endif()

target_include_directories(fobos_recorder PRIVATE ${CMAKE_SOURCE_DIR})

target_include_directories(fobos_recorder PRIVATE ${CMAKE_SOURCE_DIR}/fobos)
Expand All @@ -253,18 +265,8 @@ target_include_directories(fobos_recorder PRIVATE ${CMAKE_SOURCE_DIR}/fobos)
add_executable(fobos_fwloader
eval/fobos_fwloader_main.c)

target_compile_options(fobos_fwloader PUBLIC -std=c99)

target_link_libraries(fobos_fwloader PRIVATE libfobos)

if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
target_link_libraries(fobos_fwloader PRIVATE ${LIBUSB_LIBRARIES})
else()
target_link_directories(fobos_fwloader PRIVATE ${LIBUSB_LIBRARIES})
endif()

target_include_directories(fobos_fwloader PRIVATE ${CMAKE_SOURCE_DIR})

target_include_directories(fobos_fwloader PRIVATE ${CMAKE_SOURCE_DIR}/fobos)
########################################################################

Expand Down
Loading