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

Allow defining custom prefixes

Open papperlapapp opened this issue 2 years ago • 7 comments

In addition to the predefined prefixes 'gh', 'gl' and 'bb', allow defining your own prefixes for, e.g. internal hosts.

papperlapapp avatar Feb 15 '23 17:02 papperlapapp

Hey thanks for the PR! Changes look good to me though I'd like an additional opinion from @iboB as he authored the original feature. Could you also format the code using according to the styleguides?

TheLartians avatar Feb 20 '23 19:02 TheLartians

Here's how I would do it:

CPMAddCustomScheme(
    c1 # scheme name
    PREFIX https://c1.example.com/ # optional
    SUFFIX .git # optional
    TYPE GIT_REPOSITORY # optional. if not specified, tries to infer the type from the composed uri
)

# ...

CPMAddPackage(c1:foo/[email protected]) # :)

If this is implemented, the existing default schemes can be added to the same underlying lists that this is using.

It can even allow overriding of existing schemes and some of the functionality requested in #333

iboB avatar Feb 21 '23 07:02 iboB

This looks definitely better than my attempt. I already had the feeling that a generic way of implementing this should somehow be possible.

Time for diving deeper into the CMake documentation ...

Shall I close the PR and start anew, or just keep it open and work on it (will definitely take its time)?

papperlapapp avatar Feb 21 '23 16:02 papperlapapp

Awesome! It's great that you want to invest more in this

Shall I close the PR and start anew, or just keep it open and work on it (will definitely take its time)?

I have no special opinion on the matter. However you prefer

iboB avatar Feb 21 '23 17:02 iboB

I think this change has really useful potential, something I had considered as would simplify setup with enterprise servers.

Ideally all the existing prefix/schema types should be migrated to use this mechanism imho. Partly as a basis of solid testing to harden the design but also as it may be desirable to modify existing behavior on the pre-existing schemas!

For example, I was considering allowing to provision alternative server addresses or fallbacks when the primary are not accessible e.g.CPM_GITHUB_SERVER=local-github.internal;central-github.internal;github.com so CPM will check in order precedence etc. There are definitely edge cases to consider here but if the prefix/schema had a 'function' aspect akin to dependency_provider then this may be super power making the core of CPM technically more modular in this area.

EDIT: I should note I haven't thought much on the example as I think it falls more into ExternalProject functionality to have alternatives for GIT as it does for URL downloads:

URL <url1> [<url2>...] List of paths and/or URL(s) of the external project's source. When more than one URL is given, they are tried in turn until one succeeds.

CraigHutchinson avatar Mar 21 '23 16:03 CraigHutchinson

Would this MR https://github.com/cpm-cmake/CPM.cmake/pull/528 be a the simpler solution for your problem?

ClausKlein avatar Dec 18 '23 19:12 ClausKlein

I just implemented a similar thing to this... and then checked the open PRs only to find this one!

https://github.com/cpm-cmake/CPM.cmake/commit/a6cc6b9096ad0687119a781997be504326058a72

This feature would really help me out. I'm happy to help get this PR completed if that'a any use to you guys :)

k-channon-PA avatar May 30 '24 08:05 k-channon-PA