![]() In its most general form a generator expression is specified with a dollar-sign and a pair of angle brackets: $ Now that you know where generator expressions can be used, let’s see how to use them. You’ll develop a feel for it with time, just consult the documentation for specifics as you go. There are exceptions to this of course – if a variable is later used by cmake to initialize properties on targets, then you’ll get the desired effect. On the other hand if you try using generator-expressions on plain variables you’re bound to have a bad time. Expect generator-expressions to be usable with all of the commands prefixed with target_ ( target_include_directories etc.) and commands that operate on properties directly ( set_target_properties, etc.). Well, broadly speaking generator-expressions, much like most of modern CMake, work with targets and properties – if a command deals with a target and modifies its properties in some way, chances are you’ll be able to use generator-expressions with that command. That’s great, but what does this actually mean in practical terms? With which specific commands can I, or can I not use generator-expressions? build – generator-expressions are OK here.generation – generator-expressions are OK here.configuration – can’t use generator-expressions here.So the actual cmake build process stages are: As a result, they can not be used before that – i.e. As the name might suggest generator-expressions are evaluated during the generation stage. This is the stage where cmake actually generates the specified (or default for the platform, if omitted) build system. However, if on closer inspection of cmake’s output during the configuration stage it is apparent that another distinct stage is present – the generation stage: $ cmake -B build -S. ![]() These two stages are obvious, as they are two separate actions that the user must take. build – when the generated build system is ran in the build directory.configuration – when cmake is executed on the project.Most of the time this is simplified to two distinct stages: The first step to understanding generator expressions is to get a solid grasp on the CMake build process. In this post I’ll describe the basic structure of generator-expressions and provide some context for their use. Another reason might be that the syntax can be rather unfamiliar at first, due to how terse it is, thus making generator-expressions difficult to read and understand. This may be due to the fact that they are a relatively recent addition to the language, and as a consequence not much relevant tutorial material is available. One CMake feature that I feel like raises more eyebrows and causes more confusion than the others are generator-expressions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |