The install target in CMakeLists.txt is an essential component to this recipe:
install(
TARGETS
hello-conda
DESTINATION
bin
)
This target makes sure that the binary is installed in ${CMAKE_INSTALL_PREFIX}/bin. The prefix variable is defined by Conda in the build step of meta.yaml:
build:
number: 0
binary_relocation: true
script:
- cmake -H. -Bbuild_conda -G "${CMAKE_GENERATOR}"
-DCMAKE_INSTALL_PREFIX=${PREFIX} # [not win]
- cmake -H. -Bbuild_conda -G "%CMAKE_GENERATOR%"
-DCMAKE_INSTALL_PREFIX="%LIBRARY_PREFIX%" # [win]
- cmake --build build_conda --target install
The build step configures the project, sets the install prefix to ${PREFIX} (intrinsic variable set by Conda), builds, and installs the project. The motivation to call the build directory build_conda is similar to the previous recipes: a specific build directory name makes it easier to experiment with local installs based on directories that might already contain a directory called build.
By installing the package into the Anaconda environment, we made the executable available to the system.