cmake-avr - a cmake toolchain for AVR projects

Overview

cmake-avr - a cmake toolchain for AVR projects

Testing the example provided

The toolchain was created and tested within the following environment:

Linux

  • Arch Linux with kernel 3.12.5-1-ARCH up to 3.16.2-1-ARCH
  • cmake version 2.8.12.1 - 3.0.2
  • GNU Make 4.0
  • avr-gcc (GCC) 4.8.2 - 4.9.1
  • avr-binutils 2.23.2-1 - 2.24-2
  • avr-libc 1.8.0-5 - 1.8.1-1
  • git version 1.8.5.2 - 2.1.0

Windows XP

  • cmake version 2.8.10.2
  • GNU Make 3.81
  • avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.1_798) 4.6.2 (Atmel Studio 6)
  • avr-binutils AVR_8_bit_GNU_Toolchain_3.4.1_798 (Atmel Studio 6)
  • avr-libc AVR_8_bit_GNU_Toolchain_3.4.1_798 (Atmel Studio 6)
  • git version 1.7.11.msysgit.1

Windows 7

  • cmake 3.0.2
  • Atmel Studio 6.2
  • git 1.9.0.msysgit

OS X

  • OS X 10.10 with AVR toolchain installed from macports
  • cmake 3.0.2
  • GNU Make 3.81
  • avr-gcc 4.9.1
  • avr-libc 1.8.1
  • avr-binutils 2.24_1
  • git version 2.1.2

Note: If building in a Windows environment, you need to extent the values of the environment variable PATH to the location of the binaries, especially to find make. To enable a more general approach to different Windows toolchains, the variable AVR_FIND_ROOT_PATH needs to be defined. Tested was it with the following setup (XP):

PATH=...;d:/Program Files/Atmel/Atmel Studio 6.0/extensions/Atmel/AVRGCC/3.4.1.81/AVRToolchain/bin;...
AVR_FIND_ROOT_PATH="d:/Program Files/Atmel/Atmel Studio 6.0/extensions/Atmel/AVRGCC/3.4.1.81/AVRToolchain/avr"

Issue within Windows 7 environment With Windows 7 (64bit) and the Atmel Studio 6.2 setup, make.exe now resides differently. It also crashes during the cmake generation process, just after the simple examples to test the compiler (try_compile(...)) ran through. The why and avoidance of this is currently unknown to me. I didn't try to use a cygwin make as a substitute yet.

After getting the project

git clone [email protected]:mkleemann/cmake-avr.git /path/to/clone/in

you just need to run the following commands

mkdir -p /path/to/some/build/dir
cd /path/to/some/build/dir
cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/clone/in/generic-gcc-avr.cmake /path/to/clone/in/example
make

For Windows use:

cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/path/to/clone/in/generic-gcc-avr.cmake /path/to/clone/in/example

This just creates the example, but does not upload it. For all possible targets, you need to run

make help

after running the cmake command.

ToDo

  • option for target name attachments with MCU type (option -DWITH_MCU=ON (default))
  • usage of target names w/o extension for avr_target_link_libraries command
  • cleanup baudrate and other AVRDUDE settings
  • test in Windows environment
  • use add_definition() instead of variables for compiler settings
  • some more tests with upload and fuses
