[CMake] Multiple dependencies to library which needs to be built with different flags

irukandji irukandji at voidptr.eu
Fri Apr 13 05:47:43 EDT 2012


Hi,

I am doing investigation if cmake would fit into project and so far it 
looks great but i have encountered
to an interesting problem i am not able to solve.

--

I have a few libraries which are built in different way (but having 
same sources), for the sake of example i will represent
it that i need shared and static libraries although the case is more 
complicated (PIC, nonPIC...). I have made some structure
where the add_subdirectory is made for that library only if it was 
actually requested from the executable binary to avoid
building libraries even if only partial build of sources is made on 
dev. machine and i would like to keep it this way
(not building shared library if no executable will use it).

A bit of ascii art:

A --uses--> libX
   --uses--> libY
   --uses--> libProblematic(static)

B --uses--> libN
   --uses--> libProblematic(dynamic)

C add_subdirectory( A )
   add_subdirectory( B )


If i start cmake on A the libX and libY are set to be linked to A, then 
some generic function determines the
libProblematic path and sets it to be linked to A, then does 
add_subdirectory on libProblematic.

At build time, the libProblematic is built, then A is built and linked 
to libX, libY libProblematic.

Similar goes for B.

C builds everything.

The scenario for building can be, either A, B, C (C for nightly build, 
A,B for developers).

If libProblematic would only be used as static, this works perfectly. 
The problem is that that some projects should
build it as dynamic. Here I dont know what i should do. If project 
would allow using of variable i could make a
variable and push it to CACHE, then used it with CMakeLists.txt for 
libProblematic but this was a failure for me.

The second solution would be to add multiple CMakeLists.txt but this is 
really a LAST, LAAAAST resort as the differences
between the different libProblematic configurations are minimal and 
making mutiple files out of it will diverge to out of
sync condition...

Thank you for at least reading it, everything else is eternal gratitude 
:)
Irukandji

p.s.: btw i would prefer whatever real scripting language with return 
values from functions and cleaner syntax instead
of what cmake has atm, i can survive but the strange behaviour (like 
lists beeing expanded into argv, set(x , "blah") leaves
x uninitialized,... is killing me :) I have noticed a lua port, what is 
happening with it?



More information about the CMake mailing list