Skip to content

cmake install(EXPORT ...) targets #22

@george-pippos-qb

Description

@george-pippos-qb

This is more of a feature request but at the moment, we are only able to use cryptolens-cpp via adding it as a subdirectory which means anything set in cryptolens' CMakeLists.txt and other cmake files can pollute our downstream build and create hard to diagnose issues with less control of things like compiler toolchains etc (and that can lead to further build/runtime issues that are hard to diagnose because of different ABIs introduced because of other compiler or dependency version requirements downstream projects have). Conventionally, projects designed to be a dependency of other projects use install(EXPORT... ) and package configuration files so that can be used via the canonical cmake workflow:

cmake -B cyrptolens/build -S cyrptolens -DCMAKE_INSTALL_PREFIX=/opt/cryptolens
cmake --build cyrptolens/build -j $(nproc)
cmake --install cyrptolens/build

And this along with other install(...) directives to install the built headers and libraries would make an install of cryptolens with the following structure:

  • /opt/cryptolens/include containing headers
  • /opt/cryptolens/lib containing library files
  • /opt/cryptolens/lib/cmake containing cmake package config files which allow downstream users to import header and library files
    • Note that this location is different for almost every project but there are a set of common locations that cmake expects within a project's installation directory to find the package's config files

Once the package is built and installed, we can then simply add it to our parent project via:

cmake -B my_cool_project_that_uses_cryptolens/build -S my_cool_project_that_uses_cryptolens -DCMAKE_PREFIX_PATH=/opt/cryptolens

Our CMakeLists.txt for my_cool_project_that_uses_cryptolens would then simply need to do find_package(cryptolens-cpp REQUIRED) and the package's config file would run and set up the include and library paths so that we could use add_library(my_cool_project_that_uses_cryptolens PRIVATE cryptolens-cpp::cryptolens-cpp).

More info here:

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