![]() We’ve set the value of the variable to ON. Commands may interpret a variable differently, but the underlying type is always string.Īlso, note that variables with the prefix CMAKE_ are either provided by CMake or are otherwise meaningful to CMake when set by the project. There aren’t really any other data types in CMake. We will gloss over the details, and for now note just that a normal CMake variable is visible from the point of definition onward, and is always of type string. In addition to normal variables set can operate on cache and environment variables, but we will not discuss those for now.ĬMake variables behave more or less the same way one would expect – they obey scope rules and have a type. The form of the set command presented here operates on what CMake documentation calls a normal variable. The set command defines or assigns a value to a variable. We still need them, since we’d like to look at exactly what’s going on. Here we set them in the CMakeLists.txt, so that we don’t have to do it every time we configure the project. These are the same variables we’ve previously set via command-line. The CMakeLists.txt that defines the project looks as follows: cmake_minimum_required(VERSION 3.19) Int Add::add(int l, int r, calc_status& cs) noexcept Int add(int l, int r, calc_status& cs) noexcept Alternatively, a git gist for the complete example is available in the reference section. If you wish to follow along you can copy-paste, or type-in the listings. Let’s assume that we’re very concerned about all the possible integer-operation failure modes and that we’re unable to use exceptions for some reason, so we decide to use simple enum error codes to report them (this will come into play later). To illustrate our example we will define an extremely simple library that exposes just a single function – add, which adds two integers. In this part, we will look at how to build libraries, and use static libraries with CMake. The next part in the series will comprise of a CMake example using Qt and how a library can be exported using modern methodologies.Īlso, my best advice is to keep CMake code clean - treat it as it would be production code.In the first post of the series we already looked at the very basics of defining a CMake-based project – we know how to write a CMakeLists.txt file and use it to compile a single or multi-source binary. If you're intrested in learning more, an excellent resource is the following GitHub project. I've only scratched the surface of modern CMake as this post only covers the basic. ![]() ) and if you do use it - learn and share about the problems to the team. target_link_libraries() automatically solves transitive dependencies,.Avoid using global commands such as include_directories() and link_libraries().Be selective with the scope - if possible, avoid exposing parameters in the INTERFACE scope. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |