Building a library for use with RTEMS via CMake

Robin Müller robin.mueller.m at gmail.com
Wed Jul 21 14:48:45 UTC 2021


tems-cmake uses the toolchain file functionality which takes care of
finding the RTEMS compiler and add the required flags for RTEMS.
If the CMakeLists.txt belongs to a library, I would guess you will compile
it as part of a  (dummy) project and you can still edit the top
CMakeLists.txt?
If you still need a custom toolchain file you can probably write your own
toolchain file and then include the rtems-cmake toolchain file but I have
never
tested doing something like that.

As long as your library does not require setting another toolchain file as
well, compiling it should not be an issue.

Kind Regards
Robin

On Wed, 21 Jul 2021 at 16:48, Robin Müller <robin.mueller.m at gmail.com>
wrote:

> rtems-cmake uses the toolchain file functionality which takes care of
> finding the RTEMS compiler and add the required flags for RTEMS.
> If the CMakeLists.txt belongs to a library, I would guess you will compile
> it as part of a  (dummy) project and you can still edit the top
> CMakeLists.txt?
> If you still need a custom toolchain file you can probably write your own
> toolchain file and then include the rtems-cmake toolchain file but I have
> never
> tested doing something like that.
>
> As long as your library does not require setting another toolchain file as
> well, compiling it should not be an issue.
>
> Kind Regards
> Robin
>
> On Tue, 20 Jul 2021 at 13:07, <Andre.Nahrwold at dlr.de> wrote:
>
>> Hey guys,
>>
>>
>>
>> that was so far very helpful in understanding the problem in more depth.
>>
>> Putting in the right flags at least reduced the linker errors by nearly
>> 99% or so, Thanks.
>>
>> Maybe I am on the right path now and just need to tweak it a bit to make
>> it work.
>>
>>
>>
>> The rtems-cmake repository looks also very promising to me, I surely have
>> to dig deeper into the processes going on there.
>>
>> Problem is that I should (ideally) not change the CMakeLists.txt from the
>> library so it stays independent.
>>
>> Do you have any thoughts on that Robin?
>>
>> Do you think wrapping the library CMakeLists.txt in another one which
>> then uses the repository might work?
>>
>>
>>
>> But I realized that I have missed some information while explaining this
>> issue.
>>
>> The RTEMS application itself is built with SCons and therefore the
>> desired build environment (flags and so forth) is already defined within a
>> python dictionary.
>>
>> Now we need to somehow build the library via CMake using the established
>> environment, install and link against it via SCons.
>>
>> Do you have worked with something  like this before?
>>
>>
>>
>> Best regards
>>
>> André
>>
>>
>>
>> *Von:* devel <devel-bounces at rtems.org> *Im Auftrag von *Robin Müller
>> *Gesendet:* Dienstag, 20. Juli 2021 11:46
>> *An:* Michael Davidsaver <mdavidsaver at gmail.com>; devel at rtems.org
>> *Betreff:* Re: Building a library for use with RTEMS via CMake
>>
>>
>>
>> I managed to compile our project with CMake, using this repository:
>> https://github.com/spacefisch/rtems-cmake
>>
>> It uses the pkg-config files to set up the cross compiler given the BSP
>> and RTEMS prefix information.
>>
>>
>>
>> Maybe this can help you
>>
>>
>>
>> Kind Regards
>>
>> Robin
>>
>>
>>
>> On Tue, 20 Jul 2021 at 00:50, Michael Davidsaver <mdavidsaver at gmail.com>
>> wrote:
>>
>> On 7/19/21 6:17 AM, Andre.Nahrwold at dlr.de wrote:
>> > Hello,
>> >
>> > I have built RTEMS 5 and its tools for the Xilinx Zynq Zedboard and
>> installed the BSP and tools at a certain position on my machine.
>> > The tools are added to the PATH variable and RTEMS_BSPS is also
>> available in the environment.
>> >
>> > Now we need to build a library for the use with RTEMS via CMake.
>> > For this we wanted to use the toolchain files.
>> > Does anybody know how to correctly setup such a toolchain file using
>> the RTEMS compiler?
>> >
>> > We managed to get a toolchain file working which at least built the
>> library.
>> > But when we wanted to link to this library during compilation of a
>> RTEMS application we got a bunch of errors due to undefined references to
>> standard library functions.
>> > Does anybody has a clue where this might origin from?
>>
>> As it happens, I went through this exercise recently with libevent.
>> The main obstacle for me was that the CMake try_compile() command
>> actually tries to link an executable.  With RTEMS 5 this can't be
>> done generically without also adding '-lrtemsdefaultconfig'.
>>
>> eg.
>>
>> > string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -lrtemsdefaultconfig")
>>
>> Also, if you use networking you might want to add.
>>
>> > set(CMAKE_REQUIRED_LIBRARIES "-lbsd")
>>
>> for eg. CheckFunctionExists.cmake to work correctly.
>>
>>
>> The (fairly complex) result of this all can be found here:
>>
>> https://github.com/mdavidsaver/pvxs/tree/master/bundle
>>
>> The essential parts are:
>>
>> - cmake/RTEMS.cmake@
>>
>> Template toolchain file.  (expand using definitions from RTEMS makefiles)
>>
>> - cmake/Platform/
>>
>> Hooks into the CMake startup process.  The exact interplay between
>> Platform/ and toolchain file is... quite involved.  Also not well
>> documented.  The best I've found is:
>>
>>
>> https://github.com/Kitware/CMake/blob/f86d8009c6a4482c81221114a2b04b375564cc94/Source/cmGlobalGenerator.cxx#L461-L504
>>
>>
>>
>> > Building a RTEMS application which does not use the own library works
>> fine.
>> >
>> > Our toolchain file looks like this:
>> >
>> > # CMake toolchain file for ARM
>> > # The compiler is based on
>> > # The RTEMS_BSPS environment variable is expected to be set.
>> > set(ARCH arm)
>> > set(CMAKE_SYSTEM_NAME RTEMS5)
>> >
>> > set(CMAKE_CXX_FLAGS "" CACHE STRING "ARM RTEMS5 gcc additional compiler
>> flags" FORCE)
>> >
>> > set(RTEMS_TOOLS_PATH $ENV{RTEMS_BSPS}/../../tools/bin)
>> >
>> > set(CMAKE_C_COMPILER ${RTEMS_TOOLS_PATH}/arm-rtems5-gcc CACHE PATH "ARM
>> RTEMS5 gcc" FORCE)
>> > set(CMAKE_CXX_COMPILER ${RTEMS_TOOLS_PATH}/arm-rtems5-gcc CACHE PATH
>> "ARM RTEMS5 gcc" FORCE)
>> > set(CMAKE_CXX_COMPILER_AR ${RTEMS_TOOLS_PATH}/arm-rtems5-gcc-ar CACHE
>> PATH "ARM RTEMS5 ar" FORCE)
>> > set(CMAKE_CXX_COMPILER_RANLIB ${RTEMS_TOOLS_PATH}/arm-rtems5-gcc-ranlib
>> CACHE PATH "ARM RTEMS5 gcc ranlib" FORCE)
>> > set(CMAKE_RANLIB ${RTEMS_TOOLS_PATH}/arm-rtems5-ranlib CACHE PATH "ARM
>> RTEMS5 ranlib" FORCE)
>> > set(CMAKE_READELF ${RTEMS_TOOLS_PATH}/arm-rtems5-readelf CACHE PATH
>> "ARM RTEMS5 readelf" FORCE)
>> > set(CMAKE_STRIP ${RTEMS_TOOLS_PATH}/arm-rtems5-strip CACHE PATH "ARM
>> RTEMS5 strip" FORCE)
>> > set(CMAKE_ADDR2LINE ${RTEMS_TOOLS_PATH}/arm-rtems5-addr2line CACHE PATH
>> "ARM RTEMS5 addr2line" FORCE)
>> > set(CMAKE_LINKER ${RTEMS_TOOLS_PATH}/arm-rtems5-ld CACHE PATH "ARM
>> RTEMS5 ld" FORCE)
>> > set(CMAKE_NM ${RTEMS_TOOLS_PATH}/arm-rtems5-nm CACHE PATH "ARM RTEMS5
>> nm" FORCE)
>> > set(CMAKE_OBJCOPY ${RTEMS_TOOLS_PATH}/arm-rtems5-objcopy CACHE PATH
>> "ARM RTEMS5 objcopy" FORCE)
>> > set(CMAKE_OBJDUMP ${RTEMS_TOOLS_PATH}/arm-rtems5-objdump CACHE PATH
>> "ARM RTEMS5 objdump" FORCE)
>> >
>> > set(CMAKE_TARGET_CONFIG_POSTFIX .rtems5_gcc_arm)
>> >
>> > Best regards
>> > Andre Nahrwold
>> > --------------------------
>> > Deutsches Zentrum für Luft- und Raumfahrt e. V. (DLR)
>> > German Aerospace Center
>> > Institute for Software Technolog | SRV-OSS BS | Lilienthalpl. 7 | 38108
>> Braunschweig | Geb. 112C Raum 001
>> > M.Sc. Andre Nahrwold | Telephone +49 531 295-3834 |
>> andre.nahrwold at dlr.de
>> > DLR.de
>> >
>> > _______________________________________________
>> > users mailing list
>> > users at rtems.org
>> > http://lists.rtems.org/mailman/listinfo/users
>> >
>>
>> _______________________________________________
>> users mailing list
>> users at rtems.org
>> http://lists.rtems.org/mailman/listinfo/users
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20210721/3c5bab56/attachment-0001.html>


More information about the devel mailing list