0

I'm using CMake/make to attempt to build an arduino c++ project on MacOS, for some reason it is attempting to pass -isysroot to avr-as. Does anyone know how to get rid of it?

avr-as  -I/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/libraries/EEPROM/src -I/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/a
rduino -I/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/standard -I/Users/david/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1
-arduino7/avr/include -I/Users/david/C/arduino/avr-libstdcpp/include -isysroot /Applications/Xcode14.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX1
3.0.sdk -o CMakeFiles/untitled.dir/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/wiring_pulse.S.o -c /Users/david/Library/Arduino15/packages
/arduino/hardware/avr/1.8.6/cores/arduino/wiring_pulse.S
avr-as: unrecognized option `-isysroot'
make[2]: *** [CMakeFiles/untitled.dir/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/wiring_pulse.S.o] Error 1
make[1]: *** [CMakeFiles/untitled.dir/all] Error 2

my CMakeLists.txt

cmake_minimum_required(VERSION 3.20)

set(HAVE_FLAG_SEARCH_PATHS_FIRST 0)

project(untitled)
project(untitled LANGUAGES C CXX ASM)

set(CMAKE_C_COMPILER avr-gcc)
set(CMAKE_CXX_COMPILER avr-g++)
set(CMAKE_ASM_COMPILER avr-as)

set(CMAKE_C_COMPILER_FORCED 1)
set(CMAKE_CXX_COMPILER_FORCED 1)

#set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#sanitizers: address, thread, undefined, safe-stack
set(CMAKE_CXX_FLAGS "-DF_CPU=16000000 -D__AVR_ATmega16U2__=1 -DTX_RX_LED_INIT=0 -DRXLED0=0 -DTXLED0=1 -DRXLED1=5 -DTXLED1=6 -DLED01=13 -DUSB_VID=0x2341 -DUSB_PID=0x0036 -usb_product=32u416m -mmcu=atmega2560 -O2")
set(CMAKE_C_FLAGS "-DF_CPU=16000000 -D__AVR_ATmega16U2__=1 -DTX_RX_LED_INIT=0 -DRXLED0=0 -DTXLED0=1 -DRXLED1=5 -DTXLED1=6 -DLED01=13 -DUSB_VID=0x2341 -DUSB_PID=0x0036 -usb_product=32u416m -mmcu=atmega2560 -O2")
set(CMAKE_ASM_FLAGS "")

file(GLOB SOURCES "/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/*.cpp" "/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/*.c" "/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/*.S" "main.cpp")

add_executable(untitled ${SOURCES})

# changes c++ standard from gnu++YEAR to c++YEAR
# seems to fix issues using bear and clangd
set_target_properties(untitled PROPERTIES CXX_EXTENSIONS OFF)

target_include_directories(untitled PUBLIC "/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/libraries/EEPROM/src/")
target_include_directories(untitled PUBLIC "/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/")
target_include_directories(untitled PUBLIC "/Users/david/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/variants/standard")
target_include_directories(untitled PUBLIC "/Users/david/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include/")
target_include_directories(untitled PUBLIC "/Users/david/C/arduino/avr-libstdcpp/include")
David Carpenter
  • 1,389
  • 2
  • 16
  • 29
  • Setting variable `CMAKE_C_COMPILER` after the `project()` call is wrong: https://stackoverflow.com/a/63944545/3440745. You are better to prepare a [toolchain file](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling) and describe cross-compiling aspects there. – Tsyvarev Apr 09 '23 at 09:20
  • In most cases, you want to use `avr-gcc` (the compiler driver) to invoke the assembler, not `avr-as` directly. `avr-gcc -c *.S` will pre-compile the source and then call the assembler with the right options. Notice that `-c` is only supported by `gcc`, not `as`. Also, to provide additional system include path, you would use `gcc -isystem ` and not `-I `. – emacs drives me nuts Apr 17 '23 at 11:30

0 Answers0