CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

[Feature Request] Support an optional dependency

Open blozano-tt opened this issue 10 months ago • 2 comments

We are facing a scenario where we have private repos that not all users would have access to.

Could CPM support a scenario where a dependency is declared, but not error out if the source is unreachable?

Something like:

CPMTryAddPackage(
  NAME optionalThing
)

if(optionalThing_Added)
  list(APPEND myTargets optionalThing::optionalThing)
endif()

blozano-tt avatar Feb 19 '25 17:02 blozano-tt

Hmmm, I like the idea, but I've encountered two issues already that seem impossible to solve.

  1. FetchContent Errors: FetchContent will always error out, and the log can't be turned off. About half a year ago, I tested around with FetchContent's log output (I think it was also an issue someone raised here :) ), but basically, you cannot turn off the error logs. And CPM can't change that behavior. I'm not sure if this stops the configuration completely or if it keeps going, but either way, when an error is printed, we can't really continue and carry on without confusing the user.

  2. Windows: My Windows machine opens a separate process and window where it expects credentials for the arbitrary repository I declared as a dependency. CMake then waits until I do something with it. A try catch mechanism doesn't really make sense when a seperate window interupts everything. This might just be my 8-year-old, bloated installation though :P.

Even though I like the idea, I don't really see a reason for such a feature tbh.

Edit: I guess, when you can't find a dependency you could setup your project such that you can atleast build the targets that don't require the dependency.

Avus-c avatar Feb 22 '25 13:02 Avus-c

Yeah, this thing could easily be solved with explicit options… -DBUILD_WITH_OPTIONAL_THING=ON

But it was desired by a colleague to make it automatic handling.

Thanks for giving it some thought.

blozano-tt avatar Feb 22 '25 16:02 blozano-tt