![]() ![]() Scope and returning valuesĪs I already mentioned functions introduce a new scope, whereas macros don’t. The little extra effort is worth it, as it could prevent some debugging sessions as the project grows. I’d suggest sticking with functions whenever possible. Accidentally overwriting existing variables is also likely. I’d advise against it for the same reason one would avoid macros in C/C++ – it’s best not to pollute the calling scope with whatever variables are defined within the macro’s body. Before we move on to more interesting examples let me touch on one important point.īecause macros don’t introduce new scope they’re often chosen over functions for their ease of use – it’s much more intuitive to “return” a value by defining or mutating a variable in the caller’s scope than it is to use a function. Once defined, both can be called just like builtin CMake commands: myFunction("hello" "functions")Įxecuting this code results in the expected output: $ cmake -S. In the macro’s case they are string-substitutions, but for day-to-day use this shouldn’t make much difference to the user – they’re still accessed the same way within the macro’s body. The parameters foo and bar are regular variables in case of the function. The most important difference between the two is that functions introduce a new scope, whereas macros don’t – their body is essentially copy-pasted into the call site.įunctions and macros can be defined as follows: function(myFunction foo bar) Functions and Macros basicsĪt a first glance, CMake functions and macros behave exactly as one would expect, having experience with any of the C/C++ family of languages. Once the basics are covered I then move on to demonstrating the uses of cmake_parse_arguments. In this post I’ll discuss the basic use of functions and macros in CMake. Due to CMake language scope rules, this requires some special handling and is rather unintuitive, which often causes people to relegate to macros altogether. This is especially true for functions that are expected to return a value. However, they might be somewhat inconvenient to use at first. It enables users to define both functions and macros allowing for encapsulation of repetitive tasks. Every scripting language needs to provide some facilities for code reuse. List of arguments to pass to Android applicationsĮnables building multi-ABI packages using the autodetected Qt for Android SDK listĪllows to share CMake variables in multi-ABI builds List of ABIs that the project packages are built for Qt6::CoreĪndroid-specific architecture of the host system They may be set by the project, a toolchain file or other third-party packages. These variables can influence CMake commands provided by Qt. This means that only selected symbols are exported. On Unix, a boolean that describes whether Qt libraries and plugins were compiled with -fvisibility=hidden. Instead, you need to use the targets starting with Qt6. Hides the imported targets starting with Qt. Hides commands that start with qt_, leaving only the versioned ones starting with qt6_. If not set, the first find_package call defines the default version.Ī string that holds the infix used in library names, when Qt is configured with -libinfix. ![]() If set to 6, they will call their counterpart starting with qt6_. If set to 5, commands starting with qt_ will call their counterpart starting with qt5_. It needs to be set to either 5 or 6 before the respective find_package() calls. Installation variablesĪdditionally, there are also variables that don't relate to a particular package, but to the Qt installation itself.Īn integer that controls the Qt version that qt_ commands forward to in case of mixed Qt 5 and Qt 6 projects. The name of the imported target for the module: Qt5::WidgetsĪ list of private include directories to use when building against the library and using private Qt API.Ī string containing the module's version.įor all packages found with find_package, equivalents of these variables are available they are case-sensitive. A list of compile definitions to use when building against the library.Ī list of definitions to use when building against the library.Ī string of flags to use when building executables against the library.Ī boolean that describes whether the module was found successfully.Ī list of include directories to use when building against the library. ![]()
0 Comments
Leave a Reply. |