Issues
  • Binary extensions and -pedantic-errors

    Binary extensions and -pedantic-errors

    With enabled add_definitions("-pedantic-errors") avr-gcc causes an error in code that contains binary extensions, for example:

    value = 0b10101; 
    
    invalid wontfix 
    opened by bevice 2
  • Changing config variables does not affect building

    Changing config variables does not affect building

    Hey,

    first of all I want to thank you for the grate project.

    But i think there is a bug: The variables (e.g. AVR_MCU) defined at the top of the CmakeLists file inside the root directory are never used.

    I think this is because the tool chain file, which is passed with "-DCMAKE_TOOLCHAIN_FILE=../../generic-gcc-avr.cmake is parsed right after the project() call, but at this moment there are´t any variables set. Because of this the generic-gcc-avr.cmake script uses always the default values.

    Steps to reproduce

    1. Clean build directory
    2. Run cmake
    3. make (look at the file names)
    4. Clean build directory
    5. Change AVR_MCU to atmega16
    6. Run cmake
    7. make (file name suffix is still atmega8)

    Possible solution 1 Move the project() call to a position downwards. (Don´t know which variables will be used by the generic-gcc file... so it could be that we need to move the project() call anywhere else ?!) e.g.

    set(AVR_UPLOADTOOL avrdude)
    set(AVR_PROGRAMMER avrispmkII)
    set(AVR_UPLOADTOOL_PORT usb)
    
    set(AVR_MCU atmega16)
    set(AVR_H_FUSE 0xd9)
    set(AVR_L_FUSE 0xc3)
    
    project(AVR-EXAMPLE)
    

    2 Introduce a new parameter and manually include the generic-gcc-cmake file.

    bug 
    opened by nbars 2
  • Add REQUIRED to the avr-gcc, avr-g++, executables

    Add REQUIRED to the avr-gcc, avr-g++, executables

    This is a suggestion of getting clearer messages at the moment that the files can't be found. This helps in particular to show where the lack of finding is happening, so people can check their path.

    opened by AE1020 1
  • Passing options to the linker

    Passing options to the linker

    How can I pass options to the linker? I am building a bootloader and I need to pass: -section-start=.text=0x7c00 Also, is there a way with cmake to display/log the actual compiler/linker commands being executed?

    opened by rvalle 1
  • macports avr-gcc support: avr-size args and correct CMAKE_FIND_ROOT_PATH

    macports avr-gcc support: avr-size args and correct CMAKE_FIND_ROOT_PATH

    Added OSX support with AVR toolchaing installed from macports.org

    • fix: avr-size args (unsupported "-C" key)
    • fix: CMAKE_FIND_ROOT_PATH: /opt/local/avr

    Tested in osx 10.10 with tools versions specified in README.md

    opened by bevice 1
  • Bypass Linking for CMake Compiler Test

    Bypass Linking for CMake Compiler Test

    Some generators throw in a try_compile() sanity check that will fail trying to link and run an exe on the host platform since this is a cross-compiler. This behavior was seen on Windows.

    Since linking and running won't work with this toolchain on the host, change the CMAKE_TRY_COMPILE_TARGET_TYPE to "STATIC_LIBRARY".

    opened by AE1020 0
  • Fix avr_target_link_libraries

    Fix avr_target_link_libraries

    This PR fixes avr_target_link_libraries. Due to a typo, using it resulted in a CMake error:

    CMake Error at generic-gcc-avr.cmake:348 (target_link_libraries):
      The INTERFACE, PUBLIC or PRIVATE option must appear as the second argument,
      just after the target name.
    Call Stack (most recent call first):
      CMakeLists.txt:32 (avr_target_link_libraries)
    
    opened by klaussnd 0
  • Fix multiple use of add_avr_executable

    Fix multiple use of add_avr_executable

    This PR fixes problems when using add_avr_executable more than once by disambiguating targets with the same name.

    Currently, when adding several images, you get:

    Make Error at generic-gcc-avr.cmake:224 (add_custom_target):
      add_custom_target cannot create target "upload_eeprom" because another
      target with the same name already exists.  The existing target is a custom
      target created in source directory "...".
      See documentation for policy CMP0002 for more details.
    

    The problem was solved in several steps:

    1. The target upload_eeprom was renamed upload_${EXECUTABLE_NAME}_eeprom
    2. The targets get_status, get_fuses, set_fuses, get_calibration, and set_calibration were moved inside a new function, since they are stand-alone and don't depend on the executable target. The user has to explicitly call avr_generate_fixed_targets().

    Please note that this PR changes the usage.

    opened by klaussnd 0
  • Add additional macros and identification variable

    Add additional macros and identification variable

    • Add additional macros for target_include_directories and target_compile_definitions
    • Add identification variable AVR, which is very useful for cross-platform cmake configurations (e.g. AVR and Raspi, depending on tool chain)
    opened by klaussnd 0
  • Add support for upload baudrate and additional parameters

    Add support for upload baudrate and additional parameters

    • added support for setting the upload baudrate
    • added baudrate parameter in get_status
    • added baudrate massage
    • changed the order of messages
    • aligned comment-lines
    • added baudrate comments
    • added support for uploadtool additional parameters
    opened by PRESFIL 0
  • enable CMAKE_BUILD_TYPE MinSizeRel

    enable CMAKE_BUILD_TYPE MinSizeRel

    The CMAKE_BUILD_TYPE MinSizeRel is currently not recognized so that the build system falls back to Release. In contrast to Release, MinSizeRel advises the compiler to optimize for size instead of speed which is particularly interesting on micro controllers. For GCC CMake will typically specify the option -Os instead of -O3.

    opened by fetzerch 0
  • MOD: Added support for avr-gcc from homebrew

    MOD: Added support for avr-gcc from homebrew

    • Added support for avr-gcc from homebrew. The current supported version is 9.3.1
    • Additionally, now generates compile_commands.json for use with YouCompleteMe (a vim/vundle plugin)
    opened by brothaman 0
  • What is the relation of cmake-avr and avrdude?

    What is the relation of cmake-avr and avrdude?

    I created hex-files with the help of this great repository, thanks already for this very helpful project! Now I want to upload my code to a MCU (using avrdude!?) But I haven't really exactly figured out how this would work. There seems to be some connection between cmake and avrdude, is that correct? For example there are some things set in the CMakeLists.txt like

    set(AVR_UPLOADTOOL avrdude) set(AVR_PROGRAMMER avrispmkII) set(AVR_UPLOADTOOL_PORT usb)

    later in the "generic-gcc-avr.cmake", these definitions are used for add_custom_target()-functions:

    `

    ##########################################################################

    avr_target_compile_definitions

    Calls target_compile_definitions with AVR target names

    ##########################################################################

    function(avr_target_compile_definitions EXECUTABLE_TARGET) if(NOT ARGN) message(FATAL_ERROR "No compile definitions to add to ${EXECUTABLE_TARGET}.") endif()

    get_target_property(TARGET_LIST ${EXECUTABLE_TARGET} OUTPUT_NAME)
    set(extra_args ${ARGN})
    

    target_compile_definitions(${TARGET_LIST} ${extra_args}) endfunction()

    function(avr_generate_fixed_targets)

    get status

    add_custom_target( get_status ${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT} -n -v COMMENT "Get status from ${AVR_MCU}" )

    get fuses

    add_custom_target( get_fuses ${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT} -n -U lfuse:r:-:b -U hfuse:r:-:b COMMENT "Get fuses from ${AVR_MCU}" )

    set fuses

    add_custom_target( set_fuses ${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT} -U lfuse:w:${AVR_L_FUSE}:m -U hfuse:w:${AVR_H_FUSE}:m COMMENT "Setup: High Fuse: ${AVR_H_FUSE} Low Fuse: ${AVR_L_FUSE}" )

    get oscillator calibration

    add_custom_target( get_calibration ${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT} -U calibration:r:${AVR_MCU}_calib.tmp:r COMMENT "Write calibration status of internal oscillator to ${AVR_MCU}_calib.tmp." )

    set oscillator calibration

    add_custom_target( set_calibration ${AVR_UPLOADTOOL} ${AVR_UPLOADTOOL_BASE_OPTIONS} -P ${AVR_UPLOADTOOL_PORT} -U calibration:w:${AVR_MCU}_calib.hex COMMENT "Program calibration status of internal oscillator from ${AVR_MCU}_calib.hex." ) endfunction()

    `

    but what is happening here exactly? Could anyone elaborate or point me to to the documentation for these details? Also, as stated in the topic, how does this cmake-avr interact with avrdude or some other mechanisms to upload the code to my mcu?

    opened by IJkb 2
  • Paths to elf, hex, lst and map files are more flexible

    Paths to elf, hex, lst and map files are more flexible

    This should fix problem with file location when building in customdirectory. Add frequency speed into compiler flags. Unless variable is cache, they should be lower_case. But if required, I can change it to UPPER_CASE.

    opened by MartinStej 0
  • Add target debug (simavr, simulavr, avarice, etc)

    Add target debug (simavr, simulavr, avarice, etc)

    First of all, thank you for this project, it's really nice.

    Would like to ask if it's any development towards, a custom target that runs ie. simavr, and connect to it, without to running it on every compile. I find tedious to make && simavr -t ... & and in other window / tab avr-gdb file foo and inside gdb target remote localhost:port.

    If there are none, I did a little modification in the code to do this automatically, and it could be modified to work with other ie. simulavr, avarice... I could pull request it for your review, if it's fine.

    opened by icyd 2
  • MCU specific libc

    MCU specific libc

    When I use find_package(C_LIB c) for my (atmega128) project, I get the wrong /usr/lib/avr/lib/libc.a when I require /usr/lib/avr/lib/avr51/libc.a. Is there a way to indicate this architecture specific setting to cmake?

    question wontfix 
    opened by pdgendt 4
