Hi,

Thank you all for answering. First, I would like to mention that the
pkg-config alternative isn't very portable. Like other already said, it does
not work well under Microsoft Windows nor MSVC. Also, all paths are wrote in
.pc files which aren't very portable.

I think I might have found a solution to this problem today. Here are the
basics of the idea:

You first need a main configuration file which contains a WORKING_DIR for
the executable to be build as well as a PROJECT_INCLUDE_DIR and a
PROJECT_LIBRARY_DIR (which are in the WORKING_DIR.

For each library, you need two files:
    - A CMake script that tells the CMake engine how to build the library;
    - A configuration file that tells the CMake engine who the library is
and where to get it dependencies.

The trick is in how the CMake engine process the CMake scripts. A feature of
CMake's engine is that it can propagate dependencies up-bottom. This is nice
if you want to use a "master-script" approach but isn't usable if you want
to be able to build every part of the chain independantly. To acheive such
goal, you may want to propagate dependencies bottom-up. As far as I know,
this is not doable natively with the CMake engine but can be acheive with
the basics I've told earlier. Here's a small example:

The project A which contains the A_BuildScript and A_ConfigScript. The
project A needs the project B to build.
The project B which contains the B_BuildScript and B_ConfigScript. The
project B need the third party library C to build.
The library C is built by another build system independantly.

The B_ConfigScript contains the B project's settings as well as where to
find C includes and libraries. Let call the include path
PROJECT_B_INCLUDE_DIR.
The B_BuildScript contains the instructions on how to build the
project Bwith the source files list and what directories to include
(refer to
PROJECT_B_INClUDE_DIR).
The A_ConfigScript contains the A project's settings as well as where to
find the B_ConfigScript. Let's call the include path PROJECT_A_INCLUDE_DIR.
The A_BuildScript contains the instructions on how to build the project A
with the source files life and what directory to include (refer to
PROJECT_A_INClUDE_DIR
and PROJECT_B_INClUDE_DIR).

Depending on how your code has been written, you might need to copy project
B's libraries and include to the PROJECT_LIBRARY_DIR and the
PROJECT_INCLUDE_DIR. This can be done in the A_BuildScript and
B_BuildScriptand processed by calling the CMake's
SUBDIRS command.

As far as I know, with all the testing I did, this works very well. By
including the B_ConfigScript into the A_ConfigScript, you also include
the Clibrary w/o having to know whatever about
C itself because de dependencies propagate bottom-up. Another good thing is
that now every single part of the chain can be build independantly (by
processing the A_BuildScript or the B_BuildScript directly). I might write
some practical example if I have time or if someone asks for it.

Please give me your feedback about it.

Thank you for reading me,
Félix C. Morency
_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to