cpm-cmake / CPM.cmake

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optional dependency (don't fail on error)

jodlbauer opened this issue · comments

Hi,
is there an option to mark a package as optional and proceed within cmake if downloading/configuring/building the dependency failed?
Or something like a try CPMAddPackage(...) else ...
The only approach I have found so far that could work is using CMakes execute_process, but I think such an OPTIONAL option could make sense to be supported more natively.

In what cases should it silently fail? No connection / configuration error etc?

Also I'm not sure I like implicitly skipping components as it can add unpredictability to a build. I'd rather recommend to use CMake's options, e.g. option(shouldAddDependency "" off), and moving the CPM call inside an if (shouldAddDependency) statement.

In my case, one of the libraries (A) I pulled with CPM had an additional dependency (B) that could not be satisfied on one machine, but (A) was only necessary for some tests.
In that case, I manually checked whether (B) could be found and put the CPM call into an if block as you suggested.
However, this would not really scale well, since I need to know beforehand what dependencies a certain library has.
Something like CPMAddPackage( ... OPTIONAL) similar to find_package(... REQUIRED) could make that a whole lot easier.

Thanks for clarifying! Tbh I don't think we will be supporting this as CMake does not have any try / catch mechanisms which would make this very challenging to implement. Also IMO it's usually more suited for the library itself to handle the implications of missing local libraries explicitly using find_package mechanisms.