I'm sorry for not posting all the info in the first post...
What I was trying to do is to compile and upload the code in the arduino board using cmake. I found some code on the net but it
is too complicated from my point of view, and so I wrote my own.
My intention is to clean the file after it works and make it available to other people.
This is my CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER avr-gcc)
set(CMAKE_CXX_COMPILER avr-g++)
set(CSTANDARD "-std=gnu99")
set(CDEBUG "-gstabs")
set(CWARN "-Wall -Wstrict-prototypes")
set(CTUNING "-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums")
set(COPT "-Os")
set(CMCU "-mmcu=atmega168")
set(CDEFS "-DF_CPU=16000000")
set(CFLAGS "${CMCU} ${CDEBUG} ${CDEFS} ${COPT} ${CWARN} ${CSTANDARD} ${CEXTRA}")
set(CXXFLAGS "${CMCU} ${CDEFS} ${COPT}")
set(CMAKE_C_FLAGS ${CFLAGS})
set(CMAKE_CXX_FLAGS ${CXXFLAGS})
set(ARDUINO_SRC_DIR "${CMAKE_SOURCE_DIR}/../arduino-1.0.3") #this is the directory containing the arduino ide and the other files
include_directories(${ARDUINO_SRC_DIR}/hardware/arduino/cores/arduino)
include_directories(${ARDUINO_SRC_DIR}/hardware/arduino/variants/standard)
include_directories(${ARDUINO_SRC_DIR}/libraries/SoftwareSerial)
#creation of a library containing the core functionalities from the arduino project
#the library contains also the file main.cpp which declares the main function
file(GLOB ARDUINO_CORE_CPP "${ARDUINO_SRC_DIR}/hardware/arduino/cores/arduino/*.cpp")
file(GLOB ARDUINO_CORE_C "${ARDUINO_SRC_DIR}/hardware/arduino/cores/arduino/*.c")
add_library(arduinocore ${ARDUINO_CORE_C} ${ARDUINO_CORE_CPP})
#creation of the library with the SoftwareSerial code
add_library(SoftwareSerial ${ARDUINO_SRC_DIR}/libraries/SoftwareSerial/SoftwareSerial.cpp)
#creation of my executable
add_executable(change_splash change_splash.cpp)
target_link_libraries(change_splash SoftwareSerial arduinocore)
#code for the conversion elf -> hex
add_custom_target(hex
COMMAND avr-objcopy -O ihex -R .eeprom change_splash output.hex
DEPENDS change_splash)
#code for the upload
add_custom_target(upload
COMMAND avrdude -V -c arduino -p m168 -b 19200 -P /dev/ttyUSB0 -U flash:w:output.hex
DEPENDS hex)
With this file and the one I put in my previous post (change_splash.cpp) I did the following:
1) cd change_splash (this is the directory containing change_splash.cpp and CMakeLists.txt)
2) mkdir build
3) cd build
4) cmake ..
Output:
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/csavorgn/arduino/change_splash/build
5) make VERBOSE=1
Output ( I cut part of it, but there are no error messages)
....
[100%] Building CXX object CMakeFiles/change_splash.dir/change_splash.cpp.o
avr-g++ -mmcu=atmega168 -DF_CPU=16000000 -Os -I/home/csavorgn/arduino/change_splash/../arduino-1.0.3/hardware/arduino/cores/arduino -I/home/csavorgn/arduino/change_splash/../arduino-1.0.3/hardware/arduino/variants/standard -I/home/csavorgn/arduino/change_splash/../arduino-1.0.3/libraries/SoftwareSerial -o CMakeFiles/change_splash.dir/change_splash.cpp.o -c /home/csavorgn/arduino/change_splash/change_splash.cpp
Linking CXX executable change_splash
/usr/bin/cmake -E cmake_link_script CMakeFiles/change_splash.dir/link.txt --verbose=1
avr-g++ -mmcu=atmega168 -DF_CPU=16000000 -Os CMakeFiles/change_splash.dir/change_splash.cpp.o -o change_splash -rdynamic libSoftwareSerial.a libarduinocore.a
avr-g++: unrecognized option '-rdynamic'
make[2]: Leaving directory `/home/csavorgn/arduino/change_splash/build'
/usr/bin/cmake -E cmake_progress_report /home/csavorgn/arduino/change_splash/build/CMakeFiles 20
[100%] Built target change_splash
make[1]: Leaving directory `/home/csavorgn/arduino/change_splash/build'
/usr/bin/cmake -E cmake_progress_start /home/csavorgn/arduino/change_splash/build/CMakeFiles 0
6) make hex VERBOSE=1
Output (I cut the first part):
...
make[3]: Entering directory `/home/csavorgn/arduino/change_splash/build'
avr-objcopy -O ihex -R .eeprom change_splash output.hex
make[3]: Leaving directory `/home/csavorgn/arduino/change_splash/build'
/usr/bin/cmake -E cmake_progress_report /home/csavorgn/arduino/change_splash/build/CMakeFiles
[100%] Built target hex
make[2]: Leaving directory `/home/csavorgn/arduino/change_splash/build'
/usr/bin/cmake -E cmake_progress_start /home/csavorgn/arduino/change_splash/build/CMakeFiles 0
make[1]: Leaving directory `/home/csavorgn/arduino/change_splash/build'
7) make upload VERBOSE=1
Output (I cut the first part):
avrdude -V -c arduino -p m168 -b 19200 -P /dev/ttyUSB0 -U flash:w:output.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "output.hex"
avrdude: input file output.hex auto detected as Intel Hex
avrdude: writing flash (15328 bytes):
Writing | ################################################## | 100% 9.98s
avrdude: 15328 bytes of flash written
avrdude: safemode: Fuses OK
avrdude done. Thank you.
After doing this I checked the board but it doesn't work...
Carlo