![]() To include a directory into a project we introduce a new command – add_subdirectory The add_subdirectory command does exactly what it says – it adds the specified directory to the project. The top-level CMakeLists.txt now looks as follows: cmake_minimum_required(VERSION 3.19) ![]() We now need to incorporate this directory into our project so that we may use it. Īll that needs to be done in the Add library CMakeLists.txt is to declare the library target: add_library(Add We end up with the following directory structure. For this purpose we create a subdirectory named add, move the library source files – calc_status.h, add.h, add.cpp into that directory, and create a CMakeLists.txt within it. First of all, we will isolate the library code from the application code. Expanding this example will help us illustrate the concept of properties. In the previous part of the series we started working on a simple library that exposed a single add function. In fact, we’ve already used a command that operates on properties – target_link_libraries! If a command operates on a target, and does not create one, it most likely modifies its properties. Instead, the most used commands operate on a very limited set of properties – usually just one or two. In fact, even these commands are usually too big of a hammer for the task. Most often it’s more convenient to use the more specialized alternatives, like set_target_properties and get_target_property. However, as the result of the generality they’re the most complicated to use. These commands can set or fetch the value of any property in any scope. Properies may be operated on directly using the most general commands – set_property and get_property. Today we’ll focus on TARGET properties – as these are what will help us with using targets to structure our projects well. Properties may be specified for a wide range of scopes – from GLOBAL, through DIRECTORY and TARGET down do individual files. Whereas variables, be it normal or cached, have for the most part, global scope, properties are attached to an entity – they specify some aspect of it within the project. Propertiesīroadly speaking CMake projects are customized with two major facilities – cache variables (which we will return to at some point) and properties. Once again, there’s a lot of ground to cover, so let’s get right into it. While we’re at it, we will once again extend the project we have gotten started on in part 2. In this part we explore the concepts of target properties and the PRIVATE, INTERFACE and PUBLIC keywords – a crucial pieces of knowledge to using CMake well. In the previous part of the series we looked at the basics of defining and using libraries with CMake.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |