CMake and AVR - any experience/thoughts?

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all,

Has anyone played with using CMake instead of writing their own makefiles with avr-gcc? If so, what's your experience been with it?

Apparently, there are some cross-compile facilities with recent versions of it, but as of yet, I haven't yet really played with it.

There has been one passing reference to it by JohanEkdahl in https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=78299, and one unanswered post at: https://www.avrfreaks.net/index.p...

Apart from playing with a cool new technology, my other motive for asking is for the ADD_TEST() command - I'd really like to create some test harnesses (even if they're full-on C++ linking to my little embedded routines) and run them on the host before throwing them at the target.

It'll probably require a bit of thought - such as flags to the native compiler to consider doubles to be 4-bytes and int to be 2-bytes.

-- Damien

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've done just a bit with it as I've always liked the CMake syntax. It is simple enough to build the elf, but a bit more work would have to be done to allow for hex generation, programming and such. I haven't looked at test generation yet either so that may be more difficult, but the cross compilation support is actually pretty nice. Might be worth looking into further.

Martin Jay McKee

As with most things in engineering, the answer is an unabashed, "It depends."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mckeemj wrote:
I've done just a bit with it as I've always liked the CMake syntax. It is simple enough to build the elf, but a bit more work would have to be done to allow for hex generation, programming and such. I haven't looked at test generation yet either so that may be more difficult, but the cross compilation support is actually pretty nice. Might be worth looking into further.

Martin Jay McKee

I've had a bit of a hack and you're right... it seems easy enough to build a .elf file, but I've had to wrap a build script for pre- and post-build operations.

I have attached what I have done below. I'm still a cmake noob, so be nice :)

Comments are welcome, especially those that will further my agenda :P

-- Damien

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you use this with the other commercial compilers? If not, move to gcc forum.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Can you use this with the other commercial compilers? If not, move to gcc forum.

That will depend on whether they can be invoked at the command line - anyone know? If someone can confirm that GCC is the only compiler that can be invoked from a Makefile with command line build paramters then I will, indeed, move this.

Cliff

PS but I have a sneaking suspicion IAR can be used properly too.

PPS just checked my eval version of ICC and file:///D:/iccv7avr/Help/ICCAVR/9-CmdLine4.html#wp488399 in the help files shows that the compiler can be invoked at the command line. So the thread stays here.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the imagecraft complier generates a makefile from the project file list then runs it. I suspect that the imakew it uses expects unix make syntax though...

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes but the advanced programmer can take control of all that themselves and put together a makefile and then either make or cmake it to then invoke iccavr.exe with the chosen command line parameters.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now-a-days, I avoid rocks in my shoes and make files

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We used cmake once a while (~4 years ago) for more complex projects including avr-gcc and iar compiler. The iar can be used from command line, it needs a huge list of options, but that was no issue (except under windos, where the command line length is limited). On the other hand you can call iarbuild.exe, the iar make tool, but then you have to maintain two build environments.

What cmake lacks of was the flexibility to integrate other tools and the dependency managment. The idea with the wrapper script sounds promising in terms of tools. But which script language do you use if you have to build under both windows and linux?

Sooner or later we found scons more promising and flexible and we changed the system. The advantage of scons is the automatic dependency generation, so you never again have to do a "make clean" to be shure that all is build correctly, because even the command line options are in the dependency hash. On the other hand there are some tricks needed to keep scons fast if the project is growing, but this should be topic of another thread....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good afternoon everybody. I know this topic is really old but I think this is the right place to write.

I'm trying to use cmake for compiling my program and I reached the stage where I can fully compile my C source file. The problem is that I have 2 asm file to compile too. I googled for it but I didn't find anything on this subject. Someone here have some idea on how to do this?

The C project is compiled using those files:

SET(CMAKE_SYSTEM_NAME Generic)

#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH /usr/lib/gcc/avr )

SET(CMAKE_C_COMPILER avr-gcc)
SET(CMAKE_CXX_COMPILER avr-g++)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

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=atxmega64d3")
SET(CDEFS "-DF_CPU=32000000")


SET(CFLAGS "${CMCU} ${CDEBUG} ${CDEFS} ${CINCS} ${COPT} ${CWARN} ${CSTANDARD} ${CEXTRA}")
SET(CXXFLAGS "${CMCU} ${CDEFS} ${CINCS} ${COPT}")

SET(CMAKE_C_FLAGS  ${CFLAGS})
SET(CMAKE_CXX_FLAGS ${CXXFLAGS})

in the CMakeLists.txt I placed all my c files in sources and wrote:

add_executable(main  ${SOURCES}) 

at the end.
when I compile it obviously linker fail for missing functions in asm file.
Thank you for your help.
A

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everybody.
I came into this post today. I'm just writing how I solve it for future references and in the case someone needs the same info.
http://stackoverflow.com/questions/15132185/mixing-c-sources-and-assembly-source-and-build-with-cmake this is what worked for me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There were things which appealed and puzzled me:

Quote:
Apart from playing with a cool new technology, my other motive for asking is for the ADD_TEST() command - I'd really like to create some test harnesses (even if they're full-on C++ linking to my little embedded routines) and run them on the host before throwing them at the target.

Well, it would be very difficult to test from a PC (perhaps with a debugger? maybe the tests would be more complicated than the features to be tested..

Quote:
It'll probably require a bit of thought - such as flags to the native compiler to consider doubles to be 4-bytes and int to be 2-bytes.

Maybe part of it can be avoided with stdint , which makes integer types portable .

There is something I do not know: I can put in a makefile some rules to indent a file, other to store my directory with a timestamp, and another to make printable versions of the makefiles, the *.c and *.h (all these rules are platform independant , of course). Is cmake able to do that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Is cmake able to do that?

Yes. You can simply run external commands with:

http://www.cmake.org/cmake/help/...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BTW has anyone else succeeded in getting Cmake to work in Windows with avr-gcc as a cross compiler? I just tried this:

E:\avr>type CmakeLists.txt
set(CMAKE_SYSTEM_NAME generic)
set(CMAKE_CROSSCOMPILING 1)
set(CMAKE_C_COMPILER avr-gcc)
set(CMAKE_CXX_COMPILER avr-g++)
set(CMAKE_C_FLAGS "-g -Os")
set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS "-lm")
project("avr_prog")
set( SRC
        test.c
        add.c
)
add_executable(program ${SRC})

(yeah I know - but it's sort of minimal options). I then:

E:\avr>md build

E:\avr>cd build

E:\avr\build>\valeoJan\tools\cmake-2.8.2-win32-x86\bin\cmake -G"Unix Makefiles" ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: E:/WinAVR-20100110/bin/avr-gcc.exe
-- Check for working C compiler: E:/WinAVR-20100110/bin/avr-gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: E:/WinAVR-20100110/bin/avr-g++.exe
-- Check for working CXX compiler: E:/WinAVR-20100110/bin/avr-g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: E:/avr/build

E:\avr\build>make
make[2]: *** [CMakeFiles/program.dir/depend] Error 1
make[1]: *** [CMakeFiles/program.dir/all] Error 2
make: *** [all] Error 2

E:\avr\build>make VERBOSE=1
E:/valeoJan/tools/cmake-2.8.2-win32-x86/bin/cmake.exe -HE:/avr -BE:/avr/build --check-build-system CMakeFiles/Makefile.c
make 0
E:/valeoJan/tools/cmake-2.8.2-win32-x86/bin/cmake.exe -E cmake_progress_start E:/avr/build/CMakeFiles E:/avr/build/CMake
Files/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `E:/avr/build'
make -f CMakeFiles/program.dir/build.make CMakeFiles/program.dir/depend
make[2]: Entering directory `E:/avr/build'
E:/valeoJan/tools/cmake-2.8.2-win32-x86/bin/cmake.exe -E cmake_depends "Unix Makefiles" E:/avr E:/avr E:/avr/build E:/av
r/build E:/avr/build/CMakeFiles/program.dir/DependInfo.cmake --color=
make[2]: *** [CMakeFiles/program.dir/depend] Error 1
make[2]: Leaving directory `E:/avr/build'
make[1]: *** [CMakeFiles/program.dir/all] Error 2
make[1]: Leaving directory `E:/avr/build'
make: *** [all] Error 2

That is the Cmake dependency scanning stage is failing. I've googled a bit and the suggestion is that it's because of something to do with running sh.exe on Windows but I cannot immediately resolve it.

Does anyone have a working solution for using Cmake with avr-gcc (WinAVR) code on Windows?

EDIT: BTW if I ask it to create a set of Code::Blocks project files and then load those and build in C:;B I get an almost identical error to do with "-E cmake_depends".