Do I need CMake install() command ?

My goal is to collect my own libraries in one common place from various projects, for example one project exports libsA libraries another project libsB libraries and all that libraries will be collected under MyLibs common folder with corresponding headers that might be in another shared drive that isn’t related to current projects directory tree. new projects will use libraries from MyLibs directory.
MyLibs will contain a subfolder LibsA with static and maybe shared libraries inside and a corresponding headers inside headers directory for each LibsX folder.

Now I’m solving that by changing ARCHIVE_OUTPUT_DIRECTORY for lib, and file(COPY …) command for header files.
problem with that is I’m changing ARCHIVE_OUTPUT_DIRECTORY and it copies library into MyLib folder but current project isn’t have library file anymore. I don’t know maybe that is ok but not sure.

I also got advised that I need to use post build custom command.
feel that my above solution isn’t best.
Some say I better use Install command

In other words too many solutions for doing same and I need advice which is best suited for above case?

Are you libs all independent projects or subdirectories one super build project?

No they might be something not related to each other.
like LibsA which I will export from Algebra project
LibsB is not related to algebra and might be something different, but all of those libs with corresponding headers needs to end up in MyLibs shared common library directory.
It’s also possible that LibsA and LibsB might both be exported from one project, but that doesn’t mean LibsC will be from that project too.
functions/classes in other words all objects from MyLibs I need to be linkable to any future project.

I need to automate that process somehow, to make custom lib that I found reusable for other projects
to end up into MyLibs and its corresponding subdirectories.

Than you should export your cmake config packages for each project to a common stagedir

i.e. install each project to /user/local

Ok thanks for help, which manual I need to read to learn what I need to do step by step ?
what is the name of those steps that I need to do, because I’m not a pro and not even intermediate in CMake, I assume that is some hard task I’m after.

Are that “cmake config packages” method only for linux ?
and why not use install () command ?


see too GitHub - friendlyanon/cmake-init: The missing CMake project initializer

1 Like