cmakeexternal-project

How do you make CMake skip an ExternalProject on subsequent runs?


I'm using CMake for a project where I want to bundle Clang. I use ExternalProject_Add to build clang from source. However, since Clang and LLVM is huge, a make with nothing changed takes 45 seconds.

Is there a way to make CMake just build the ExternalProject once, and then not even check if anything has changed on subsequent runs if it has already been built successfully?


Solution

  • The best way to use ExternalProject_Add() is to structure your project as a superbuild. This means that your top-level project (the "superbuild") does not build any actual code and instead consists only of ExternalProject_Add calls. Your "real" project is added as one of these "external" projects. This allows you to set up the superbuild with all dependencies, ordering, etc.

    The workflow is then as follows:

    1. Generate the superbuild project.
    2. Build the superbuild project. This will build and install all dependencies, and also generate (and build) your real project.
    3. Switch to the buildsystem generated for your real project and start doing further development using that. Your dependencies are already correctly set up and installed by the build of the superbuild project in the previous step, and will never be checked for out-of-dateness by the build.
    4. If you ever need to change the setup of your dependencies, do it and build the superbuild again.