Owner
Matthias Kleemann
Matthias Kleemann
CMake toolchain for all Arduino compatible boards

Arduino CMake Toolchain Arduino CMake toolchain is a CMake toolchain for cross-compiling CMake based projects for all Arduino compatible boards (AVR,

Arun 97 Jun 6, 2022
A toolchain file and examples using cmake for iOS development

ios-cmake A toolchain file and examples using cmake for iOS development. This is a fork of a similar project found on https://code.google.com/p/ios-cm

Bogdan Cristea 303 Jun 9, 2022
CMake toolchain file and other scripts for the Android NDK

android-cmake CMake is great, and so is Android. This is a collection of CMake scripts that may be useful to the Android NDK community. It is based on

Andrey Kamaev 1.2k Jun 19, 2022
A minimal CMake template for Qt 5 & 6 projects

Minimal CMake Template for Qt 6 Projects This project is updated for Qt 6. Visit qt5 branch if you are looking for the Qt 5 template. This is a minima

Vincent Lee 177 May 30, 2022
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CPM.cmake 1.2k Jun 27, 2022
CMake checks cache helper modules – for fast CI CMake builds!

cmake-checks-cache Cross platform CMake projects do platform introspection by the means of "Check" macros. Have a look at CMake's How To Write Platfor

Cristian Adam 58 May 22, 2022
CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Lin

Jose Luis Blanco-Claraco 379 Jun 23, 2022
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

Anders Lindgren 37 Dec 30, 2021
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

IXM 99 Feb 14, 2022
CMake module to enable code coverage easily and generate coverage reports with CMake targets.

CMake-codecov CMake module to enable code coverage easily and generate coverage reports with CMake targets. Include into your project To use Findcodec

HPC 76 Jun 1, 2022
unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

Jonathan Müller 72 Apr 14, 2022
[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

julp 29 Apr 26, 2022
A template for projects using both libPeConv and MS Detours

A CMake template for projects using MS Detours along with libPeConv.

hasherezade 11 Mar 16, 2022
CMake project for BL602 RISC-V processor

bl602_cmake_base CMake project for BL602 RISC-V processor How to build NOTE : This project uses a pre-compiled version of the Buffalo SDK (bl_iot_sdk)

null 9 Jan 6, 2022
curl cmake module libcurl build with msvc x86

curl-msvc Infomation curl cmake module libcurl build with MSVC10.0 arch (x86 | i386) source from https://github.com/curl/curl tags: curl-7_79_1 Usage

Jason Payne 0 May 16, 2022
NeoWorld is a resampler using the CMake build system

NeoWorld is a resampler using the CMake build system. It's designed for utsu, OpenUTAU, and UTAU.

null 4 Jun 24, 2022
A CMake addon that avoids you writing boilerplate code for resource management.

SHader INJ(I)ector SHINJI (originally SHader INJector) is a CMake addon that avoids you writing boilerplate code for resource management and exposes s

Lorenzo Rutayisire 6 Mar 21, 2022
A CMake starter template using CPM

Cmake Starter About A lightweight Cmake project meant for a binary application (not a shared library), tests with catch2 are configured, CPM is the pa

Matt Williams 1 Mar 24, 2022
Non-intrusive CMake dependency management

cmodule Non-intrusive CMake dependency management. Normally CMake's find_package() looks for packages installed on host system (and compiled for host

scapix.com 13 Jun 16, 2022