xentara-cpp-control v1.0.1
The Xentara C++ Control Framework
Loading...
Searching...
No Matches
Creating the CMakeLists.txt File

Overview

In this tutorial, we will create a CMakeLists.txt file to build a Xentara control using CMake. The CMake file will define the minimum CMake version, specify project settings, find necessary dependencies, add the control source file, and link to the Xentara library.

The objectives of this tutorial are to:

  • Understand the purpose of each command in CMakeLists.txt.
  • Configure CMake to locate Xentara dependencies and source files.
  • Set up a basic CMake file to build a Xentara control.

Step 1: Define Minimum CMake Version

First, define the minimum required version of CMake. Debian Bookworm uses CMake version 3.25, which we set as the minimum to ensure compatibility with the available system version.

cmake_minimum_required(VERSION 3.25)

Step 2: Specify Project Settings

Define the project name and language settings using the project command. The name my-control is used here as an example, and LANGUAGES CXX specifies that this project is written in C++.

project(my-control LANGUAGES CXX)

Step 3: Find the Required Packages

To build the control, we need to find the XentaraCPPControl package, which provides the necessary headers and libraries. The find_package command searches for this package and ensures it is available for use. The REQUIRED keyword means CMake will throw an error if the package is not found.

find_package(XentaraCPPControl REQUIRED)

Step 4: Add the Control Source File

Use the add_library command to specify the output target for the project. Here, we create a library module named my-control and include the source file for the control. Adjust "src/MyControl.cpp" to the actual location of your control's source file.

add_library(
my-control MODULE
"src/MyControl.cpp"
)
  • my-control: The name of the target library.
  • MODULE: Specifies that this library should be compiled as a loadable module.

Step 5: Link to the Xentara Library

The target_link_libraries command links the control to the required Xentara library (Xentara::cpp-control). This allows the control to use functionality from Xentara's C++ library.

target_link_libraries(
my-control
PRIVATE
Xentara::cpp-control
)
  • PRIVATE: This keyword restricts the link to internal use within the target (no other target can directly link to this).
  • Xentara::cpp-control: The library target provided by XentaraCPPControl that is needed to build the control.

Complete CMakeLists.txt File

Here is the complete CMakeLists.txt file, combining all the sections explained above:

cmake_minimum_required(VERSION 3.25)
project(my-control LANGUAGES CXX)
# Find the required packages
find_package(XentaraCPPControl REQUIRED)
# Add the control source file as a module
add_library(
my-control MODULE
"src/MyControl.cpp"
)
# Link to the Xentara library
target_link_libraries(
my-control
PRIVATE
Xentara::cpp-control
)

Conclusion

In this tutorial, we created a CMakeLists.txt file to build a Xentara control. This CMake file defines the minimum required version, specifies the project and dependencies, and links to the necessary Xentara libraries. This setup provides the foundation to build and integrate custom controls into the Xentara framework.