[Cmake] our tip - library dependencies

Petr Ferschmann petr at ferschmann . cz
28 Jul 2003 18:22:10 +0200


--=-whapao+ApE5g5p9EybEi
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Hello,

I want to tell you some tip we use in Kerio technologies.
This is not bug but rather some ideas, I want to share.

We have this situation:

root
+--- lib1
|=20
+--- lib2
|
+--- lib3
|
+--- program

and lib[n+1] depends on lib[n] (ie. lib3 depends on lib2).

Let say lib1 depends on OpenSSL and Kerberos.=20
So we have this variables:
lib1_INCLUDES - contains include directories
lib1_CPPFLAGS - contains flags that we get from krb5-config --cflags
	krb5=20
lib1_LIBDIRS - link directories
lib1_LIBS - libraries to link with
lib1_DEPS - dependencies between libraries. We have used
ADD_DEPENDENCIES but it is unusable on windows. We added that lib1
depends on lib2. But when there were diamant situation (lib1  depends on
lib2, lib3 depends on lib1, and lib4 depends on lib2 and lib3) the
object files from lib1 were included lib2 and lib3. So there was
warning. So now we add dependencies only for executables. And also we
add them only on windows (on Linux it doesn't work - we are using CVS
version).

So on library declaration we create this variables and they inherit.
(eg. lib2_INCLUDES also uses lib1_INCLUDES).

We created some macros for that:
MACRO(KERIO_DEP name deps)
  SET(${name}_LIBS "${${name}_LIBS};${${deps}_LIBS}" CACHE INTERNAL "-"
FORCE)
  SET(${name}_LIBDIRS "${${name}_LIBDIRS};${${deps}_LIBDIRS}" CACHE
INTERNAL "-" FORCE)
  SET(${name}_DEPS "${${name}_DEPS};${${deps}_DEPS}" CACHE INTERNAL "-"
FORCE)
  SET(${name}_INCLUDES "${${name}_INCLUDES};${${deps}_INCLUDES}" CACHE
INTERNAL "-" FORCE)
  SET(${name}_CPPFLAGS "${${name}_CPPFLAGS} ${${deps}_CPPFLAGS}" CACHE
INTERNAL "-" FORCE)
ENDMACRO(KERIO_DEP)

MACRO(KERIO_LIBRARY name dirname includes cppflags libs libdirs)
  SET(${name}_LIBS "${name}${DEBUGSUFFIX};${libs}" CACHE INTERNAL "-"
FORCE)
  SET(${name}_LIBDIRS "${${dirname}_BINARY_DIR};${libdirs}" CACHE
INTERNAL "-" FORCE)
  SET(${name}_DEPS "${name}${DEBUGSUFFIX};${deps}" CACHE INTERNAL "-"
FORCE)
  SET(${name}_INCLUDES "${${name}_INCLUDES}/include;${includes}" CACHE
INTERNAL "-" FORCE)
  SET(${name}_CPPFLAGS "${cppflags}" CACHE INTERNAL "-" FORCE)
ENDMACRO(KERIO_LIBRARY)
--------------------

And now we can use:
KERIO_LIBRARY(lib1 "lib1" "" "" "" "")
KERIO_LIBRARY(lib2 "lib2" "" "" "" "")
KERIO_DEP(lib2 lib1)
KERIO_LIBRARY(lib3 "lib3" "" "" "" "")
KERIO_DEP(lib3 lib1)

and it does dirty job for us.

I hope this will help you. Usage of this code is not limited on any way.

		With regards

--=20
                                  Petr "Fers" Ferschmann

 -=3D[  petr at ferschmann . cz  ]=3D=3D[ http://petr . ferschmann . cz/ ]=3D-
-=3D[ Koukni na http://www . postcard . cz/ ]=3D=3D[ +420 604/781 009 ]=3D-

GPG Fingerprint:
[83B0 6378 7A9D D993 035E  60BD FEEC F665 D2C8 1B9A]


--=-whapao+ApE5g5p9EybEi
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: Toto je =?iso-8859-2?Q?digit=E1ln=EC?=
	=?ISO-8859-1?Q?_podepsan=E1?= =?iso-8859-2?Q?_=E8=E1st?=
	=?ISO-8859-1?Q?_zpr=E1vy?=

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQA/JU2xKTvcB3Rwi3URAonNAJ0e5CuT/0b7z12uMOwd1QkXwaqrYgCgklfF
J854LpXRqZA8KG8yuKZf720=
=MDtk
-----END PGP SIGNATURE-----

--=-whapao+ApE5g5p9EybEi--