How-to: create a CMake project for samurai#

This how-to guide will show you how to create a simple CMake project that uses samurai.

Before creating a CMake project, make sure you have samurai installed. If you haven’t installed it yet, please refer to the installation guide here.

Create a CMake project#

To create a CMake project that uses samurai, you need to create a CMakeLists.txt file in your project directory. Here is a simple example of a CMakeLists.txt file that includes samurai:

cmake_minimum_required(VERSION 3.16)
project(MySamuraiProject)

find_package(samurai REQUIRED)

add_executable(my_executable main.cpp)
target_link_libraries(my_executable PRIVATE samurai::samurai)

In this example, we first specify the minimum required version of CMake and the project name. Then, we use the find_package command to locate the samurai library. Finally, we create an executable target called my_executable and link it with the samurai library.

Build the CMake project#

Let’s create a simple main.cpp file to test our CMake project:

#include <samurai/samurai.hpp>

int main(int argc, char* argv[])
{
    samurai::initialize("MySamuraiProject", argc, argv);
    samurai::finalize();
    return 0;
}

To build the CMake project, you can use the following commands:

cmake -S . -B build
cmake --build build

This will generate the build files in the build directory and then compile the project.

And that’s it! You have successfully created a CMake project that uses samurai.