---
title: slint_target_sources
description: The slint_target_sources CMake function — register .slint files, set the C++ namespace, library paths and compilation units.
---

import SlintRef from "../../../components/SlintRef.astro";

```
slint_target_sources(<target> <files>.... [NAMESPACE namespace] [LIBRARY_PATHS name1=lib1 name2=lib2 ...] [COMPILATION_UNITS num])
```

Use this function to tell CMake about the .slint files of your application, similar to the builtin cmake [target_sources](https://cmake.org/cmake/help/latest/command/target_sources.html) function.
The function takes care of running the slint-compiler to convert `.slint` files to `.h` files in the build directory,
and extend the include directories of your target so that the generated file is found when including it in your application.

The optional `NAMESPACE` argument will put the generated components in the given C++ namespace.

Use the `LIBRARY_PATHS` argument to specify the name and paths to <SlintRef type="ComponentLibraries" label="component libraries" code={false} />,
separated by an equals sign (`=`).

Given a file called `the_window.slint`, the following example will create a file called `the_window.h` that can
be included from your .cpp file. Assuming the `the_window.slint` contains a component `TheWindow`, the output
C++ class will be put in the namespace `ui`, resulting to `ui::TheWindow`. Any import from `@mycomponentlib/` will
be redirected to the specified path.

```cmake
add_executable(my_application main.cpp)
target_link_libraries(my_application PRIVATE Slint::Slint)
slint_target_sources(my_application the_window.slint
    NAMESPACE ui
    LIBRARY_PATHS mycomponentlib=/path/to/customcomponents
)
```

By default, a `.slint` file is compiled to a `.h` file for inclusion in your application's business logic code, and a `.cpp` file with code generated by
the slint-compiler. If you want to speed up compilation of the generated `.cpp` file, then you can pass the `COMPILATION_UNITS` argument with a value greater
than 1 to create multiple `.cpp` files. These can be compiled in parallel, which might speed up overall build times. However, splitting the generated code
across multiple `.cpp` files decreases the compiler's visibility and thus ability to perform optimizations. You can also pass `COMPILATION_UNITS 0` to generate
only one single `.h` file.

:::caution
Compiling multiple .slint files with the same namespace may create conflicting symbols. Avoid this by putting each .slint file in its own namespace.
:::
