[CMake] Question about best practices for large Multi-stage builds

Matthew Woehlke matthew.woehlke at kitware.com
Mon Aug 26 15:36:14 EDT 2013


On 2013-08-26 15:16, Thomas Taranowski wrote:
> I have the following build structure:
>
> workspace/
>      CMakeLists.txt # top level cmake
>      component_a/
>              CMakeLists.txt # component cmake
>              src/ # source in here
>      component_b/
>              CMakeLists.txt # component cmake
>              src/ # source in here
>
> Now, I'm trying to implement a multi-stage build which does the following:
> 1) builds some external third-party dependencies.
> 2) auto-generate some code
> 3) build the source
> 4) package the result

In my experience... 1-3 and 4 are covered by the 'all' and 'package' 
targets, respectively. If your dependencies are properly expressed, I 
would not expect 2 to be a target, and the parts of 1 needed by 2-3 will 
be built automatically. (If you really want, it is trivial to add a 
custom target that depends on whatever third-party pieces you have.)

I've seen two common methods for dealing with third-party packages: 
build them in the same CMake hierarchy as everything else, or build them 
as external projects. In the latter case, your main project must also be 
an external project in order to ensure the third party pieces are fully 
built before the main part of your project configures.

In either case, there is usually an option to use the 'internal' version 
of a third-party component or to supply an external version. The main 
project relies on find modules / configs to find third party components, 
and your build driver (i.e. the root CMakeLists.txt) sets whatever 
variables are necessary to use or find the internal version so that the 
consumers thereof don't need to care about the difference.

-- 
Matthew



More information about the CMake mailing list