Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_package interferes with existing installation #860

Open
LecrisUT opened this issue Aug 13, 2024 · 2 comments
Open

find_package interferes with existing installation #860

LecrisUT opened this issue Aug 13, 2024 · 2 comments

Comments

@LecrisUT
Copy link
Collaborator

LecrisUT commented Aug 13, 2024

This is a quick but rather subtle issue. My CMake list file goes like:

if (NOT TARGET Spglib::symspg)
    find_package(Spglib CONFIG)
    if (NOT Spglib_FOUND)
        message(STATUS "Using bundled spglib sources")
        add_subdirectory(${PROJECT_SOURCE_DIR}/.. _deps/spglib-build)
    endif ()
endif ()

If I pip install from scratch it works just fine, i.e. the add_subdirectory is used. But if I run pip install again, then it picks up the current installation and it goes through find_package even though it is later removed at the install stage when the previous version is uninstalled.

I think the issue is with working around NO_CMAKE_INSTALL_PREFIX, but it is weird, shouldn't that point to tmp folder that would not interfere? Otherwise I did not configure any prefix for it to use. Any clues on what's happening here and how to work around it?

I believe the issue is with:

# Add site-packages to the prefix path for CMake
site_packages = Path(sysconfig.get_path("purelib"))
self.config.prefix_dirs.append(site_packages)
logger.debug("SITE_PACKAGES: {}", site_packages)
if site_packages != DIR.parent.parent:
self.config.prefix_dirs.append(DIR.parent.parent)
logger.debug("Extra SITE_PACKAGES: {}", site_packages)

@henryiii
Copy link
Collaborator

I'm assuming you haven't set CMAKE_EXPORT_PACKAGE_REGISTRY, which could muddle with this.

The CMake way to do this is with the new-ish (3.24 IIRC) FindPackage + FetchContent integration:
(see https://github.com/scikit-hep/boost-histogram/blob/8ded2db528ac1a8538462239a72a1f1efa5e10cf/CMakeLists.txt#L45-L50)

@LecrisUT
Copy link
Collaborator Author

LecrisUT commented Aug 13, 2024

CMAKE_EXPORT_PACKAGE_REGISTRY nope not setup, on the pyproject.toml everything is rather vanilla, and the current CMakeLists.txt does not mess with anything related to find_package.

The CMake way to do this is with the new-ish (3.24 IIRC) FindPackage + FetchContent integration:

Yeah, for proper dependencies I do use the FetchContent approach. But this is a special case where I want to use the bundled project instead, i.e. Spglib_python where that snippet is in is just the python bindings and it is a subproject/subdir of Spglib so that if the system installed Spglib is found use and link to it, otherwise use the bundled source files commit-locked to the current sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants