Multiple XCommon libraries in a single repository

If you have a simple question and just want an answer.
MyKeys
Active Member
Posts: 36
Joined: Mon Jul 03, 2017 9:41 am

Multiple XCommon libraries in a single repository

Post by MyKeys »

Hi, is there a mechanism for having multiple XCommon Cmake modules within a single repository?

Looking at the dependecny format page shows how to use your own git server but it seems it is expected to use a seperate repository per library.

I have lots of small libraries that I'd rather have in a single repo rather than coming up with some creative naming scheme for indicating platform/project/function etc. to the rest of the org.

Thanks,
Mike
User avatar
upav
Verified
Active Member
Posts: 36
Joined: Wed May 22, 2024 3:30 pm

Post by upav »

As far as I remember, the philosophy behind xcommon_cmake was "one module per repo", I might be wrong here tho.

However, I think you can have a few modules and just trick xcommon_cmake into thinking it's a single one.
xcommon_cmake doesn't build static libraries, so all files from your library will be compiled with your application.
In cmake it's called an interface library, when your library doesn't compile into a .a and each app compiles its own copy of the library.
There are several advantages and disadvantages of this approach, but I won't go into this here.
So I guess, in your case, it doesn't really matter if xcommon_cmake thinks it's one library or not.
In which case, you can structure your source and api in line with xcommon_cmake guidelines and separate your code into modules all you want!

I would think something like this should work for you:
If your repo name is lib_lib (looks like an emoji, ahah)
lib_lib:
| docs
| lib_lib
___| api
______| lib1.h
______| lib2.h
___| src
______| lib1
_________| lib1.c
______| lib2
_________| lib2.c
(sorry, forum doesn't let me indent)

I'm not sure whether xcommon_cmake will pick up all the source files and headers automatically; you might need to glob them yourself.

Not a super nice solution, but it should work :)
Pavel
xmos software engineer