[CMake] C header file cross dependency

Patrick Boettcher patrick.boettcher at posteo.de
Mon Jun 6 05:36:28 EDT 2016


Hi Martin,

On Wed, 1 Jun 2016 14:58:53 +0000
Wagner Martin <Martin.Wagner at neuberger.net> wrote:

> > 
> > Could you provide a working, stripped down example to show the
> > problem provided via github (in an example repo).
> >   
> 
> I've added a simple test project to 
> 
> https://github.com/martinwag/test_cmake/tree/master
> 
> Note that this example does not need cross gcc for ARM. It doesn't
> implement any useful functionality!

I forked your repo and played a little bit around. 

https://github.com/pboettch/test_cmake

Here are my conclusions:

1) Due to the use of add_libary(... OBJECTS ...) you cannot link
libraries with libraries or interfaces, this is a pity - especially for
a complex project with a lot of sub-dirs. 

There is a possibility to merge STATIC-libraries to generated one big
archive using external tools (libtool). If I were you I'd try to
this way to profit from the target_*-cmake-features.

2) I created a log-dir with an interface-library - which only carries
the log.h and thus the printf-prototypes

3) Both, drivers and terminal link with this interface-library (to get
their hands on log.h)

4) In addition I added two libraries to drivers/ uart-logging1 and
uart-logging2. This shows how you could compile-configure your
printf-function depending on the hardware used. In the main CMakeLists
you just need to select one of them - depending on the option's value.

Basically I followed the idea of instantiating a print-function
'somewhere' in the project (it could also be done outside) and then
select the one you want to use at the final link.

Of course this way you could add other ways of printf'ing - logging1
and logging2 are just stupid examples.

HTH and sorry for the delay,
--
Patrick.





More information about the CMake mailing list