MeshLib Documentation
Loading...
Searching...
No Matches
MeshLib CMake Setup Guide

How to Use MeshLib with CMake

CMake Integration Support

MeshLib provides CMake integration support for Windows, Linux and macOS. Example CMake configuration files are available to demonstrate how to link against the pre-built libraries. You can find these examples in the examples directory.

Windows Integration Guide

MeshLib supports Windows via CMake, including integration with Visual Studio.

To enable support in Visual Studio, ensure the CMake component is installed in your Visual Studio setup. Once installed, standard CMake configuration should work seamlessly.

For easier setup and dependency management, we recommend using vcpkg as outlined in our C++ Setup Guide. You can configure your build with the following command:

cmake -DCMAKE_TOOLCHAIN_FILE=C:\path\to\vcpkg\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-meshlib

Quick Integration Guide

Find MeshLib CMake Configuration Files

For a start, find the MeshLib package:

find_package(MeshLib CONFIG REQUIRED)

Include the MeshLib Headers

Ensure that the include directory from the installed MeshLib package is added to your project's include directories. In your CMake configuration (CMakeLists.txt), add:

include_directories(${MESHLIB_INCLUDE_DIR})
# or
target_include_directories(your_project_name PUBLIC ${MESHLIB_INCLUDE_DIR})

Link the MeshLib Libraries

Specify which MeshLib libraries to link with your project:

target_link_libraries(your_project_name PUBLIC MeshLib::MRMesh)
# if you want to use viewer libraries
target_link_libraries(your_project_name PUBLIC MeshLib::MRMesh MeshLib::MRViewer)

Find Third-Party Dependencies

MeshLib have extended functionality that may have additional dependencies that need to be linked. Check the example CMakeLists.txt provided in the examples directory to see how to add required dependencies:

target_include_directories(your_project_name PUBLIC ${MESHLIB_THIRDPARTY_INCLUDE_DIR})
target_link_directories(your_project_name PUBLIC ${MESHLIB_THIRDPARTY_LIB_DIR})