This is how to proceed, step by step:
- The CMakeLists.txt file starts with the minimum version requirement, project name, and supported language:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(recipe-04 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
- We wish to build the hello-conda executable, which is built from example.cpp:
add_executable(hello-conda "")
target_sources(hello-conda
PRIVATE
example.cpp
)
- We conclude CMakeLists.txt by defining the install target:
install(
TARGETS
hello-conda
DESTINATION
bin
)
- We will describe the Conda package in a file called meta.yaml, which we will place under conda-recipe to arrive at the following file structure:
.
├── CMakeLists.txt
├── conda-recipe
│ └── meta.yaml
└── example.cpp
- The meta.yaml file consists of the following:
package:
name: conda-example-simple
version: "0.0.0"
source:
path: ../ # this can be changed to git-url
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
requirements:
build:
- cmake >=3.5
- {{ compiler('cxx') }}
about:
home: http://www.example.com
license: MIT
summary: "Summary in here ..."
- Now we can try to build the package:
$ conda build conda-recipe
- We will see lots of output on the screen, but once the build is complete, we can install the package. We will do this first locally:
$ conda install --use-local conda-example-simple
- Now we are ready to test it – open a new terminal (assuming Anaconda is activated) and type the following:
$ hello-conda
hello from your conda package!
- After the successful test, we can remove the package again:
$ conda remove conda-example-simple