This is my configure command:
cmake -B../build_atmega328 -S. -G Ninja -D CMAKE_C_COMPILER=C:\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-gcc.exe -D CMAKE_CXX_COMPILER=C:\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-g++.exe
This is the output:
E:\MyProject\display\display_controller>cmake -B../build_atmega328 -S. -G Ninja -D CMAKE_C_COMPILER=C:\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-gcc.exe -D CMAKE_CXX_COMPILER=C:\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-g++.exe-- The CXX compiler identification is GNU 7.3.0-- The C compiler identification is GNU 7.3.0-- Detecting CXX compiler ABI info-- Detecting CXX compiler ABI info - failed-- Check for working CXX compiler: C:/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++.exe-- Check for working CXX compiler: C:/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++.exe - brokenCMake Error at C:/Program Files/CMake/share/cmake-3.31/Modules/CMakeTestCXXCompiler.cmake:73 (message): The C++ compiler"C:/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: 'E:/MyProject/display/build_atmega328/CMakeFiles/CMakeScratch/TryCompile-njpofd' Run Build Command(s): E:/ninja/ninja.exe -v cmTC_3ce41 [1/2] C:\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-g++.exe -o CMakeFiles/cmTC_3ce41.dir/testCXXCompiler.cxx.obj -c E:/MyProject/display/build_atmega328/CMakeFiles/CMakeScratch/TryCompile-njpofd/testCXXCompiler.cxx [2/2] C:\Windows\system32\cmd.exe /C "cd . && C:\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-g++.exe CMakeFiles/cmTC_3ce41.dir/testCXXCompiler.cxx.obj -o cmTC_3ce41.exe -Wl,--out-implib,libcmTC_3ce41.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." FAILED: cmTC_3ce41.exe C:\Windows\system32\cmd.exe /C "cd . && C:\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-g++.exe CMakeFiles/cmTC_3ce41.dir/testCXXCompiler.cxx.obj -o cmTC_3ce41.exe -Wl,--out-implib,libcmTC_3ce41.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." c:/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: unrecognized option '--out-implib' c:/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: use the --help option for usage information collect2.exe: error: ld returned 1 exit status ninja: build stopped: subcommand failed.
Here is CMakeLists.txt
:
# I target a recent cmake, it shouldn't be a problem on a dev machinecmake_minimum_required(VERSION 3.11)# Project nameproject("ConnectionsDisplay" VERSION 0.1 LANGUAGES CXX C)set(CMAKE_CXX_STANDARD 17)set(CMAKE_CXX_STANDARD_REQUIRED ON)set(CMAKE_EXPORT_COMPILE_COMMANDS ON)# Product filenameset(PRODUCT_NAME connections_display)## AVR Chip Configuration# 8Mhz, this should match the crystal on your board,# I use 8Mhz and 3.3V for the lowest power consumptionset(F_CPU 8000000UL)# CPU, you can find the list here:# https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.htmlset(MCU atmega328p)# Default Baudrate for UART, read avr include/util/setbaud.h for usageset(BAUD 9600)# The programmer to use, read avrdude manual for listset(PROG_TYPE avrispmkII)# AVR Fuses, must be in concordance with your hardware and F_CPU# http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328pset(E_FUSE 0xfd)set(H_FUSE 0xda)set(L_FUSE 0xfd)set(LOCK_BIT 0xff)set(CMAKE_AVR_TOOL_COMPILERS "C:\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7\\bin")# Pass defines to compileradd_definitions( -DF_CPU=${F_CPU} -DBAUD=${BAUD})# mmcu MUST be passed to bot the compiler and linker, this handle the linkerset(CMAKE_EXE_LINKER_FLAGS -mmcu=${MCU})add_compile_options( -mmcu=${MCU} # MCU -Os # optimize -Wall # enable warnings -Wno-main -Wundef -pedantic -Wstrict-prototypes -Werror -Wfatal-errors -Wl,--relax,--gc-sections -g -gdwarf-2 -funsigned-char # a few optimizations -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -fno-split-wide-types -fno-tree-scev-cprop)file(GLOB SRC_FILES "src/*.cpp" "src/*.c") # Load all files in src folder# Create one targetadd_executable(${PRODUCT_NAME} ${SRC_FILES})# Rename the output to .elf as we will create multiple filesset_target_properties(${PRODUCT_NAME} PROPERTIES OUTPUT_NAME ${PRODUCT_NAME}.elf)# Strip binary for uploadadd_custom_target(strip ALL avr-strip ${PRODUCT_NAME}.elf DEPENDS ${PRODUCT_NAME})# Transform binary into hex file, we ignore the eeprom segments in the stepadd_custom_target(hex ALL avr-objcopy -R .eeprom -O ihex ${PRODUCT_NAME}.elf ${PRODUCT_NAME}.hex DEPENDS strip)# Transform binary into hex file, this is the eeprom part (empty if you don't# use eeprom static variables)add_custom_target(eeprom avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex ${PRODUCT_NAME}.elf ${PRODUCT_NAME}.eep DEPENDS strip)# Clean extra filesset_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PRODUCT_NAME}.hex;${PRODUCT_NAME}.eeprom;${PRODUCT_NAME}.lst")