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

Interaction between CPM_USE_LOCAL_PACKAGES and VERSION in CPMAddPackage

Open Edgeworth opened this issue 1 year ago • 1 comments

I am trying to get the following use case to work:

  1. Set CPM_USE_LOCAL_PACKAGES to ON
  2. Use CPMAddPackage to add a package, with a specific version
  3. Use the local package if it exists and is the right version, otherwise fallback to downloading it.

It seems to me that CPM_USE_LOCAL_PACKAGES will use a local package if it exists, regardless of the version.

For example, the following code:

set(CPM_USE_LOCAL_PACKAGES ON)

CPMAddPackage(
  NAME benchmark
  GITHUB_REPOSITORY google/benchmark
  VERSION 1.5.2
  OPTIONS "BENCHMARK_ENABLE_TESTING Off"
)

will use (and identify the version of) version 1.8.2 of benchmark on my machine if it's a local package, when CPM_USE_LOCAL_PACKAGES is ON. If CPM_USE_LOCAL_PACKAGES is OFF, it will download version 1.5.2, meaning that the versions differ between CPM_USE_LOCAL_PACKAGES ON vs OFF.

Is this intended behaviour? Is there any way to accomplish a version based fallback to downloading? Maybe I've missed something.

Thanks!

Edgeworth avatar Aug 22 '23 12:08 Edgeworth