[CMake] Again multiple subdirs

Andreas Pakulat apaku at gmx.de
Tue Feb 7 03:42:22 EST 2012


On 07.02.12 08:55:47, justin wrote:
> Hi,
> 
> and just in the beginning, I am sorry if this was asked thousands of
> times before, but I wasn't able to find it.
> 
> The situation is following
> 
> src -- common -- common.c
>  |
>   ---- a -- a.c
>  |
>   ---- b -- b.c
> 
> 
> add_library (a
>      ${project_SOURCE_DIR}/common/common
>      ${project_SOURCE_DIR}/a/a}
> 
> add_library (b
>      ${project_SOURCE_DIR}/common/common
>      ${project_SOURCE_DIR}/b/b}
> 
> 
> This results in a double compilation of common.c. One time for liba and
> the other one for libb.
> 
> What is the best way to force common.c to be compiled just ones?

If a and b are static libs, create a static lib for the common code and
link both against it. If a and b are shared libs, make the common code a
shared lib too and link a/b against the shared lib.

Andreas



More information about the CMake mailing list