einpoklum
einpoklum

Reputation: 131544

How can I prevent a CMake external project from updating & reinstalling whenever I make?

After much agony, I've successfully arranged for my CMake project to use some library via ExternalProject. I cmake, I make, it works - life is good.

However, if I make again, it performs the Update and Install steps for the external project. I definitely do not want this to happen. How do I prevent this?

Upvotes: 2

Views: 2112

Answers (2)

deqyra
deqyra

Reputation: 764

While the way you proposed in your own answer has the same effect, the actual option you might want to use for that is UPDATE_DISCONNECTED.

From CMake's documentation, under the section Update/patch options:
UPDATE_DISCONNECTED <bool>

When enabled, this option causes the update step to be skipped. It does not, however, prevent the download step. The update step can still be added as a step target (see ExternalProject_Add_StepTargets()) and called manually.

So your final thing could look like the following:

ExternalProject_Add( external_lib
    # ...
    UPDATE_DISCONNECTED True
)

If you go a bit further down the excerpt I quoted though, the documentation explicitly advises against doing this and recommends controlling the update behaviour through a directory variable EP_UPDATE_DISCONNECTED, whose value is used as the default value for UPDATE_DISCONNECTED.
This means you can keep your ExternalProject_Add call free of the UPDATE_DISCONNECTED option, and instead run your CMake command like so:

$ cmake .. -DEP_UPDATE_DISCONNECTED:BOOL=True
$ cmake --build . [your_options]

Upvotes: 2

einpoklum
einpoklum

Reputation: 131544

One way to do it is to set UPDATE_COMMAND to "" for your library's external project, that is, have:

ExternalProject_Add(the_external_library_proj_name
    # all sorts of settings here
    # etc. etc.
    # ...
    UPDATE_COMMAND ""
)

in your CMakeLists.txt. That means you might not be able to update the external project via CMake and will have to resort to doing it manually, or cleanly rebuilding everything etc.

Upvotes: 0

Related Questions