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

CPMFindPackage failed to find package installed by apt on Debian

LXYan2333 opened this issue · comments

problem

I have mimalloc installed on my Debian 12 system using apt:

$ sudo apt install libmimalloc-dev/stable

and I can find_package it:

find_package(mimalloc CONFIG REQUIRED)

now I want to try find_package it first, and if mimalloc can not be found, install it via CPM.

according to readme:

For using CPM.cmake projects with external package managers, such as conan or vcpkg, setting the variable [CPM_USE_LOCAL_PACKAGES](https://github.com/cpm-cmake/CPM.cmake/blob/369f1316f67545e6ef115b317802bc7acedf6697/README.md#options) will make CPM.cmake try to add a package through find_package first, and add it from source if it doesn't succeed.

In rare cases, this behaviour may be desirable by default. The function CPMFindPackage will try to find a local dependency via CMake's find_package and fallback to CPMAddPackage, if the dependency is not found.

I write cmake file like this:

if(NOT TARGET mimalloc)
    CPMFindPackage(
        NAME mimalloc
        GITHUB_REPOSITORY "microsoft/mimalloc"
        VERSION 2.1.2)
endif()

however cpm can't find the mimalloc provided by system, but add it via source. the log is:

CPM: Adding package mimalloc@2.1.2 (v2.1.2 at /home/lxyan/.cache/CPM/mimalloc/335bb897ed60cff43911ea8a4d21b596e5528f1a)

CPM version:

CURRENT_CPM_VERSION 0.38.7

oh, I read the code:

function(cpm_find_package NAME VERSION)
  string(REPLACE " " ";" EXTRA_ARGS "${ARGN}")
  find_package(${NAME} ${VERSION} ${EXTRA_ARGS} QUIET)
  if(${CPM_ARGS_NAME}_FOUND)
    if(DEFINED ${CPM_ARGS_NAME}_VERSION)
      set(VERSION ${${CPM_ARGS_NAME}_VERSION})
    endif()
    cpm_message(STATUS "${CPM_INDENT} Using local package ${CPM_ARGS_NAME}@${VERSION}")
    CPMRegisterPackage(${CPM_ARGS_NAME} "${VERSION}")
    set(CPM_PACKAGE_FOUND
        YES
        PARENT_SCOPE
    )
  else()
    set(CPM_PACKAGE_FOUND
        NO
        PARENT_SCOPE
    )
  endif()
endfunction()

it seems that the version number must be exactly the same. Maybe we can provide an option to soften this restriction? Since in a lot of time the version specified in CPMFindPackage is only used to indicate the last release number, not means I want the exact version.

maybe related to #497

If I remember correctly, the libraries themselves define their compatibility in their package version file, so this should actually be up to the library implementation and not CPM.

Can this be closed?