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

Unable to determine Name from Single-arg call to `CPMAddPackage`

Open CraigHutchinson opened this issue 3 years ago • 4 comments

Situation

A URI is provided from external/user CMAKE in CPM single-argument format e.g.

set( USER_CPM_URI "gh:jbeder/yaml-cpp#[email protected]"

CPMAddPackage( ${USER_CPM_URI} )
if ( ???_ADDED ) ## Unable to implement check as `NAME` is necessary

Issue

Some logic needs to check if the package _ADDED has been set and also use the _SOURCE_DIR for further modification and checks. The name of the package isn't sent to the parent scope it appears.

if ( ???_ADDED )

Propose Solution

One idea is if CPM_PACKAGE_NAME were added to parent scope representing the Name of the last package that was added . This would be consistent with behavior like PROJECT_NAME is the last name for CMake project()

CraigHutchinson avatar Sep 07 '22 14:09 CraigHutchinson

I agree that it would be good to have a way to obtain the inferred name for a package.

I don't mind the proposal. CPM_LAST_PACKAGE_NAME sounds better to me as a name but I'm also ok with the proposed one.

Two lines around here should do the trick: https://github.com/cpm-cmake/CPM.cmake/blob/master/cmake/CPM.cmake#L597

@TheLartians what you think?

iboB avatar Sep 08 '22 03:09 iboB

I can see how this would be useful, and don't have anything against it. For naming I agree that CPM_LAST_PACKAGE_NAME makes the intent more clear.

TheLartians avatar Sep 13 '22 21:09 TheLartians

@CraigHutchinson do you want to make a PR for this?

iboB avatar Sep 14 '22 04:09 iboB

Pull-confirmed as working: image

CraigHutchinson avatar Sep 20 '22 08:09 CraigHutchinson

Closed by #403

iboB avatar Sep 28 '22 19:09 iboB