generated from TDD-Templates/cmake_cpputest_template_avr
Initial commit
This commit is contained in:
commit
63ca73b223
|
@ -0,0 +1,12 @@
|
||||||
|
build/CMakeFiles
|
||||||
|
build/Testing/Temporary
|
||||||
|
build/cpputest
|
||||||
|
build/src
|
||||||
|
build/tests
|
||||||
|
build/CMakeCache.txt
|
||||||
|
build/CTestTestfile.cmake
|
||||||
|
build/Makefile
|
||||||
|
build/cmake_install.cmake
|
||||||
|
build/compile_commands.json
|
||||||
|
.cache/clangd/index
|
||||||
|
build/.cache/clangd/index
|
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "cpputest"]
|
||||||
|
path = cpputest
|
||||||
|
url = https://github.com/cpputest/cpputest.git
|
|
@ -0,0 +1,7 @@
|
||||||
|
add_library(module_name STATIC
|
||||||
|
module_name.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(module_name PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
|
@ -0,0 +1,10 @@
|
||||||
|
# TEST_RUNNER
|
||||||
|
add_library(test_module_name
|
||||||
|
test_module_name.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(test_module_name
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||||
|
module_name
|
||||||
|
)
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* Author: username
|
||||||
|
* Date: todays_date
|
||||||
|
* filename: module_name.c
|
||||||
|
* description: module_purpose
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "module_name.h"
|
||||||
|
|
||||||
|
// dumb test function
|
||||||
|
int add_two(int a)
|
||||||
|
{
|
||||||
|
int b = a;
|
||||||
|
b += 2;
|
||||||
|
return b;
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
* @brief PUT_TEXT_HERE
|
||||||
|
* @details This file is...
|
||||||
|
* @author username
|
||||||
|
* @date todays_date
|
||||||
|
* @copyright None
|
||||||
|
* @file module_name.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef module_name_H
|
||||||
|
#define module_name_H
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that adds two to a number
|
||||||
|
* @param a The first argument
|
||||||
|
*/
|
||||||
|
int add_two(int a);
|
||||||
|
|
||||||
|
#endif //module_name_H
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Author: username
|
||||||
|
* Date: todays_date
|
||||||
|
* filename: test_module_name.c
|
||||||
|
* description: module_purpose
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include "module_name.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_GROUP(FirstTestGroup)
|
||||||
|
{
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void teardown()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
TEST(FirstTestGroup, FirstTest)
|
||||||
|
{
|
||||||
|
FAIL("Fail me!");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(FirstTestGroup, SecondTest)
|
||||||
|
{
|
||||||
|
STRCMP_EQUAL("hello", "world");
|
||||||
|
LONGS_EQUAL(1, 2);
|
||||||
|
CHECK(false);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
# Use the fancy version substitution
|
||||||
|
project(main
|
||||||
|
VERSION 1.0
|
||||||
|
DESCRIPTION "template for cmake + cpputest"
|
||||||
|
LANGUAGES C CXX
|
||||||
|
)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
set(TARGET_GROUP production CACHE STRING "Group to build")
|
||||||
|
|
||||||
|
if(MSVC OR MSYS OR MINGW)
|
||||||
|
message("### SETUP FOR WINDOWS ###")
|
||||||
|
add_definitions(-DWINDOWS)
|
||||||
|
else()
|
||||||
|
message("### SETUP FOR UNIX ###")
|
||||||
|
add_definitions(-DUNIX)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# For being able to used LSP
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# Request C 17 standard features
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||||
|
# set(CMAKE_C_FLAGS "-Wall -Werror -Wpedantic")
|
||||||
|
|
||||||
|
# SETUP THE CXX flags for .cpp
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
set(CMAKE_CXX_FLAGS "-Wall -Werror -Wpedantic")
|
||||||
|
|
||||||
|
|
||||||
|
# #######################################
|
||||||
|
# TESTING STUFF
|
||||||
|
# #######################################
|
||||||
|
|
||||||
|
|
||||||
|
if (UNIT_TESTING)
|
||||||
|
|
||||||
|
if(DEFINED ENV{CPPUTEST_HOME})
|
||||||
|
message(STATUS "Using CppUTest home: $ENV{CPPUTEST_HOME}")
|
||||||
|
set(CPPUTEST_INCLUDE_DIRS $ENV{CPPUTEST_HOME}/include)
|
||||||
|
set(CPPUTEST_LIBRARIES $ENV{CPPUTEST_HOME}/lib)
|
||||||
|
set(CPPUTEST_LDFLAGS CppUTest CppUTestExt)
|
||||||
|
else()
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_search_module(CPPUTEST REQUIRED cpputest>=3.8)
|
||||||
|
message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
${CPPUTEST_INCLUDE_DIRS}
|
||||||
|
/usr/include/c++/11/
|
||||||
|
./inc
|
||||||
|
./mocks
|
||||||
|
)
|
||||||
|
link_directories(${CPPUTEST_LIBRARIES})
|
||||||
|
|
||||||
|
add_subdirectory(mocks)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# #######################################
|
||||||
|
# PROJECT SPECIFIC
|
||||||
|
# #######################################
|
||||||
|
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
./inc
|
||||||
|
)
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
|
@ -0,0 +1,51 @@
|
||||||
|
# ###############################
|
||||||
|
# AVR-GCC toolchain file
|
||||||
|
# ###############################
|
||||||
|
|
||||||
|
# Specify the cross-compiler
|
||||||
|
set(CMAKE_SYSTEM_NAME Generic)
|
||||||
|
set(CMAKE_SYSTEM_VERSION 1)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR avr)
|
||||||
|
|
||||||
|
# Specify the compiler and linker
|
||||||
|
#set(AVR_MCU atmega328p) # The old Classic
|
||||||
|
#set(AVR_MCU attiny85) # The older ATtiny series, avr25
|
||||||
|
set(AVR_MCU attiny404) # this is the avrxmega3 series
|
||||||
|
#set(AVR_MCU avr64dd28) # Newer DX series, avrxmega2
|
||||||
|
|
||||||
|
# The default frequency of an 328p devboard using the external crystal.
|
||||||
|
set(F_CPU 16000000UL)
|
||||||
|
#set(F_CPU 8000000)
|
||||||
|
add_compile_definitions(F_CPU=${F_CPU})
|
||||||
|
# add_compile_definitions(MCU=atmega328p)
|
||||||
|
#add_compile_definitions(__AVR_ATmega328P__)
|
||||||
|
add_compile_definitions(__AVR_ATtiny404__)
|
||||||
|
|
||||||
|
# Set up the programmer for it
|
||||||
|
#set(PROGRAMMER usbasp-clone)
|
||||||
|
#set(PROGRAMMER arduino)
|
||||||
|
set(PROGRAMMER serialupdi)
|
||||||
|
|
||||||
|
# Set the Port for the programmer
|
||||||
|
set(PORT /dev/ttyUSB0)
|
||||||
|
|
||||||
|
|
||||||
|
# Define the toolchain executables
|
||||||
|
set(CMAKE_C_COMPILER avr-gcc)
|
||||||
|
set(CMAKE_CXX_COMPILER avr-g++)
|
||||||
|
set(CMAKE_ASM_COMPILER avr-gcc)
|
||||||
|
set(CMAKE_LINKER avr-ld)
|
||||||
|
set(CMAKE_OBJCOPY avr-objcopy)
|
||||||
|
set(CMAKE_SIZE avr-size)
|
||||||
|
|
||||||
|
|
||||||
|
# Define compile options
|
||||||
|
set(CMAKE_C_FLAGS " -Os -mmcu=${AVR_MCU} -DF_CPU=${F_CPU}")
|
||||||
|
set(CMAKE_CXX_FLAGS "-mmcu=${AVR_MCU} -DF_CPU=${F_CPU}")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS_INIT "-mmcu=${AVR_MCU}")
|
||||||
|
|
||||||
|
|
||||||
|
# Define the archiver and other tools
|
||||||
|
set(CMAKE_AR avr-ar)
|
||||||
|
set(CMAKE_RANLIB avr-ranlib)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
# CMAKE generated file: DO NOT EDIT!
|
||||||
|
# Generated by "Unix Makefiles" Generator, CMake Version 3.22
|
||||||
|
|
||||||
|
# Relative path conversion top directories.
|
||||||
|
set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr")
|
||||||
|
set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build")
|
||||||
|
|
||||||
|
# Force unix paths in dependencies.
|
||||||
|
set(CMAKE_FORCE_UNIX_PATHS 1)
|
||||||
|
|
||||||
|
|
||||||
|
# The C and CXX include file regular expressions for this directory.
|
||||||
|
set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$")
|
||||||
|
set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$")
|
||||||
|
set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})
|
||||||
|
set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN})
|
|
@ -0,0 +1 @@
|
||||||
|
0
|
|
@ -0,0 +1,6 @@
|
||||||
|
# CMake generated Testfile for
|
||||||
|
# Source directory: /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/mocks
|
||||||
|
# Build directory: /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build/mocks
|
||||||
|
#
|
||||||
|
# This file includes the relevant testing commands required for
|
||||||
|
# testing this directory and lists subdirectories to be tested as well.
|
|
@ -0,0 +1,154 @@
|
||||||
|
# CMAKE generated file: DO NOT EDIT!
|
||||||
|
# Generated by "Unix Makefiles" Generator, CMake Version 3.22
|
||||||
|
|
||||||
|
# Default target executed when no arguments are given to make.
|
||||||
|
default_target: all
|
||||||
|
.PHONY : default_target
|
||||||
|
|
||||||
|
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
|
||||||
|
.NOTPARALLEL:
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Special targets provided by cmake.
|
||||||
|
|
||||||
|
# Disable implicit rules so canonical targets will work.
|
||||||
|
.SUFFIXES:
|
||||||
|
|
||||||
|
# Disable VCS-based implicit rules.
|
||||||
|
% : %,v
|
||||||
|
|
||||||
|
# Disable VCS-based implicit rules.
|
||||||
|
% : RCS/%
|
||||||
|
|
||||||
|
# Disable VCS-based implicit rules.
|
||||||
|
% : RCS/%,v
|
||||||
|
|
||||||
|
# Disable VCS-based implicit rules.
|
||||||
|
% : SCCS/s.%
|
||||||
|
|
||||||
|
# Disable VCS-based implicit rules.
|
||||||
|
% : s.%
|
||||||
|
|
||||||
|
.SUFFIXES: .hpux_make_needs_suffix_list
|
||||||
|
|
||||||
|
# Produce verbose output by default.
|
||||||
|
VERBOSE = 1
|
||||||
|
|
||||||
|
# Command-line flag to silence nested $(MAKE).
|
||||||
|
$(VERBOSE)MAKESILENT = -s
|
||||||
|
|
||||||
|
#Suppress display of executed commands.
|
||||||
|
$(VERBOSE).SILENT:
|
||||||
|
|
||||||
|
# A target that is always out of date.
|
||||||
|
cmake_force:
|
||||||
|
.PHONY : cmake_force
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Set environment variables for the build.
|
||||||
|
|
||||||
|
# The shell in which to execute make rules.
|
||||||
|
SHELL = /bin/sh
|
||||||
|
|
||||||
|
# The CMake executable.
|
||||||
|
CMAKE_COMMAND = /usr/bin/cmake
|
||||||
|
|
||||||
|
# The command to remove a file.
|
||||||
|
RM = /usr/bin/cmake -E rm -f
|
||||||
|
|
||||||
|
# Escaping for special characters.
|
||||||
|
EQUALS = =
|
||||||
|
|
||||||
|
# The top-level source directory on which CMake was run.
|
||||||
|
CMAKE_SOURCE_DIR = /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr
|
||||||
|
|
||||||
|
# The top-level build directory on which CMake was run.
|
||||||
|
CMAKE_BINARY_DIR = /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Targets provided globally by CMake.
|
||||||
|
|
||||||
|
# Special rule for the target test
|
||||||
|
test:
|
||||||
|
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..."
|
||||||
|
/usr/bin/ctest --force-new-ctest-process $(ARGS)
|
||||||
|
.PHONY : test
|
||||||
|
|
||||||
|
# Special rule for the target test
|
||||||
|
test/fast: test
|
||||||
|
.PHONY : test/fast
|
||||||
|
|
||||||
|
# Special rule for the target edit_cache
|
||||||
|
edit_cache:
|
||||||
|
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
|
||||||
|
/usr/bin/cmake-gui -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
|
||||||
|
.PHONY : edit_cache
|
||||||
|
|
||||||
|
# Special rule for the target edit_cache
|
||||||
|
edit_cache/fast: edit_cache
|
||||||
|
.PHONY : edit_cache/fast
|
||||||
|
|
||||||
|
# Special rule for the target rebuild_cache
|
||||||
|
rebuild_cache:
|
||||||
|
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
|
||||||
|
/usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
|
||||||
|
.PHONY : rebuild_cache
|
||||||
|
|
||||||
|
# Special rule for the target rebuild_cache
|
||||||
|
rebuild_cache/fast: rebuild_cache
|
||||||
|
.PHONY : rebuild_cache/fast
|
||||||
|
|
||||||
|
# The main all target
|
||||||
|
all: cmake_check_build_system
|
||||||
|
cd /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build && $(CMAKE_COMMAND) -E cmake_progress_start /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build/CMakeFiles /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build/mocks//CMakeFiles/progress.marks
|
||||||
|
cd /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 mocks/all
|
||||||
|
$(CMAKE_COMMAND) -E cmake_progress_start /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build/CMakeFiles 0
|
||||||
|
.PHONY : all
|
||||||
|
|
||||||
|
# The main clean target
|
||||||
|
clean:
|
||||||
|
cd /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 mocks/clean
|
||||||
|
.PHONY : clean
|
||||||
|
|
||||||
|
# The main clean target
|
||||||
|
clean/fast: clean
|
||||||
|
.PHONY : clean/fast
|
||||||
|
|
||||||
|
# Prepare targets for installation.
|
||||||
|
preinstall: all
|
||||||
|
cd /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 mocks/preinstall
|
||||||
|
.PHONY : preinstall
|
||||||
|
|
||||||
|
# Prepare targets for installation.
|
||||||
|
preinstall/fast:
|
||||||
|
cd /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 mocks/preinstall
|
||||||
|
.PHONY : preinstall/fast
|
||||||
|
|
||||||
|
# clear depends
|
||||||
|
depend:
|
||||||
|
cd /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
|
||||||
|
.PHONY : depend
|
||||||
|
|
||||||
|
# Help Target
|
||||||
|
help:
|
||||||
|
@echo "The following are some of the valid targets for this Makefile:"
|
||||||
|
@echo "... all (the default if no target is provided)"
|
||||||
|
@echo "... clean"
|
||||||
|
@echo "... depend"
|
||||||
|
@echo "... edit_cache"
|
||||||
|
@echo "... rebuild_cache"
|
||||||
|
@echo "... test"
|
||||||
|
.PHONY : help
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Special targets to cleanup operation of make.
|
||||||
|
|
||||||
|
# Special rule to run CMake to check the build system integrity.
|
||||||
|
# No rule that depends on this can have commands that come from listfiles
|
||||||
|
# because they might be regenerated.
|
||||||
|
cmake_check_build_system:
|
||||||
|
cd /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/build && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
|
||||||
|
.PHONY : cmake_check_build_system
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
# Install script for directory: /home/ronin/Documents/projects/templates/cpputest_template_worktrees/avr/mocks
|
||||||
|
|
||||||
|
# Set the install prefix
|
||||||
|
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
|
||||||
|
set(CMAKE_INSTALL_PREFIX "/usr/local")
|
||||||
|
endif()
|
||||||
|
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
||||||
|
|
||||||
|
# Set the install configuration name.
|
||||||
|
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
||||||
|
if(BUILD_TYPE)
|
||||||
|
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
|
||||||
|
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
|
||||||
|
else()
|
||||||
|
set(CMAKE_INSTALL_CONFIG_NAME "")
|
||||||
|
endif()
|
||||||
|
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Set the component getting installed.
|
||||||
|
if(NOT CMAKE_INSTALL_COMPONENT)
|
||||||
|
if(COMPONENT)
|
||||||
|
message(STATUS "Install component: \"${COMPONENT}\"")
|
||||||
|
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
|
||||||
|
else()
|
||||||
|
set(CMAKE_INSTALL_COMPONENT)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Install shared libraries without execute permission?
|
||||||
|
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
|
||||||
|
set(CMAKE_INSTALL_SO_NO_EXE "1")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Is this installation the result of a crosscompile?
|
||||||
|
if(NOT DEFINED CMAKE_CROSSCOMPILING)
|
||||||
|
set(CMAKE_CROSSCOMPILING "FALSE")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Set default install directory permissions.
|
||||||
|
if(NOT DEFINED CMAKE_OBJDUMP)
|
||||||
|
set(CMAKE_OBJDUMP "/usr/bin/objdump")
|
||||||
|
endif()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
./build/compile_commands.json
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,278 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Author: Jake Goodwin
|
||||||
|
# Date: 2024
|
||||||
|
# Filename: otto.sh
|
||||||
|
|
||||||
|
AVR_TC="$(pwd)/avr-gcc-toolchain.cmake"
|
||||||
|
CMAKE_VERBOSE="ON"
|
||||||
|
CROSS_COMPILE=1
|
||||||
|
TEMPLATE_FILES=".template_files"
|
||||||
|
MODULE_DIR="${TEMPLATE_FILES}/modules"
|
||||||
|
|
||||||
|
|
||||||
|
add_compile_commands () {
|
||||||
|
if [ -f ./compile_commands.json ]; then
|
||||||
|
echo "compile_commands.json already exists!\n"
|
||||||
|
else
|
||||||
|
echo "Creating new symlink for compile commands!\n"
|
||||||
|
ln -s ./build/compile_commands.json ./compile_commands.json
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
clear_cmake_cache () {
|
||||||
|
cd ./build
|
||||||
|
rm -rf CMakeCache.txt CMakeFiles/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
does_module_exist () {
|
||||||
|
local basename="$1"
|
||||||
|
|
||||||
|
if [ -d "src/${basename}" ]; then
|
||||||
|
echo "1"
|
||||||
|
else
|
||||||
|
echo "0"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
add_module_to_cmakes () {
|
||||||
|
local basename="$1"
|
||||||
|
|
||||||
|
echo "add_subdirectory(${basename})" >> ./src/CMakeLists.txt
|
||||||
|
|
||||||
|
# Tests cmake file needs to be edited in place.
|
||||||
|
sed -i'' "s/# TEST_DIRS.*$/# TEST_DIRS\r\nadd_subdirectory(${basename})/g" ./tests/CMakeLists.txt
|
||||||
|
sed -i'' "s/# TEST_LINKS.*$/# TEST_LINKS\r\n\t${basename}/g" ./tests/CMakeLists.txt
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_module_from_cmakes () {
|
||||||
|
local basename="$1"
|
||||||
|
|
||||||
|
sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./src/CMakeLists.txt
|
||||||
|
sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./tests/CMakeLists.txt
|
||||||
|
sed -i'' "s/^.*${basename}.*$//g" ./tests/CMakeLists.txt
|
||||||
|
}
|
||||||
|
|
||||||
|
git_add_module () {
|
||||||
|
|
||||||
|
local basename="$1"
|
||||||
|
|
||||||
|
read -p "Auto add to git?(y/n):" CHOICE
|
||||||
|
if [ "${CHOICE}" = "n" ]; then
|
||||||
|
echo "not being added!"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
modsrc_dir="./src/${basename}"
|
||||||
|
modtest_dir="./tests/${basename}"
|
||||||
|
|
||||||
|
# Now we add the new files to the git tracked files
|
||||||
|
git add ${modsrc_dir}/*
|
||||||
|
git add ${modsrc_dir}
|
||||||
|
git add ${modtest_dir}/*
|
||||||
|
git add ${modtest_dir}
|
||||||
|
git add ./src/CMakeLists.txt
|
||||||
|
git add ./tests/CMakeLists.txt
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
git_remove_module () {
|
||||||
|
local basename="$1"
|
||||||
|
|
||||||
|
read -p "Auto del from git?(y/n):" CHOICE
|
||||||
|
if [ "${CHOICE}" -eq "n" ]; then
|
||||||
|
echo "not being removed!"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
modsrc_dir="./src/${basename}"
|
||||||
|
modtest_dir="./tests/${basename}"
|
||||||
|
|
||||||
|
# Now we add the new files to the git tracked files
|
||||||
|
git rm -r ${modsrc_dir}/*
|
||||||
|
git rm -r ${modsrc_dir}
|
||||||
|
git rm -r ${modtest_dir}/*
|
||||||
|
git rm -r ${modtest_dir}
|
||||||
|
git rm -r ./src/CMakeLists.txt
|
||||||
|
git rm -r ./tests/CMakeLists.txt
|
||||||
|
}
|
||||||
|
|
||||||
|
add_mock_module () {
|
||||||
|
echo "Not yet implimented!"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
add_new_module () {
|
||||||
|
read -p "Enter the name of the module:" modname
|
||||||
|
|
||||||
|
result=$(does_module_exist "$modname")
|
||||||
|
|
||||||
|
if [ "${result}" -eq "1" ]; then
|
||||||
|
echo "Module already exists!"
|
||||||
|
echo "Exiting without changing anything"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g')
|
||||||
|
modsrc_dir="./src/${modname}"
|
||||||
|
modtest_dir="./tests/${modname}"
|
||||||
|
|
||||||
|
echo "creating: ${modsrc_dir}, ${modtest_dir}"
|
||||||
|
mkdir $modsrc_dir
|
||||||
|
mkdir $modtest_dir
|
||||||
|
|
||||||
|
#copy the template files.
|
||||||
|
echo "copying & customizing template files..."
|
||||||
|
|
||||||
|
sed "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c
|
||||||
|
sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c
|
||||||
|
|
||||||
|
sed "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h
|
||||||
|
sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h
|
||||||
|
|
||||||
|
sed "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt
|
||||||
|
|
||||||
|
sed "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp
|
||||||
|
sed "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
|
||||||
|
|
||||||
|
# Add the module to the cmake lists files.
|
||||||
|
add_module_to_cmakes "${modname}"
|
||||||
|
|
||||||
|
echo "Resulting files/dirs:"
|
||||||
|
tree -L 2 $modsrc_dir
|
||||||
|
tree -L 2 $modtest_dir
|
||||||
|
|
||||||
|
# Now we add the new files to the git tracked files
|
||||||
|
git_add_module "${modname}"
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
del_module () {
|
||||||
|
read -p "Enter the name of the module:" modname
|
||||||
|
|
||||||
|
rm -r ./tests/${modname}
|
||||||
|
rm -r ./src/${modname}
|
||||||
|
remove_module_from_cmakes "${modname}"
|
||||||
|
}
|
||||||
|
|
||||||
|
cross_compile () {
|
||||||
|
echo "ERROR: Currently no toolchain / target!"
|
||||||
|
}
|
||||||
|
|
||||||
|
build_release() {
|
||||||
|
clear_cmake_cache
|
||||||
|
cmake -DCAM_HANDLER_LIB=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
|
||||||
|
make
|
||||||
|
}
|
||||||
|
|
||||||
|
build_main () {
|
||||||
|
clear_cmake_cache
|
||||||
|
cmake -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
|
||||||
|
make main
|
||||||
|
}
|
||||||
|
|
||||||
|
build_hex () {
|
||||||
|
clear_cmake_cache
|
||||||
|
|
||||||
|
CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE}"
|
||||||
|
CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${AVR_TC}"
|
||||||
|
|
||||||
|
cmake ${CMAKE_ARGS} ../
|
||||||
|
make all
|
||||||
|
make hex
|
||||||
|
}
|
||||||
|
|
||||||
|
build_hex_optimized () {
|
||||||
|
clear_cmake_cache
|
||||||
|
|
||||||
|
CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE}"
|
||||||
|
CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${AVR_TC}"
|
||||||
|
|
||||||
|
cmake ${CMAKE_ARGS} ../
|
||||||
|
make all
|
||||||
|
make hex-release
|
||||||
|
}
|
||||||
|
|
||||||
|
flash_avr () {
|
||||||
|
build_hex_optimized
|
||||||
|
make upload
|
||||||
|
}
|
||||||
|
|
||||||
|
run_c_tests () {
|
||||||
|
clear_cmake_cache
|
||||||
|
cmake -DUNIT_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../
|
||||||
|
make AllTests && ./tests/AllTests
|
||||||
|
}
|
||||||
|
|
||||||
|
print_menu () {
|
||||||
|
echo "BUILD MENU:"
|
||||||
|
echo "0. Add Mock Module"
|
||||||
|
echo "1. Run Tests"
|
||||||
|
echo "2. Build Project(hex)"
|
||||||
|
echo "3. Build for release(hex)"
|
||||||
|
echo "4. Flash to AVR"
|
||||||
|
echo "5. Add new module to project"
|
||||||
|
echo "6. Delete module from project"
|
||||||
|
echo "7. Exit"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
main() {
|
||||||
|
add_compile_commands
|
||||||
|
valid_choice=false
|
||||||
|
|
||||||
|
while [ "$valid_choice" != true ]; do
|
||||||
|
print_menu
|
||||||
|
read -p "Enter your choice: " choice
|
||||||
|
|
||||||
|
case $choice in
|
||||||
|
0)
|
||||||
|
echo "You selected Option 0"
|
||||||
|
valid_choice=true
|
||||||
|
add_mock_module
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
echo "You selected Option 1"
|
||||||
|
valid_choice=true
|
||||||
|
run_c_tests
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
echo "You selected Option 2"
|
||||||
|
valid_choice=true
|
||||||
|
build_hex
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
echo "You selected Option 3"
|
||||||
|
valid_choice=true
|
||||||
|
build_hex_optimized
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
echo "You selected Option 4"
|
||||||
|
valid_choice=true
|
||||||
|
flash_avr
|
||||||
|
;;
|
||||||
|
5)
|
||||||
|
echo "You selected Option 5"
|
||||||
|
valid_choice=true
|
||||||
|
add_new_module
|
||||||
|
;;
|
||||||
|
6)
|
||||||
|
echo "You selected Option 6"
|
||||||
|
valid_choice=true
|
||||||
|
del_module
|
||||||
|
;;
|
||||||
|
7)
|
||||||
|
echo "Exiting..."
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid choice. Please select a valid option."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
|
@ -0,0 +1,86 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#Author: Jake G
|
||||||
|
#Date: 2024
|
||||||
|
#Filename: setup.sh
|
||||||
|
|
||||||
|
PKG_MNGR=""
|
||||||
|
DEBIAN=0
|
||||||
|
FBSD=0
|
||||||
|
SYSINSTALL=0
|
||||||
|
DEV_UTILS="vim tmux fzf"
|
||||||
|
|
||||||
|
|
||||||
|
install_dev_utils () {
|
||||||
|
ICMD=""
|
||||||
|
if [ $DEBIAN -eq 1 ]; then
|
||||||
|
ICMD="sudo apt install"
|
||||||
|
elif [ $FBSD -eq 1 ]; then
|
||||||
|
ICMD="sudo pkg install"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for util in $DEV_UTILS
|
||||||
|
do
|
||||||
|
${ICMD} ${util}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
check_os () {
|
||||||
|
if [ -f /etc/debian_version ]; then
|
||||||
|
DEBIAN=1
|
||||||
|
elif [ -f /etc/freebsd-update.conf ]; then
|
||||||
|
FBSD=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
remove_template_examples () {
|
||||||
|
echo "does nothing right now"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
install_needed_dependencies () {
|
||||||
|
# Check the OS
|
||||||
|
echo "checking the OS..."
|
||||||
|
# If it's debian based then apt install
|
||||||
|
|
||||||
|
# If it's freeBSD then pkg
|
||||||
|
|
||||||
|
# If it's windows....you're SOL
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
create_project_symlinks () {
|
||||||
|
# Allows the clangd LSP to find it.
|
||||||
|
ln -s ./build/compile_commands.json ./compile_commands.json
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
build_cpputest () {
|
||||||
|
git submodule add https://github.com/cpputest/cpputest.git
|
||||||
|
git sumodule status
|
||||||
|
cd ./cpputest/build
|
||||||
|
cmake ../
|
||||||
|
|
||||||
|
if [ SYSINSTALL -eq 1]; then
|
||||||
|
make install
|
||||||
|
else
|
||||||
|
make
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# The default setup stuff.
|
||||||
|
default () {
|
||||||
|
remove_template_examples
|
||||||
|
install_needed_dependencies
|
||||||
|
create_project_symlinks
|
||||||
|
}
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
echo "Setting up env"
|
||||||
|
check_os
|
||||||
|
install_dev_utils
|
||||||
|
}
|
||||||
|
|
||||||
|
setup
|
|
@ -0,0 +1,40 @@
|
||||||
|
add_executable(${PROJECT_NAME}
|
||||||
|
main.c
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure the build rules are defined
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".elf")
|
||||||
|
|
||||||
|
if(NOT TARGET size)
|
||||||
|
# Set the size utility to display the size of the final binary
|
||||||
|
add_custom_target(size ALL
|
||||||
|
COMMAND ${CMAKE_SIZE} --format=avr --mcu=${AVR_MCU} ${CMAKE_PROJECT_NAME}.elf
|
||||||
|
DEPENDS ${CMAKE_PROJECT_NAME}.elf
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
if(NOT TARGET hex)
|
||||||
|
# Define how to convert ELF to HEX
|
||||||
|
add_custom_target(hex ALL
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} -O ihex -R .eeprom ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.hex
|
||||||
|
DEPENDS ${CMAKE_PROJECT_NAME}.elf
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT TARGET bin)
|
||||||
|
# Define how to convert ELF to BIN
|
||||||
|
add_custom_target(bin ALL
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} -O binary -R .eeprom ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin
|
||||||
|
DEPENDS ${CMAKE_PROJECT_NAME}.elf
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
if(NOT TARGET upload)
|
||||||
|
# Upload command (adjust according to your programmer)
|
||||||
|
add_custom_target(upload ALL
|
||||||
|
COMMAND avrdude -c ${PROGRAMMER} -P ${PORT} -p ${AVR_MCU} -U flash:w:${CMAKE_PROJECT_NAME}.hex
|
||||||
|
DEPENDS hex
|
||||||
|
)
|
||||||
|
endif()
|
|
@ -0,0 +1,59 @@
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
|
||||||
|
//#############################
|
||||||
|
//Globals
|
||||||
|
//#############################
|
||||||
|
|
||||||
|
#define LED_PORT (1<<5)
|
||||||
|
#define LED_PIN PB5
|
||||||
|
#define BLINK_DELAY_MS 5000
|
||||||
|
|
||||||
|
//#############################
|
||||||
|
//Prototypes
|
||||||
|
//#############################
|
||||||
|
|
||||||
|
void led_blink(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//#############################
|
||||||
|
//MAIN
|
||||||
|
//#############################
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
led_blink();
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
led_blink();
|
||||||
|
_delay_ms(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//#############################
|
||||||
|
//FUNCTIONS
|
||||||
|
//#############################
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Input: None
|
||||||
|
* Output: None
|
||||||
|
* Description: Toggles the pin for the LED indicator.
|
||||||
|
*/
|
||||||
|
void led_blink(void) {
|
||||||
|
//Set the DDR for output.
|
||||||
|
DDRB |= LED_PORT;
|
||||||
|
|
||||||
|
PORTB ^= (1<<LED_PIN);
|
||||||
|
_delay_ms(500);
|
||||||
|
PORTB ^= (1<<LED_PIN);
|
||||||
|
_delay_ms(500);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
|
||||||
|
|
||||||
|
//ImportTestGroups
|
||||||
|
IMPORT_TEST_GROUP(simple_test);
|
||||||
|
|
||||||
|
//START: main
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
return RUN_ALL_TESTS(argc, argv);
|
||||||
|
}
|
||||||
|
//END: main
|
|
@ -0,0 +1,16 @@
|
||||||
|
project(Tests)
|
||||||
|
|
||||||
|
# TEST_DIRS
|
||||||
|
add_subdirectory(simple_test)
|
||||||
|
|
||||||
|
# TEST_RUNNER
|
||||||
|
add_executable(AllTests
|
||||||
|
AllTests.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(AllTests
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||||
|
# TEST_LINKS
|
||||||
|
simple_test
|
||||||
|
)
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
# TEST_RUNNER
|
||||||
|
add_library(simple_test
|
||||||
|
simple_test.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(simple_test
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
#include "CppUTest/TestHarness.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
extern C
|
||||||
|
{
|
||||||
|
#include "simple.h"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
TEST_GROUP(simple_test)
|
||||||
|
{
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void teardown()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(simple_test, passing_test)
|
||||||
|
{
|
||||||
|
CHECK_TRUE(1);
|
||||||
|
}
|
Loading…
Reference in New Issue