Skip to content

Commit

Permalink
Merge pull request #95 from anarkiwi/clang2
Browse files Browse the repository at this point in the history
Run/enforce clang/cmakefile formatter.
  • Loading branch information
anarkiwi authored Aug 14, 2023
2 parents 733bfe9 + 362f786 commit 660f9f7
Show file tree
Hide file tree
Showing 29 changed files with 1,214 additions and 1,168 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ name: test
on: [push, pull_request]

jobs:
test-clang-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: clang-format
run: |
sudo apt-get update -yq && sudo apt-get install -yq clang-format python3-pip && pip3 install cmake_format && bin/run_c_format.sh $(pwd) lib include/gnuradio/iqtlabs
test-latest:
runs-on: ubuntu-latest
steps:
Expand Down
133 changes: 68 additions & 65 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# SPDX-License-Identifier: Apache-2.0
#

########################################################################
# ##############################################################################
# Project setup
########################################################################
# ##############################################################################
cmake_minimum_required(VERSION 3.8)
project(gr-iqtlabs CXX C)
enable_testing()
Expand All @@ -13,23 +13,31 @@ set(CMAKE_CXX_STANDARD 17)

# Install to PyBOMBS target prefix if defined
if(DEFINED ENV{PYBOMBS_PREFIX})
set(CMAKE_INSTALL_PREFIX $ENV{PYBOMBS_PREFIX})
message(STATUS "PyBOMBS installed GNU Radio. Setting CMAKE_INSTALL_PREFIX to $ENV{PYBOMBS_PREFIX}")
set(CMAKE_INSTALL_PREFIX $ENV{PYBOMBS_PREFIX})
message(
STATUS
"PyBOMBS installed GNU Radio. Setting CMAKE_INSTALL_PREFIX to $ENV{PYBOMBS_PREFIX}"
)
endif()

# Select the release build type by default to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: defaulting to release.")
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: defaulting to release.")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")
set(CMAKE_BUILD_TYPE
${CMAKE_BUILD_TYPE}
CACHE STRING "")

# Make sure our local CMake Modules path comes first
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/Modules)
# Find gnuradio to get access to the cmake modules
find_package(Gnuradio "3.9" REQUIRED)

find_package(Boost ${Boost_Version} COMPONENTS filesystem iostreams REQUIRED)
find_package(
Boost ${Boost_Version}
COMPONENTS filesystem iostreams
REQUIRED)

find_package(OpenCV 4 REQUIRED)
include_directories(${CMAKE_SOURCE_DIR}/include ${OpenCV_INCLUDE_DIRS})
Expand All @@ -38,94 +46,92 @@ find_package(libsigmf REQUIRED)

# Set the version information here
set(VERSION_MAJOR 1)
set(VERSION_API 0)
set(VERSION_ABI 0)
set(VERSION_API 0)
set(VERSION_ABI 0)
set(VERSION_PATCH 0)

cmake_policy(SET CMP0011 NEW)

# Enable generation of compile_commands.json for code completion engines
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

########################################################################
# ##############################################################################
# Minimum Version Requirements
########################################################################
# ##############################################################################

# include(GrMinReq)

########################################################################
# ##############################################################################
# Compiler settings
########################################################################
# ##############################################################################

# include(GrCompilerSettings)

########################################################################
# ##############################################################################
# Install directories
########################################################################
# ##############################################################################
include(GrVersion)

include(GrPlatform) #define LIB_SUFFIX
include(GrPlatform) # define LIB_SUFFIX

if(NOT CMAKE_MODULES_DIR)
set(CMAKE_MODULES_DIR lib${LIB_SUFFIX}/cmake)
endif(NOT CMAKE_MODULES_DIR)

set(GR_INCLUDE_DIR include/gnuradio/iqtlabs)
set(GR_CMAKE_DIR ${CMAKE_MODULES_DIR}/gnuradio-iqtlabs)
set(GR_PKG_DATA_DIR ${GR_DATA_DIR}/${CMAKE_PROJECT_NAME})
set(GR_PKG_DOC_DIR ${GR_DOC_DIR}/${CMAKE_PROJECT_NAME})
set(GR_PKG_CONF_DIR ${GR_CONF_DIR}/${CMAKE_PROJECT_NAME}/conf.d)
set(GR_PKG_LIBEXEC_DIR ${GR_LIBEXEC_DIR}/${CMAKE_PROJECT_NAME})
set(GR_INCLUDE_DIR include/gnuradio/iqtlabs)
set(GR_CMAKE_DIR ${CMAKE_MODULES_DIR}/gnuradio-iqtlabs)
set(GR_PKG_DATA_DIR ${GR_DATA_DIR}/${CMAKE_PROJECT_NAME})
set(GR_PKG_DOC_DIR ${GR_DOC_DIR}/${CMAKE_PROJECT_NAME})
set(GR_PKG_CONF_DIR ${GR_CONF_DIR}/${CMAKE_PROJECT_NAME}/conf.d)
set(GR_PKG_LIBEXEC_DIR ${GR_LIBEXEC_DIR}/${CMAKE_PROJECT_NAME})

########################################################################
# ##############################################################################
# On Apple only, set install name and use rpath correctly, if not already set
########################################################################
# ##############################################################################
if(APPLE)
if(NOT CMAKE_INSTALL_NAME_DIR)
set(CMAKE_INSTALL_NAME_DIR
${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE
PATH "Library Install Name Destination Directory" FORCE)
endif(NOT CMAKE_INSTALL_NAME_DIR)
if(NOT CMAKE_INSTALL_RPATH)
set(CMAKE_INSTALL_RPATH
${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE
PATH "Library Install RPath" FORCE)
endif(NOT CMAKE_INSTALL_RPATH)
if(NOT CMAKE_BUILD_WITH_INSTALL_RPATH)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE
BOOL "Do Build Using Library Install RPath" FORCE)
endif(NOT CMAKE_BUILD_WITH_INSTALL_RPATH)
if(NOT CMAKE_INSTALL_NAME_DIR)
set(CMAKE_INSTALL_NAME_DIR
${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR}
CACHE PATH "Library Install Name Destination Directory" FORCE)
endif(NOT CMAKE_INSTALL_NAME_DIR)
if(NOT CMAKE_INSTALL_RPATH)
set(CMAKE_INSTALL_RPATH
${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR}
CACHE PATH "Library Install RPath" FORCE)
endif(NOT CMAKE_INSTALL_RPATH)
if(NOT CMAKE_BUILD_WITH_INSTALL_RPATH)
set(CMAKE_BUILD_WITH_INSTALL_RPATH
ON
CACHE BOOL "Do Build Using Library Install RPath" FORCE)
endif(NOT CMAKE_BUILD_WITH_INSTALL_RPATH)
endif(APPLE)

########################################################################
# ##############################################################################
# Find gnuradio build dependencies
########################################################################
# ##############################################################################
find_package(Doxygen)

########################################################################
# ##############################################################################
# Setup doxygen option
########################################################################
# ##############################################################################
if(DOXYGEN_FOUND)
option(ENABLE_DOXYGEN "Build docs using Doxygen" ON)
option(ENABLE_DOXYGEN "Build docs using Doxygen" ON)
else(DOXYGEN_FOUND)
option(ENABLE_DOXYGEN "Build docs using Doxygen" OFF)
option(ENABLE_DOXYGEN "Build docs using Doxygen" OFF)
endif(DOXYGEN_FOUND)

########################################################################
# ##############################################################################
# Create uninstall target
########################################################################
configure_file(
${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
@ONLY)
# ##############################################################################
configure_file(${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake @ONLY)

add_custom_target(uninstall
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
add_custom_target(uninstall ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)

########################################################################
# ##############################################################################
# Add subdirectories
########################################################################
# ##############################################################################
add_subdirectory(include/gnuradio/iqtlabs)
add_subdirectory(lib)
add_subdirectory(apps)
Expand All @@ -139,18 +145,15 @@ else(ENABLE_PYTHON)
message(STATUS "PYTHON and GRC components are disabled")
endif(ENABLE_PYTHON)

########################################################################
# ##############################################################################
# Install cmake search helper for this library
########################################################################
# ##############################################################################

install(FILES cmake/Modules/gnuradio-iqtlabsConfig.cmake
DESTINATION ${GR_CMAKE_DIR}
)
DESTINATION ${GR_CMAKE_DIR})

include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/Modules/targetConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/Modules/${target}Config.cmake
INSTALL_DESTINATION ${GR_CMAKE_DIR}
)

${PROJECT_SOURCE_DIR}/cmake/Modules/targetConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/Modules/${target}Config.cmake
INSTALL_DESTINATION ${GR_CMAKE_DIR})
19 changes: 19 additions & 0 deletions bin/run_c_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

for dir in $* ; do
for cfile in "$dir"/*.[hc]* ; do
if [ -f "$cfile" ] ; then
clang-format --style=llvm -i $cfile
fi
done
if [ -f "$dir/CMakeLists.txt" ] ; then
cmake-format -i "$dir/CMakeLists.txt"
fi
done
if [ "$(git diff -u)" != "" ] ; then
git diff -u
exit 1
fi
exit 0
15 changes: 5 additions & 10 deletions include/gnuradio/iqtlabs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
# SPDX-License-Identifier: Apache-2.0
#

########################################################################
# ##############################################################################
# Install public header files
########################################################################
install(FILES
api.h
tuneable_test_source.h
retune_fft.h
write_freq_samples.h
image_inference.h
vector_to_json.h DESTINATION include/gnuradio/iqtlabs
)
# ##############################################################################
install(FILES api.h tuneable_test_source.h retune_fft.h write_freq_samples.h
image_inference.h vector_to_json.h
DESTINATION include/gnuradio/iqtlabs)
28 changes: 15 additions & 13 deletions include/gnuradio/iqtlabs/image_inference.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@
#ifndef INCLUDED_IQTLABS_IMAGE_INFERENCE_H
#define INCLUDED_IQTLABS_IMAGE_INFERENCE_H

#include <gnuradio/iqtlabs/api.h>
#include <gnuradio/block.h>
#include <gnuradio/iqtlabs/api.h>

namespace gr {
namespace iqtlabs {
Expand All @@ -216,20 +216,22 @@ namespace iqtlabs {
* \ingroup iqtlabs
*
*/
class IQTLABS_API image_inference : virtual public gr::block
{
class IQTLABS_API image_inference : virtual public gr::block {
public:
typedef std::shared_ptr<image_inference> sptr;
typedef std::shared_ptr<image_inference> sptr;

/*!
* \brief Return a shared_ptr to a new instance of iqtlabs::image_inference.
*
* To avoid accidental use of raw pointers, iqtlabs::image_inference's
* constructor is in a private implementation
* class. iqtlabs::image_inference::make is the public interface for
* creating new instances.
*/
static sptr make(const std::string &tag, int vlen, int x, int y, const std::string &image_dir, double convert_alpha, double norm_alpha, double norm_beta, int norm_type, int colormap, int interpolation, int flip);
/*!
* \brief Return a shared_ptr to a new instance of iqtlabs::image_inference.
*
* To avoid accidental use of raw pointers, iqtlabs::image_inference's
* constructor is in a private implementation
* class. iqtlabs::image_inference::make is the public interface for
* creating new instances.
*/
static sptr make(const std::string &tag, int vlen, int x, int y,
const std::string &image_dir, double convert_alpha,
double norm_alpha, double norm_beta, int norm_type,
int colormap, int interpolation, int flip);
};

} // namespace iqtlabs
Expand Down
47 changes: 26 additions & 21 deletions include/gnuradio/iqtlabs/retune_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,30 +209,35 @@
#include <gnuradio/sync_block.h>

namespace gr {
namespace iqtlabs {
namespace iqtlabs {

/*!
* \brief <+description of block+>
* \ingroup iqtlabs
*
*/
class IQTLABS_API retune_fft : virtual public gr::block
{
public:
typedef std::shared_ptr<retune_fft> sptr;
/*!
* \brief <+description of block+>
* \ingroup iqtlabs
*
*/
class IQTLABS_API retune_fft : virtual public gr::block {
public:
typedef std::shared_ptr<retune_fft> sptr;

/*!
* \brief Return a shared_ptr to a new instance of iqtlabs::retune_fft.
*
* To avoid accidental use of raw pointers, iqtlabs::retune_fft's
* constructor is in a private implementation
* class. iqtlabs::retune_fft::make is the public interface for
* creating new instances.
*/
static sptr make(const std::string &tag, int vlen, int nfft, uint64_t samp_rate, uint64_t freq_start, uint64_t freq_end, int tune_step_hz, int tune_step_fft, int skip_tune_step_fft, bool fft_roll, double fft_min, double fft_max, const std::string &sdir, uint64_t write_step_fft, double bucket_range, const std::string &tuning_ranges, const std::string &description, uint64_t rotate_secs);
};
/*!
* \brief Return a shared_ptr to a new instance of iqtlabs::retune_fft.
*
* To avoid accidental use of raw pointers, iqtlabs::retune_fft's
* constructor is in a private implementation
* class. iqtlabs::retune_fft::make is the public interface for
* creating new instances.
*/
static sptr make(const std::string &tag, int vlen, int nfft,
uint64_t samp_rate, uint64_t freq_start, uint64_t freq_end,
int tune_step_hz, int tune_step_fft, int skip_tune_step_fft,
bool fft_roll, double fft_min, double fft_max,
const std::string &sdir, uint64_t write_step_fft,
double bucket_range, const std::string &tuning_ranges,
const std::string &description, uint64_t rotate_secs);
};

} // namespace iqtlabs
} // namespace iqtlabs
} // namespace gr

#endif /* INCLUDED_IQTLABS_RETUNE_FFT_H */
Loading

0 comments on commit 660f9f7

Please sign in to comment.