You are here: Start » Getting Started » Using Library with CMake

Using Library with CMake

Library ships with CMake configuration modules. It makes the project portable, and easy to compile for Windows, linux or Android. The minimum CMake version supported is 3.10 (for example shipped with Ubuntu bionic/18.04)

Quick Start

A simple template for CMakeLists.txt is presented below:

cmake_minimum_required(VERSION 3.10)
project(example)

find_package(
    AVL
    # for a specific version, uncomment the line below
    #5.3
    CONFIG
    REQUIRED
)

# copy binaries to build directory
copy_avl()

add_executable(
    # executable name
    example_exec
    # source files
    main.cpp
)

target_link_libraries(
    example_exec
    PUBLIC
    AVL
)

# install user executable
install(TARGETS example_exec)
# install ALL AVL libraries
install_avl()

One can also copy one of the CMake examples, and modify to your needs. For further cmake use refer to online documentation. Be aware that ubuntu 18.04 is the baseline distribution, so minimal CMake version is 3.10

Reference

package

CMake package is provided for windows installer and linux archive. Both should be usable after installation. Linux additionally ships with Android libraries. The library is only discoverable using CONFIG mode, so it's sensible to restrict find_package to that mode.

find_package(
    AVL
    # for a specific version, uncomment the line below
    #5.3
    CONFIG
    REQUIRED
)
    

On Android to use system installed AVL it is necessary to add CMAKE_FIND_ROOT_PATH_BOTH argument:

find_package(AVL CONFIG REQUIRED CMAKE_FIND_ROOT_PATH_BOTH)
Possible packages:

  • AVL - full library
  • AVL_Lite - lite library
  • Weaver - deep learning inference library

install_avl

Install all AVL libraries when executing make install or ninja install or building INSTALL project in Visual Studio. It accepts a LIB argument to override default installation directory. It requires find_package(AVL...) call first.

find_package(AVL CONFIG REQUIRED)

install_avl()
    
By default it installs to ${CMAKE_INSTALL_PREFIX}/bin on Windows and ${CMAKE_INSTALL_PREFIX}/lib on Linux. When provided the LIB argument it installs to ${CMAKE_INSTALL_PREFIX}/${LIB_ARGUMENT}
install_avl(LIB "avl_directory")
Possible variants:

  • install_avl()
  • install_avl_lite()
  • install_weaver()

copy_avl

Copy all AVL libraries when compiling targets that depend on AVL to binary directory. By default it's ${CMAKE_BINARY_DIR} or ${CMAKE_BINARY_DIR}/$<CONFIG> on Windows. It requires find_package(AVL...) call first.

find_package(AVL CONFIG REQUIRED)

copy_avl()
    
Possible variants:

  • copy_avl()
  • copy_avl_lite()
  • copy_weaver()