Skip to content

CMake Quality of Life: export targets, ExternalProject #981

@samuelpmish

Description

@samuelpmish

Hi, I'm just starting to try out enzyme and it's a little bit unclear how to integrate it into an existing C++/CMake project.

After building and installing Enzyme, find_package does something, but I can't seem to figure out what it actually defines, or how to use it.

I was hoping that I might be able to follow the idiomatic cmake patterns of doing one of

  • (installed Enzyme)
find_package(Enzyme REQUIRED)

add_executable(my_application main.cpp)
target_link_libraries(my_application PUBLIC Enzyme::Enzyme)
  • (Enzyme as a subdirectory)
add_subdirectory(path/to/Enzyme)

add_executable(my_application main.cpp)
target_link_libraries(my_application PUBLIC Enzyme::Enzyme)

but neither seemed to work. I'm able to define a custom INTERFACE target locally, doing

add_library(Enzyme INTERFACE)
set(MY_ENZYME_LIB "/my/specific/hardcoded/path/to/Enzyme/enzyme/build/Enzyme/ClangEnzyme-14.so")
target_compile_options(Enzyme INTERFACE -flegacy-pass-manager)
target_compile_options(Enzyme INTERFACE "SHELL: -Xclang -load")
target_compile_options(Enzyme INTERFACE "SHELL: -Xclang ${MY_ENZYME_LIB}")
# note: the "SHELL: ..." stuff seems to be necessary to stop CMake's flag deduplication
# from removing the second -Xclang flag

add_executable(my_application main.cpp)
target_link_libraries(my_application PUBLIC Enzyme) # works!

Would it make sense to include such a target in Enzyme directly, to streamline the user CMake experience?
Or maybe something like this already exists and I just missed it!


Another, unrelated thought: the documentation here seems a little out of date with respect to supported versions of LLVM. CMake's ExternalProject_Add tool would let the Enzyme CMake build grab a vetted version of the llvm repo and automatically configure/build it with the appropriate flags, which would make building from source as simple as

git clone https://github.com/EnzymeAD/Enzyme
cd Enzyme/enzyme
cmake . -Bbuild && cmake --build build --parallel

And for backward compatiiblity, if a user specified -DLLVM_DIR=... then the user-provided directory would be used instead of downloading LLVM through CMake.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions