-
Notifications
You must be signed in to change notification settings - Fork 15
Description
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: