# Cppkg

## Add dependencies&#x20;

**First. Search package**

{% code title="" %}

```bash
cppm cppkg search Catch
Name                Version   Repository   Description                                       Use                                                                   
===================================================================================================================================================================
Catch2              git       cppkg        modern, C++-native, header-only, test framework f$Catch2="git"                                                          
Catch2              2.9.1     cppkg        modern, C++-native, header-only, test framework f$Catch2="2.9.1"                                                        
Catch               latest    hunter                                                        https://docs.hunter.sh/en/latest/packages/pkg/Catch.html#index-
                                                                                            # hunter example Catch2 = {module="Catch2", hunter=true}   
```

{% endcode %}

**Second. add this option in cppm.toml**

{% code title="cppm.toml" %}

```
[dependencies]
exam = {module="exam::exam", version="latest"}
Catch2 = "2.9.1"
# Catch2 = {module="Catch2", hunter=true} 
```

{% endcode %}

**If you can't find package, add new package in local repo**

## Generate New Cppkg and Add your local repository

**First. Initialize cppkg**&#x20;

```bash
cppm cppkg init exam
```

**Second. Edit exam.toml file**

{% code title="exam.toml" %}

```
[package]
    name     = "exam"
    version  = "lastest" # git repo version is lastest
    description = "cppkg example"
    global=false # install prefix if global is false, install to $HOME/.cppm/local/
    cmake    = {name = {exam cmake library name}}
    download = {git="{git repo}"} # or url
```

{% endcode %}

**Third. Build exam.toml**

```bash
cppm cppkg build exam
```

{% code title="exam/" %}

```
${version}/
+-- cppkg.toml  # same exam.toml
+-- eaxm.cmake.in # cppkg library auto installer
```

{% endcode %}

**Fourth. Add options in cppkg.toml and eaxm.cmake.in**

{% code title="exam/cppkg.toml" %}

```
[package]
    name     = "exam"
    version  = "lastest" # git repo version is lastest
    description = "cppkg example"
    global = false
    cmake    = {name = {exam cmake library name}, finlib={Findlib.cmake file}}
    download = {git="{git repo}"} # or url
```

{% endcode %}

> cmake.findlib options, auto install your project 'cmake/Modules' path\
> Find{name}.cmake is none cmake project finder\
> 'download\_package()' is External\_Project\_Add wrapper

{% code title="exam.cmake.in" %}

```
cmake_minimum_required(VERSION 3.10)
project(exam--install NONE)

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_tool.cmake)
download_package(exam lastest GIT https://github.com/exam/exam.git   LOCAL)

# Other Options:
# - Linux Configure:
#    L_CONFIGURE {...}, L_BUILD {...}, L_INSTALL {...}
# - Windows Configure: 
#    W_CONFIGURE {...}, W_BUILD {...}, W_INSTALL {...}
# - Install Path Option:
#    LOCAL(default) GLOBAL
```

{% endcode %}

**Fifth. Add cppkg in your local repository**

```bash
cppm cppkg push exam
```

## Fast Add and Generate Cppkg&#x20;

> if dependency is cmake base project, you can add too simple\
> git repo default version is lastest\
> Option: \
> \--git \[-g] {repo}                 :add git repo\
> \--git\_tag \[-t] {tag}             :add git tag\
> \--global                             : not cppm local install \
> \--help \[-h]                          :show cppm command and options\
> \--module \[-m] {module}  :add module name\
> \--p \[-p]                                :cmake base library install to local cppkg repo, Require --url or --git \
> \--url \[-u] {url}                     :add url repo Require --version\
> &#x20;\--version \[-v] {version}   :add library version Require --version\
> \--p \[-p]                               :cmake base library install to local cppkg repo, Require --url or --git&#x20;

```
cppm cppkg init -g {git repo} -m "exam::exam" exam
#or
cppm cppkg init -u {url} -v {version} -m "exam::exam" exam 
```
