Skip to content

Scan generated export files to determine dependencies. #8385

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

Merged
merged 1 commit into from
Aug 10, 2024

Conversation

alexreinking
Copy link
Member

This module contains a system for declaring that an export file might depend on another CMake package that was found by find_package. Such dependencies are collected in a project-wide property (rather than a variable) along with a snippet of code that reconstructs the original call.

Then, after we have installed an export file via install(EXPORT), we can call a helper to add install rules that will read the file as-generated by CMake to check whether any of these packages could be required.

CMake does not like to expose this information, in part because generator expressions make computing the eventual link set undecidable. Even so, for our purposes if Pkg:: appears in our link-libraries list, then we need to find_package(Pkg).

This module implements that heuristic.

So why is this hard? It's because checking whether a dependency is actually included is very complicated. A library will appear if:

  1. It is SHARED or MODULE
  2. It linked privately to a STATIC target
    • These appear as $<LINK_ONLY:${dep}>
  3. It is STATIC and linked publicly to a SHARED target;
  4. It is INTERFACE or ALIAS and linked publicly
  5. It is included transitively via (4) and meets (1), (2), or (3)
  6. I am not sure this set of rules is exhaustive.

There is an experimental feature in CMake 3.30 that will someday replace this module.


Some care is taken in the implementation to format the generated code. Here is an example of the code that is injected into packaging/cmake_install.cmake:

if(CMAKE_INSTALL_COMPONENT STREQUAL "Halide_Development" OR NOT CMAKE_INSTALL_COMPONENT)
  if (target_cmake MATCHES "Halide_LLVM::")
    file(APPEND "/Users/areinking/dev/Halide/build/macOS/packaging/Halide-static-deps.cmake.in"
         [===[set(Halide_LLVM_SHARED_LIBS [[YES]])
find_dependency(
    Halide_LLVM 18.1.8
    COMPONENTS WebAssembly;X86;AArch64;ARM;Hexagon;NVPTX;PowerPC;RISCV
)]===] "\n")
  endif ()
endif()

And in the final halide-static-deps.cmake:

set(Halide_LLVM_SHARED_LIBS [[YES]])
find_dependency(
    Halide_LLVM 18.1.8
    COMPONENTS WebAssembly;X86;AArch64;ARM;Hexagon;NVPTX;PowerPC;RISCV
)
find_dependency(flatbuffers 24.3.25)
find_dependency(wabt 1.0.36)

These were produced by configuring with

cmake --preset macOS -DHalide_USE_FETCHCONTENT=NO -DBUILD_SHARED_LIBS=NO

@alexreinking
Copy link
Member Author

mullapudi2016_reorder again

@alexreinking alexreinking merged commit 3cdeb53 into main Aug 10, 2024
15 of 16 checks passed
@alexreinking alexreinking deleted the build/scan-cmake-deps branch August 10, 2024 02:55
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

Successfully merging this pull request may close these issues.

2 participants